Socket
Socket
Sign inDemoInstall

hashtabler.js

Package Overview
Dependencies
2
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    hashtabler.js

Library with a hash table.


Version published
Weekly downloads
3
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Hashtabler.js

This library include a hash table

Methods

/**
 * Insert object
 *
 * @param {Object} object
 * @param {String} key
 * @returns {string} key
 */
insert(object, key = null);
/**
 * Find key
 *
 * @param {String} key
 * @returns {Object|undefined} Returns the object if key exists.
 */
get(key);
/**
 * Return true if key exists
 *
 * @param {String} key
 * @returns {boolean}
 */
existsKey(key);
/**
 * Calculate new key
 *
 * @param {Object} object
 * @returns {String}
 */
calculateKey(object);
/**
 * Delete object
 *
 * @param {String} key
 * @returns {boolean} Returns true if key are deleted.
 */
delete(key);
/**
 * Delete all objects
 *
 * @returns {boolean}
 */
clear();

Example

const { Hashtabler } = require('hashtabler');

let table = new Hashtabler();
let person1 = {
  name: 'Ricardo',
  age: 26
};
let person2 = {
    name: 'John',
    age: 32
};

let key1 = table.insert(person1);
console.log(key1); //87c7219c3741dc3a2019fbc9c30c1d846168bd6f
let key2 = table.insert(person2);
console.log(key2); //02f6a83a50b673a00a444f04008711e0f86f1451

let list = table.get(key1);
for (let item of list) {
    console.log(item); //{ name: 'Ricardo', age: 26 }
}

table.delete(key1);
console.log(table.get(key1)); //undefined

let key = table.insert(person2, 'PRS:{2}');
console.log(key); //{ name: 'Ricardo', age: 26 }

list = table.get(key);
for (let item of list) {
    console.log(item); //{ name: 'John', age: 32 }
}

Keywords

FAQs

Last updated on 13 Jul 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc