diff --git a/sources/Data/Collections/HashTable.uc b/sources/Data/Collections/HashTable.uc index 92ae16c..844f343 100644 --- a/sources/Data/Collections/HashTable.uc +++ b/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. *