Browse Source

Add `TakeItem()` an ability to deallocate key

pull/8/head
Anton Tarasenko 3 years ago
parent
commit
ec3a751162
  1. 14
      sources/Data/Collections/AssociativeArray.uc

14
sources/Data/Collections/AssociativeArray.uc

@ -320,12 +320,22 @@ public final function Entry TakeEntry(AcediaObject key)
* and must be deallocated once you do not need it anymore.
*
* @param key Key for which to return value.
* @param freeKey Setting this to `true` will also free the key item was
* stored with. Passed argument `key` will not be deallocated, unless it is
* the exact same object as item's key inside caller collection.
* @return Value, stored with given key `key`. If there is no value with
* such a key method will return `none`.
*/
public final function AcediaObject TakeItem(AcediaObject key)
public final function AcediaObject TakeItem(
AcediaObject key,
optional bool freeKey)
{
return TakeEntry(key).value;
local Entry entry;
entry = TakeEntry(key);
if (freeKey) {
_.memory.Free(entry.key);
}
return entry.value;
}
/**

Loading…
Cancel
Save