Class HashArray<T>
Type Parameters
- T extends object
Index
Constructors
Accessors
Methods
Properties
Constructors
constructor
- new HashArray<T extends object>(
keyFields?: string | KeyFields,
options?: HashArrayOptions<T>,
): HashArray<T>Type Parameters
- T extends object
Parameters
OptionalkeyFields: string | KeyFieldsA single string or an array of strings / arrays representing what fields on added objects are to be used as keys for the trie search / HashArray.
Optionaloptions: HashArrayOptions<T>Options.
Returns HashArray<T>
Accessors
keyFields
Returns KeyFields
A clone of the current key fields.
size
- get size(): number
Returns number
The mapped size; number of keys in HashArray.
sizeFlat
- get sizeFlat(): number
Returns number
The flattened size; number of items in HashArray.
Methods
add
clear
Clears all items.
Returns this
This instance.
clone
Clones this HashArray. By default, returning an empty HashArray with cloned KeyFields. Set
itemsin options toCloneOps.SHALLOWto copy the items. To fully clone all items setCloneOps.DEEP.Parameters
Optionalopts: { items?: CloneOps; options?: HashArrayOptions<T> }Optional parameters.
Optionalitems?: CloneOpsClone operation for items. By default, no items are included in the clone. Supply
SHALLOWand items are copied. SupplyDEEPand items are cloned as well.Optionaloptions?: HashArrayOptions<T>Optional change to options for the clone that is merged with current HashArray options.
Returns HashArray<T>
collides
entries
Returns IterableIterator<[string, T[]]>
An entries iterator w/ key and all associated values.
entriesFlat
filter
forEach
forEachDeep
Iterates over all items retrieved by the given key invoking the callback function for each item with the value found by the
indexKey and the item itself.Parameters
Returns this
This instance.
get
getAll
getAsArray
Gets item(s) by the given key always returning an array including an empty array when key is not in the HashArray.
Parameters
- key: string
The key for item(s) to retrieve.
Returns T[]
All items for key or empty array.
- key: string
getAt
Gets the item stored in the flat list of all items at the given index.
Parameters
- index: number
The index to retrieve.
Returns T
- index: number
has
Verifies if this HashArray has this key.
Parameters
- key: string
The key to check.
Returns boolean
Whether this HashArray already has the given key.
- key: string
intersection
keys
Returns IterableIterator<string>
A keys iterator.
remove
removeByKey
Remove item(s) associated with the given keys from the HashArray.
Parameters
- ...keys: string[]
Keys associated with the item(s) to be removed.
Returns this
This instance.
- ...keys: string[]
removeFirst
When treating HashArray as a cache removing the first item removes the oldest item.
Returns this
This instance.
removeLast
When treating HashArray as a cache removing the last item removes the newest item.
Returns this
This instance.
values
Returns IterableIterator<T[]>
A values iterator / all items values grouped by key.
valuesFlat
Returns IterableIterator<T>
A flat values iterator by default in order added.
Properties
Static ReadonlyCloneOps
An enum used in HashArray.clone determining how items are handled.
HashArray is a data structure that combines the best feature of a hash (O(1) retrieval) and an array (length and ordering). Think of it as a super-lightweight, extensible, self-indexing set database in memory.