alib-hashtable
A Javascript hashtable implementation
Install
Install with npm:
$ npm i alib-hashtable --save
Usage
const hashtable = ; //new instanceconst myHashTable = ;
id refers to the key prop name for any added objects.
Load items - used to initially fill the hashtable with objects
myHashTable
set - inserts an item or if an item is there with matching key updates existing
myHashTable;
set can optionally be sent a compare function to set the items position
get - Returns the object with the associated key
myHashTable;//=> {id:'parisvb', name:'Paris', surname:'Val Baker', age: 44}
position - Returns the position of the object with the associated key, if not found it returns null
myHashTable;//=> 1
remove - Removes an object with the associated key from the hashtable
myHashTable;
pop - Removes an object from end of hashtable and returns it
myHashTable;//=> {id:'rowenavb', name:'Rowena', surname:'Val Baker'}
length - Returns number of items in hashtable
myHashTablelength;//=> 2
clear - Empties the hashtable
myHashTableclear;
getCollection - Returns array of objects in the hashtable in order
myHashTable;//=> [{id:'parisvb', name:'Paris', surname:'Val Baker', age: 44}, {id:'rowenavb', name:'Rowena', surname:'Val Baker'}]