Hashie
Hashie is a small library that implements a hash data structure.
Installation
npm i hashie
Usage
var Hashie = ; //create a new Hashie object with the desired key.var myHash = 10; myHash;myHash;myHash;myHash;myHash;
What it does
For every element you want to insert (e.g. 543) a new key is generated with a custom modulo (on creation). So the key for var myHash = new Hashie(10)
would be yourNumber % 10
. Hashie will push in the position 3 (from 543) and insert the number 543 there.
API methods
The following methods exist for Hashie (more coming):
//Adds element to data structuremyHash; //Erases certain elementmyHash; //Finds a certain element (boolean)myHash; //Returns the amount of elements in the hashmyHash; //Returns the kays used so farmyHash; //Returns the whole data structuremyHash; //Returns the singular array stored in the hashmyHash; //index of drawer //Erases a certain element of the hashmyHash // number to be deleted //Prints the hashmyHash; //Resets the hashmyHash;
Data types
Hashie accepts ints
and floats
for now.
Colissions
Since it's an array, colissions are handled with a simple push method. so the drawer with key 3 can have multiple values (543, 643, 943, 743, etc).
Optimization
Hashie is designed for large amounts of data that avoid many colissions (e.g. 01192543 with a key of % 100 to be 43). For a set of 150,000 ids, there'd only be around 150 colissions (which is good). This means that for searching for a specific piece of data, instead of looking in 150,000 elements, you'd only look at about 150
Avoid
Adding numbers with the same key (430, 320, 540, 870) exclusively, as this will only generate a single array.