mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
Core: *Map::GetPut(K, T) fixed
This commit is contained in:
parent
47c0f89e0a
commit
902e3a82aa
7 changed files with 71 additions and 26 deletions
11
autotest/GetPut/Etalon.log
Normal file
11
autotest/GetPut/Etalon.log
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
* C:\upp\out\autotest\CLANGx64.Debug.Debug_Full\GetPut.exe 27.04.2023 08:59:05, user: cxl
|
||||
|
||||
data = {0: zero, 1: one}
|
||||
data.Get("0", "ZERO") = zero
|
||||
data.Get("1", "ONE") = one
|
||||
data = {0: zero, UNLINKED 1: one}
|
||||
data.Get("0", "ZERO") = zero
|
||||
data.Get("1", "ONE") = ONE
|
||||
data = {0: zero, 1: I}
|
||||
data.Get("0", "ZERO") = zero
|
||||
data.Get("1", "ONE") = I
|
||||
26
autotest/GetPut/GetPut.cpp
Normal file
26
autotest/GetPut/GetPut.cpp
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#include <Core/Core.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
{
|
||||
StdLogSetup(LOG_COUT|LOG_FILE);
|
||||
|
||||
VectorMap<String, String> data;
|
||||
|
||||
data.Add("0", "zero");
|
||||
data.Add("1", "one");
|
||||
DUMP(data);
|
||||
DUMP(data.Get("0", "ZERO"));
|
||||
DUMP(data.Get("1", "ONE"));
|
||||
data.UnlinkKey("1");
|
||||
DUMP(data);
|
||||
DUMP(data.Get("0", "ZERO"));
|
||||
DUMP(data.Get("1", "ONE"));
|
||||
data.GetPut("1", "I");
|
||||
DUMP(data);
|
||||
DUMP(data.Get("0", "ZERO"));
|
||||
DUMP(data.Get("1", "ONE"));
|
||||
|
||||
CheckLogEtalon();
|
||||
}
|
||||
12
autotest/GetPut/GetPut.upp
Normal file
12
autotest/GetPut/GetPut.upp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
description "Testing VectorMap::GetPut\377";
|
||||
|
||||
uses
|
||||
Core;
|
||||
|
||||
file
|
||||
Etalon.log,
|
||||
GetPut.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "";
|
||||
|
||||
|
|
@ -66,7 +66,7 @@ class Index : MoveableAndDeepCopyOption<Index<T>>, IndexCommon {
|
|||
template <typename U> void AddS(U&& k, dword sh);
|
||||
|
||||
template <class OP, class U> int FindAdd(U&& k, OP add_op);
|
||||
template <class U> int FindPut0(U&& k);
|
||||
template <class U> int FindPut0(U&& k, bool& put);
|
||||
|
||||
template <typename U> int Put0(U&& k, dword sh);
|
||||
template <typename U> void Set0(int i, U&& k);
|
||||
|
|
@ -91,8 +91,10 @@ public:
|
|||
|
||||
int Put(const T& k) { return Put0(k, Smear(k)); }
|
||||
int Put(T&& k) { return Put0(pick(k), Smear(k)); }
|
||||
int FindPut(const T& k) { return FindPut0(k); }
|
||||
int FindPut(T&& k) { return FindPut0(pick(k)); }
|
||||
int FindPut(const T& k, bool& p){ return FindPut0(k, p); }
|
||||
int FindPut(T&& k, bool& p) { return FindPut0(pick(k), p); }
|
||||
int FindPut(const T& k) { bool p; return FindPut0(k); }
|
||||
int FindPut(T&& k) { bool p; return FindPut0(pick(k)); }
|
||||
|
||||
void Unlink(int i);
|
||||
int UnlinkKey(const T& k);
|
||||
|
|
|
|||
|
|
@ -242,10 +242,12 @@ int Index<T>::Put0(U&& k, dword sh)
|
|||
template <class T>
|
||||
template <class U>
|
||||
force_inline
|
||||
int Index<T>::FindPut0(U&& k) {
|
||||
int Index<T>::FindPut0(U&& k, bool& put)
|
||||
{
|
||||
dword sh = Smear(k);
|
||||
int& m = map[sh & mask];
|
||||
int i = m;
|
||||
put = false;
|
||||
if(i >= 0)
|
||||
do {
|
||||
if(key[i] == k)
|
||||
|
|
@ -253,6 +255,7 @@ int Index<T>::FindPut0(U&& k) {
|
|||
i = hash[i].next;
|
||||
}
|
||||
while(i != m);
|
||||
put = true;
|
||||
return Put0(std::forward<U>(k), sh);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -105,7 +105,10 @@ template <class K, class T, class V>
|
|||
template <class KK, class TT>
|
||||
T& AMap<K, T, V>::GetPut_(KK&& k, TT&& x)
|
||||
{
|
||||
int i = key.FindPut(std::forward<KK>(k));
|
||||
bool put = false;
|
||||
int i = key.FindPut(std::forward<KK>(k), put);
|
||||
if(put)
|
||||
return value[i] = std::forward<TT>(x);
|
||||
return i < value.GetCount() ? value[i] : value.Add(std::forward<TT>(x));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
topic "Index";
|
||||
[2 $$0,0#00000000000000000000000000000000:Default]
|
||||
[i448;a25;kKO9;2 $$1,0#37138531426314131252341829483380:class]
|
||||
[l288;2 $$2,0#27521748481378242620020725143825:desc]
|
||||
[0 $$3,0#96390100711032703541132217272105:end]
|
||||
|
|
@ -9,6 +8,7 @@ topic "Index";
|
|||
[l288;i1121;b17;O9;~~~.1408;2 $$7,0#10431211400427159095818037425705:param]
|
||||
[i448;b42;O9;2 $$8,8#61672508125594000341940100500538:tparam]
|
||||
[b42;2 $$9,9#13035079074754324216151401829390:normal]
|
||||
[2 $$0,0#00000000000000000000000000000000:Default]
|
||||
[{_}%EN-US
|
||||
[ {{10000@(113.42.0) [s0; [*@7;4 Index]]}}&]
|
||||
[s3; &]
|
||||
|
|
@ -267,24 +267,11 @@ with the specified value is appended to the end of AIndex using
|
|||
[s6; Invalidates references to Index.&]
|
||||
[s3; &]
|
||||
[s4;%- &]
|
||||
[s5;:Index`:`:FindPut`(const T`&`,unsigned`):%- [@(0.0.255) int]_[* FindPut]([@(0.0.255) co
|
||||
nst]_[*@4 T][@(0.0.255) `&]_[*@3 key], [@(0.0.255) unsigned]_[*@3 `_hash])&]
|
||||
[s5;:Upp`:`:Index`:`:FindPut`(T`&`&`,unsigned`):%- [@(0.0.255) int]_[* FindPut]([*@4 T][@(0.0.255) `&
|
||||
`&]_[*@3 key], [@(0.0.255) unsigned]_[*@3 hash])&]
|
||||
[s2; Retrieves the position of the first element with the value [%-*@3 key]
|
||||
in AIndex, using a precomputed [%-*@3 `_hash]. The precomputed
|
||||
hash value must be the same as the hash value that would be the
|
||||
result of HashFn. If the specified value does not exist in the
|
||||
AIndex, it is placed to it using [* Put(const T`& x, unsigned `_hash).]
|
||||
The position of the found or placed element is returned.&]
|
||||
[s6;~~~.992; Invalidates multi`-key ordering.&]
|
||||
[s6; Invalidates iterators to AIndex.&]
|
||||
[s6; Invalidates references to Index.&]
|
||||
[s6;%- The precomputed [@3 `_hash] must be the same as the hash specified
|
||||
by HashFn.&]
|
||||
[s2; [%-*@3 key] .&]
|
||||
[s3; &]
|
||||
[s4;%- &]
|
||||
[s5;:Upp`:`:Index`:`:FindPut`(const T`&`,bool`&`):%- [@(0.0.255) int]
|
||||
[* FindPut]([@(0.0.255) const] T[@(0.0.255) `&] [*@3 key], [@(0.0.255) bool`&]
|
||||
[*@3 put])&]
|
||||
[s5;:Upp`:`:Index`:`:FindPut`(T`&`&`,bool`&`):%- [@(0.0.255) int] [* FindPut](T[@(0.0.255) `&
|
||||
`&] [*@3 key], [@(0.0.255) bool`&] [*@3 put])&]
|
||||
[s5;:Index`:`:FindPut`(const T`&`):%- [@(0.0.255) int]_[* FindPut]([@(0.0.255) const]_[*@4 T][@(0.0.255) `&
|
||||
]_[*@3 key])&]
|
||||
[s5;:Upp`:`:Index`:`:FindPut`(T`&`&`):%- [@(0.0.255) int]_[* FindPut]([*@4 T][@(0.0.255) `&`&
|
||||
|
|
@ -292,11 +279,12 @@ by HashFn.&]
|
|||
[s2; Retrieves the position of the first element with value [%-*@3 key]
|
||||
in AIndex. If the element does not exist in the AIndex, it is
|
||||
placed to it using [* Put(const T`& x).] The position of the found
|
||||
or placed element is returned.&]
|
||||
or placed element is returned. If element is placed, variants
|
||||
with [%-*@3 put] set it to true.&]
|
||||
[s6; Invalidates multi`-key ordering.&]
|
||||
[s6; Invalidates iterators to AIndex.&]
|
||||
[s6; Invalidates references to Index.&]
|
||||
[s3; &]
|
||||
[s3;%- &]
|
||||
[s4;%- &]
|
||||
[s5;:Index`:`:Set`(int`,const T`&`,unsigned`):%- [*@4 T][@(0.0.255) `&]_[* Set]([@(0.0.255) i
|
||||
nt]_[*@3 i], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x], [@(0.0.255) unsigned]_[*@3 `_ha
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue