namastey-hash-set
v1.0.0
Published
A package implementing the Hash Set data structure with efficient operations for storing unique elements.
Downloads
8
Maintainers
Readme
namastey-hash-set
Brief Description:
namastey-hash-set
is a JavaScript package that implements a Hash Set data structure. It provides efficient methods to manage unique values.
Features:
- add(value): Adds a value to the set if it is not already present.
- remove(value): Removes a value from the set.
- has(value): Checks if a value is present in the set.
- size(): Returns the number of elements in the set.
- values(): Returns an array of all elements in the set.
- clear(): Removes all elements from the set.
Installation:
You can install namastey-hash-set
globally using npm:
npm install -g namastey-hash-set
Examples
const HashSet = require('namastey-hash-set');
const mySet = new HashSet();
mySet.add('apple');
mySet.add('banana');
console.log(mySet.values()); // Output: [ 'apple', 'banana' ]
console.log(mySet.has('apple')); // Output: true
console.log(mySet.has('cherry')); // Output: false
mySet.remove('banana');
console.log(mySet.values()); // Output: [ 'apple' ]
console.log(mySet.size()); // Output: 1
mySet.clear();
console.log(mySet.values()); // Output: []