namastey-hash-table
v1.0.0
Published
A powerful and efficient implementation of hash tables for JavaScript, optimized for performance and scalability.
Downloads
15
Maintainers
Readme
namastey-hash-table
A simple and efficient JavaScript implementation of a Hash Table with various important methods.
Features
set(key, value)
: Adds a key-value pair to the hash table. If the key already exists, it updates the value.get(key)
: Retrieves the value associated with the given key. Returnsundefined
if the key does not exist.delete(key)
: Removes the key-value pair from the hash table. Returnstrue
if the pair was removed,false
otherwise.has(key)
: Checks if the key exists in the hash table. Returnstrue
if the key exists,false
otherwise.keys()
: Returns an array of all the keys in the hash table.values()
: Returns an array of all the values in the hash table.
Installation
To install the package globally, run:
npm install -g .
Examples
const HashTable = require('namastey-hash-table');
const hashTable = new HashTable();
hashTable.set('name', 'Alice');
console.log(hashTable.get('name')); // Output: Alice
hashTable.set('age', 25);
console.log(hashTable.keys()); // Output: ['name', 'age']
console.log(hashTable.values()); // Output: ['Alice', 25]
hashTable.delete('age');
console.log(hashTable.has('age')); // Output: false