alib-hashtable

1.1.2 • Public • Published

alib-hashtable

A Javascript hashtable implementation

Install

Install with npm:

$ npm i alib-hashtable --save

Usage

const hashtable = require('alib-hashtable');
 
//new instance
const myHashTable = hashtable('id');

id refers to the key prop name for any added objects.

Load items - used to initially fill the hashtable with objects

myHashTable.load([{id:'parisvb', name:'Paris', surname:'Val Baker'}, {id:'rowenavb', name:'Rowena', surname:'Val Baker'}])

set - inserts an item or if an item is there with matching key updates existing

myHashTable.set({id:'parisvb', name:'Paris', surname:'Val Baker', age: 44});

set can optionally be sent a compare function to set the items position

get - Returns the object with the associated key

myHashTable.get('parisvb');
//=> {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.position('rowenavb');
//=> 1

remove - Removes an object with the associated key from the hashtable

myHashTable.remove('parisvb');

pop - Removes an object from end of hashtable and returns it

myHashTable.pop();
//=> {id:'rowenavb', name:'Rowena', surname:'Val Baker'}

length - Returns number of items in hashtable

myHashTable.length();
//=> 2

clear - Empties the hashtable

myHashTable.clear();

getCollection - Returns array of objects in the hashtable in order

myHashTable.getCollection();
//=> [{id:'parisvb', name:'Paris', surname:'Val Baker', age: 44}, {id:'rowenavb', name:'Rowena', surname:'Val Baker'}]

Readme

Keywords

Package Sidebar

Install

npm i alib-hashtable

Weekly Downloads

5

Version

1.1.2

License

MIT

Unpacked Size

10.4 kB

Total Files

5

Last publish

Collaborators

  • pastyman