1.1.2 • Published 5 years ago

alib-hashtable v1.1.2

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

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'}]
1.1.2

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago