mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
Core: ValueMap::RemoveKey #470
git-svn-id: svn://ultimatepp.org/upp/trunk@6252 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
6cf6bab74c
commit
63ea42e7e9
3 changed files with 36 additions and 0 deletions
|
|
@ -500,6 +500,23 @@ void ValueMap::SetKey(int i, const Value& k) {
|
|||
Clone().key.Set(i, k);
|
||||
}
|
||||
|
||||
int ValueMap::RemoveKey(const Value& key)
|
||||
{
|
||||
Data& d = Clone();
|
||||
Vector<int> rk;
|
||||
int q = d.key.Find(key);
|
||||
while(q >= 0) {
|
||||
rk.Add(q);
|
||||
q = d.key.FindNext(q);
|
||||
}
|
||||
int count = rk.GetCount();
|
||||
if(count) {
|
||||
d.key.Remove(rk);
|
||||
d.value.data->data.Remove(rk);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void ValueMap::Remove(int i)
|
||||
{
|
||||
Data& d = Clone();
|
||||
|
|
|
|||
|
|
@ -209,6 +209,7 @@ class ValueArray : ValueType<ValueArray, VALUEARRAY_V, Moveable<ValueArray> > {
|
|||
|
||||
friend Value::Void *ValueArrayDataCreate();
|
||||
friend class Value;
|
||||
friend class ValueMap;
|
||||
|
||||
public:
|
||||
ValueArray() { Init0(); }
|
||||
|
|
@ -323,6 +324,12 @@ public:
|
|||
void SetKey(int i, const char* key) { SetKey(i, Value(key)); }
|
||||
void SetKey(int i, int key) { SetKey(i, Value(key)); }
|
||||
void SetKey(int i, Id key) { SetKey(i, Value(key.ToString())); }
|
||||
|
||||
int RemoveKey(const Value& key);
|
||||
int RemoveKey(const String& key) { return RemoveKey(Value(key)); }
|
||||
int RemoveKey(const char* key) { return RemoveKey(Value(key)); }
|
||||
int RemoveKey(int key) { return RemoveKey(Value(key)); }
|
||||
int RemoveKey(Id key) { return RemoveKey(Value(key.ToString())); }
|
||||
void Remove(int i);
|
||||
|
||||
const Index<Value>& GetKeys() const { return data->key; }
|
||||
|
|
|
|||
|
|
@ -168,6 +168,18 @@ t]_[*@3 i], [@(0.0.255) const]_[@(0.0.255) char`*]_[*@3 key])&]
|
|||
required to make Id and SqlId work with ValueMap.&]
|
||||
[s3; &]
|
||||
[s4;%- &]
|
||||
[s5;:ValueMap`:`:RemoveKey`(const Value`&`):%- [@(0.0.255) int]_[* RemoveKey]([@(0.0.255) c
|
||||
onst]_[_^Value^ Value][@(0.0.255) `&]_[*@3 key])&]
|
||||
[s5;:ValueMap`:`:RemoveKey`(const String`&`):%- [@(0.0.255) int]_[* RemoveKey]([@(0.0.255) c
|
||||
onst]_[_^String^ String][@(0.0.255) `&]_[*@3 key])&]
|
||||
[s5;:ValueMap`:`:RemoveKey`(const char`*`):%- [@(0.0.255) int]_[* RemoveKey]([@(0.0.255) co
|
||||
nst]_[@(0.0.255) char`*]_[*@3 key])&]
|
||||
[s5;:ValueMap`:`:RemoveKey`(int`):%- [@(0.0.255) int]_[* RemoveKey]([@(0.0.255) int]_[*@3 key
|
||||
])&]
|
||||
[s5;:ValueMap`:`:RemoveKey`(Id`):%- [@(0.0.255) int]_[* RemoveKey]([_^Id^ Id]_[*@3 key])&]
|
||||
[s2; Removes all key`-value pairs with given key. Slow O(n) operation.&]
|
||||
[s3; &]
|
||||
[s4;%- &]
|
||||
[s5;:ValueMap`:`:Remove`(int`):%- [@(0.0.255) void]_[* Remove]([@(0.0.255) int]_[*@3 i])&]
|
||||
[s2; Removes key`-value pair at index [%-*@3 i].&]
|
||||
[s3; &]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue