Browse Source

Add `Append` method to `HashTable`

core_refactor
Anton Tarasenko 2 years ago
parent
commit
59d6ca492d
  1. 31
      sources/Data/Collections/HashTable.uc

31
sources/Data/Collections/HashTable.uc

@ -197,6 +197,37 @@ private final function ResizeHashTable(int newSize)
}
}
/**
* Appends objects from another `HashTable` to the caller one.
*
* @param other Array to append objects from. `none` means nothing will be
* added.
* @return Reference to the caller `HashTable` to allow for method chaining.
*/
public final function HashTable Append(HashTable other)
{
local AcediaObject nextKey, nextValue;
local HashTableIterator iter;
if (other == none) return self;
if (other.GetLength() <= 0) return self;
iter = HashTableIterator(other.Iterate());
while (!iter.HasFinished())
{
nextKey = iter.GetKey();
nextValue = iter.Get();
if (!HasKey(nextKey)) {
SetItem(nextKey, nextValue);
}
_.memory.Free(nextKey);
_.memory.Free(nextValue);
iter.Next();
}
_.memory.Free(iter);
return self;
}
/**
* Returns minimal capacity of the caller associative array.
*

Loading…
Cancel
Save