Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hashes

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hashes - npm Package Compare versions

Comparing version 0.0.2 to 0.1.0

hashes.js

6

package.json
{
"name": "hashes",
"version" : "0.0.2",
"description": "A package implementing a 'real' Hashtable and (soon) Hashset",
"version" : "0.1.0",
"description": "A package implementing a HashTable and HashSet",
"author": "Boris Kozorovitzky",
"main":"hashtable.js",
"main":"hashes.js",
"keywords":[

@@ -8,0 +8,0 @@ "hashtable",

jsHash
======
A node package that implements the Hashtable and HashSet (in the near future) datastructures.
A node package that implements the HashTable and HashSet data structures.

@@ -12,4 +12,17 @@ Install:

###General
A HashTable (a.k.a Dictionary or HashMap) is a data structures that contains pairs of key and value.
The key may provide a _getHashCode_ function that returns a non-unique string value that represents that key and/or
an _equal(1)_ function that checks if the given key is equal to the given argument. **Note: If two keys are equal they must have the same hash code!**
This data structure allows fast retrieval of the stored values using the keys. Please refer to the [WiKi article](http://en.wikipedia.org/wiki/Hash_table) for more information.
In this implementation each of the two aforementioned functions is calculated in the following order:
1. The function that was provided in the options.
2. The function on the key object.
3. A default function from the _statics_ object.
A HashSet is similar to the HashTable but it stores only the keys. The data should be stored within the key. All the rules of the HashTable apply to the HashSet.
##API
Currently only a hashtable is implemented.

@@ -22,5 +35,15 @@ To use the module in your code simply type

###Hashtable
To create a new hash table use the _new_ keyword:
###Options
You may provide an optional argument to the constructors called _options_. The options object can have any of the following methods and properties:
* **getHashCode(key)** - Returns the hash code of the given _key_ object.
* **equal(first, second)** - Returns true if the given arguments are equal, and false otherwise.
The options object is used throughout the different API calls. By default, providing any of these functions will override
the default functions and the key specific functions by that name.
###HashTable
To create a new HashTable use the _new_ keyword:
```

@@ -30,28 +53,61 @@ var myHashTable = new hashes.HashTable();

You may provide an optional argument to the constructor called _options_. The options object can have any of the following methods and properties:
* **HashTable([options])** - Creates a new instance of the HashTable object. An optional _options_ argument can be provided (see above).
* **getHashCode(key)** - Returns the hash code of the given _key_ object.
* **add(key, value, [overwriteIfExists])** - Adds the given key-value pair to the HashTable. _overwriteIfExists_ is an optional argument that is used when the given key already exists in the HashTable.
If _overwriteIfExists_ is truthy then the given key-value pair will overwrite the existing key-value pair, otherwise the given key-value pair will not be added to the HashTable.
* **equal(first, second)** - Returns true if the given arguments are equal, and false otherwise.
* **get(key)** - Returns the key-value pair associated with the given key. If there is no key-value pair associated with the given key, null is returned. The returned object is ```{key:key, value:value}```.
(Note that a pair is returned because the key in the HashTable may differ from the provided key.)
The options object is used throughout the diffrent API calls. The API of the hashtable is therefore:
* **remove(key)** - Removes the key-value pair associated with the given key from the HashTable. Returns true if a key-value pair was removed and false otherwise (e.g. when there is no value associated with the given key).
* **add(key, value, [overwriteIfExists])** - Adds the given key-value pair to the hashtable. _overwriteIfExists_ is an optional argument that is used when the given key already exists in the hashtable.
If _overwriteIfExists_ is truthy then the given key-value pair will overwrite the existing key-value pair, otherwise the given key-value pair will not be added to the hashtable.
* **contains(key)** - Returns true if there is a value associated with the given key and false otherwise.
* **get(key)** - Returns the key-value pair associated with the given key. If there is no key-value pair associated with the given key, null is returned. The returned object is ```{key:key, value:value}```.
(Note that a pair is returned because the key in the hashtable may differ from the provided key.)
* **getHashes()** - Returns a string array of all the hashes that are currently in the HashTable.
* **remove(key)** - Removes the key-value pair associated with the given key from the hashtable. Returns true if a key-value pair was removed and false otherwise (e.g. when there is no value associated with the given key).
* **getKeyValuePairs()** - Returns an array of all the key-value pairs in the HashTable **in no particular order**. Each object in the returned array is ```{key:key, value:value}```.
* **contains(key)** - Returns true if there is a value associated with the given key and false otherwise.
* **count()** - Returns the number of key-value pairs in the HashTable.
* **getHashes()** - Returns a string array of all the hashes that are currently in the hashtable.
* **clear()** - Removes all the key-value pairs from the HashTable.
* **getKeyValuePairs()** - Returns an array of all the key-value pairs in the hashtable **in no particular order**. Each object in the returned array is ```{key:key, value:value}```.
* **clone()** - Returns a copy of the HashTable. All user elements are copied by reference.
* **count()** - Returns the number of key-value pairs in the hashtable.
* **rehash(options, overwriteIfExists)** - Returns a copy of the HashTable but all the key-value pairs are re-insrted using the new options. _overwriteIfExists_ is handled the same way as in the _add_ function.
* **clear()** - Removes all the key-value pairs from the hashtable.
###HashSet
To create a new HashSet use the _new_ keyword:
```
var myHashSet = new hashes.HashSet();
```
* **HashSet([options])** - Creates a new instance of the HashSet object. An optional _options_ argument can be provided (see above).
* **add(key, [overwriteIfExists])** - Adds the given key to the HashSet. _overwriteIfExists_ is an optional argument that is used when the given key already exists in the HashSet.
If _overwriteIfExists_ is truthy then the given key will overwrite the existing key, otherwise the given key is ignored.
* **get(key)** - Returns the key in the HashSet which is equal to the given key. If there is no key equal to the given key, null is returned.
* **remove(key)** - Removes the key from the HashSet. Returns true if a key was removed and false otherwise.
* **contains(key)** - Returns true if the given key is in the HashSet and false otherwise.
* **getHashes()** - Returns a string array of all the hashes that are currently in the HashSet.
* **getKeys()** - Returns an array of all the keys in the HashSet **in no particular order**.
* **count()** - Returns the number of keys the HashSet.
* **clear()** - Removes all the keys from the HashSet.
* **clone()** - Returns a copy of the HashSet. All user elements are copied by reference.
* **rehash(options, overwriteIfExists)** - Returns a copy of the HashSet but all the keys are re-insrted using the new options. _overwriteIfExists_ is handled the same way as in the _add_ function.
###statics
The _statics_ object is used internally to control the behavior of **all** the HashTable and HashSet instances.
You may override the functions of this object but this is an advanced use case.
## Contributions

@@ -66,2 +122,14 @@ Please feel free to contribute code to this module. Make sure that the contributed code is in the spirit of the existing code.

## ChangeLog
0.0.2 -> 0.1.0
* **Breaking** - Renamed the class from Hashtable to HashTable (note the capital 'T')
* **Breaking** - Moved some static functions of HashTable class to the statics object to accommodate the new HashSet class
* Added the HashSet class
* Added the _clone_ and _rehash_ functions to the HashTable class
* Fixed a bug in the get method where the key was not returned
* Fixed some global leaks
* Fixed some other code issues that jsHint didn't like
* Fixed a bug with the clone method not setting count properly
* Changed so that now only the relevant options are copied from the options object provided and a reference to the original object is not stored.
## License

@@ -68,0 +136,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc