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.1.1 to 0.1.2

.npmignore

159

hashes.js

@@ -82,3 +82,3 @@

var result = {};
if (options.hasOwnProperty("getHashCode")){
if (options.hasOwnProperty("getHashCode")) {
result.getHashCode = options.getHashCode;

@@ -159,3 +159,80 @@ }

///Creates a new HashTable which is an intersection of the first and second HashTables. You may specify an optional options parameter and
///an optional overwriteIfExists parameter. The options are used to create the result HashTable and all the key-value pairs are added accordingly.
///overwriteIfExists is used to add the elements to the resulting HashTable that might have different options (see the add function for details).
///In any case the key-value pairs from the first HashTable are in the result.
HashTable.intersection = function (first, second, options, overwriteIfExists) {
var firstLength = first.count(),
secondLength = second.count(),
result, i, keyValuePairs, tempPair;
result = new HashTable(options);
if (firstLength < secondLength) {
keyValuePairs = first.getKeyValuePairs();
for (i = 0; i < firstLength; i += 1) {
if (second.contains(keyValuePairs[i].key)) {
result.add(keyValuePairs[i].key, keyValuePairs[i].value, overwriteIfExists);
}
}
} else {
keyValuePairs = second.getKeyValuePairs();
for (i = 0; i < secondLength; i += 1) {
tempPair = first.get(keyValuePairs[i].key);
if (tempPair !== null) {
result.add(tempPair.key, tempPair.value, overwriteIfExists);
}
}
}
return result;
};
///Creates a new HashTable which is the difference of the first and second HashTables (i.e. all the key-value pairs which are in the first HashTable but not in the second HashTable).
///You may specify an optional options parameter and an optional overwriteIfExists parameter. The options are used to create the result HashTable and all the key-value pairs are added accordingly.
///overwriteIfExists is used to add the elements to the resulting HashTable that might have different options (see the add function for details).
///In any case the key-value pairs from the first HashTable are in the result.
HashTable.difference = function (first, second, options, overwriteIfExists) {
var i, length, keyValuePairs, result = new HashTable(options), pair;
keyValuePairs = first.getKeyValuePairs();
length = first.count();
for (i = 0; i < length; i += 1) {
pair = keyValuePairs[i];
if (!second.contains(pair.key, pair.value)) {
result.add(pair.key, pair.value, overwriteIfExists);
}
}
return result;
};
///Creates a new HashTable which is the symmetric difference of the first and second HashTables (i.e. all the key-value pairs which are in the first HashTable but not in the second HashTable
//or in the second HashTable but not in the first).
///You may specify an optional options parameter and an optional overwriteIfExists parameter. The options are used to create the result HashTable and all the key-value pairs are added accordingly.
///overwriteIfExists is used to add the elements to the resulting HashTable that might have different options (see the add function for details).
HashTable.symmetricDifference = function (first, second, options, overwriteIfExists) {
var i, length, keyValuePairs, result = new HashTable(options), pair;
keyValuePairs = first.getKeyValuePairs();
length = first.count();
for (i = 0; i < length; i += 1) {
pair = keyValuePairs[i];
if (!second.contains(pair.key, pair.value)) {
result.add(pair.key, pair.value, overwriteIfExists);
}
}
keyValuePairs = second.getKeyValuePairs();
length = second.count();
for (i = 0; i < length; i += 1) {
pair = keyValuePairs[i];
if (!first.contains(pair.key, pair.value)) {
result.add(pair.key, pair.value, false);
}
}
return result;
};
//Prototype functions

@@ -455,2 +532,82 @@

///Creates a new HashSet which is an intersection of the first and second HashSets. You may specify an optional options parameter and
///an optional overwriteIfExists parameter. The options are used to create the result HashSet and all the keys are added accordingly.
///overwriteIfExists is used to add the elements to the resulting HashSet that might have different options (see the add function for details).
///In any case the keys from the first HashSet are in the result.
HashSet.intersection = function (first, second, options, overwriteIfExists) {
var firstLength = first.count(),
secondLength = second.count(),
result, i, keys, tempKey;
result = new HashSet(options);
if (firstLength < secondLength) {
keys = first.getKeys();
for (i = 0; i < firstLength; i += 1) {
tempKey = keys[i];
if (second.contains(tempKey)) {
result.add(tempKey, overwriteIfExists);
}
}
} else {
keys = second.getKeys();
for (i = 0; i < secondLength; i += 1) {
tempKey = first.get(keys[i]);
if (tempKey !== null) {
result.add(tempKey, overwriteIfExists);
}
}
}
return result;
};
///Creates a new HashSet which is the difference of the first and second HashSets (i.e. all the keys which are in the first HashSet but not in the second HashSet).
///You may specify an optional options parameter and an optional overwriteIfExists parameter. The options are used to create the result HashSet and all the keys are added accordingly.
///overwriteIfExists is used to add the elements to the resulting HashSet that might have different options (see the add function for details).
///In any case the keys from the first HashSet are in the result.
HashSet.difference = function (first, second, options, overwriteIfExists) {
var i, length, keys, result = new HashSet(options), tempKey;
keys = first.getKeys();
length = first.count();
for (i = 0; i < length; i += 1) {
tempKey = keys[i];
if (!second.contains(tempKey)) {
result.add(tempKey, overwriteIfExists);
}
}
return result;
};
///Creates a new HashSet which is the symmetric difference of the first and second HashSets (i.e. all the keys which are in the first HashSet but not in the second HashSet
//or in the second HashSet but not in the first).
///You may specify an optional options parameter and an optional overwriteIfExists parameter. The options are used to create the result HashSet and all the keys are added accordingly.
///overwriteIfExists is used to add the elements to the resulting HashSet that might have different options (see the add function for details).
HashSet.symmetricDifference = function (first, second, options, overwriteIfExists) {
var i, length, keys, result = new HashSet(options), tempKey;
keys = first.getKeys();
length = first.count();
for (i = 0; i < length; i += 1) {
tempKey = keys[i];
if (!second.contains(tempKey)) {
result.add(tempKey, overwriteIfExists);
}
}
keys = second.getKeys();
length = second.count();
for (i = 0; i < length; i += 1) {
tempKey = keys[i];
if (!first.contains(tempKey)) {
result.add(tempKey, false);
}
}
return result;
};
//Prototype functions

@@ -457,0 +614,0 @@

4

package.json
{
"name": "hashes",
"version" : "0.1.1",
"version" : "0.1.2",
"description": "A package implementing a HashTable and HashSet",

@@ -10,3 +10,3 @@ "author": "Boris Kozorovitzky",

"datastructures",
"hash","hash table"
"hash","hash table","hashset", "set"
],

@@ -13,0 +13,0 @@ "homepage":"https://github.com/BorisKozo/jsHash",

@@ -90,4 +90,21 @@ jsHash

When _overwriteIfExists_ is true and a key from the second HashTable already exists in the first HashTable the entire key-value pair is overwritten in the result.
If _overwriteIfExists_ is false then the key-value pair from the second HashTable is ignored.
If _overwriteIfExists_ is false then the key-value pair from the second HashTable is ignored. In any case the key-value pairs from the first HashTable are in the result.
* **[static] intersection(first, second, [options], [overwriteIfExists])** - Creates a new HashTable which is an intersection of the first and second HashTables.
You may specify an optional _options_ parameter and an optional _overwriteIfExists_ parameter. The options are used to create the result HashTable and all the key-value pairs are added accordingly.
When _overwriteIfExists_ is true and a key from the second HashTable already exists in the first HashTable the entire key-value pair is overwritten in the result.
If _overwriteIfExists_ is false then the key-value pair from the second HashTable is ignored. In any case the key-value pairs from the first HashTable are in the result.
* **[static] difference(first, second, [options], [overwriteIfExists])** - Creates a new HashTable which is the difference of the first and second HashTables (i.e. all the key-value pairs which are in the first HashTable but not in the second HashTable).
You may specify an optional _options_ parameter and an optional _overwriteIfExists_ parameter. The options are used to create the result HashTable and all the key-value pairs are added accordingly.
When _overwriteIfExists_ is true and a key from the second HashTable already exists in the first HashTable the entire key-value pair is overwritten in the result.
If _overwriteIfExists_ is false then the key-value pair from the second HashTable is ignored.
* **[static] symmetricDifference(first, second, [options], [overwriteIfExists])** - Creates a new HashTable which is the symmetric difference of the first and second HashTables (i.e. all the key-value pairs which are in the first HashTable but not in the second HashTable
or in the second HashTable but not in the first).
You may specify an optional _options_ parameter and an optional _overwriteIfExists_ parameter. The options are used to create the result HashTable and all the key-value pairs are added accordingly.
When _overwriteIfExists_ is true and a key from the second HashTable already exists in the first HashTable the entire key-value pair is overwritten in the result.
If _overwriteIfExists_ is false then the key-value pair from the second HashTable is ignored.
###HashSet

@@ -136,5 +153,21 @@ To create a new HashSet use the _new_ keyword:

###statics
* **[static] intersection(first, second, [options], [overwriteIfExists])** - Creates a new HashSet which is an intersection of the first and second HashSets.
You may specify an optional _options_ parameter and an optional _overwriteIfExists_ parameter. The options are used to create the result HashSet and all the keys are added accordingly.
When _overwriteIfExists_ is true and a key from the second HashSet already exists in the first HashSet the key is overwritten in the result.
If _overwriteIfExists_ is false then the key from the second HashSet is ignored. In any case the keys from the first HashSet are in the result.
* **[static] difference(first, second, [options], [overwriteIfExists])** - Creates a new HashSet which is the difference of the first and second HashSets (i.e. all the keys which are in the first HashSet but not in the second HashSet).
You may specify an optional _options_ parameter and an optional _overwriteIfExists_ parameter. The options are used to create the result HashSet and all the keys are added accordingly.
When _overwriteIfExists_ is true and a key from the second HashSet already exists in the first HashSet the key is overwritten in the result.
If _overwriteIfExists_ is false then the key from the second HashSet is ignored.
* **[static] symmetricDifference(first, second, [options], [overwriteIfExists])** - Creates a new HashSet which is the symmetric difference of the first and second HashSets (i.e. all the keys which are in the first HashSet but not in the second HashSet
or in the second HashSet but not in the first).
You may specify an optional _options_ parameter and an optional _overwriteIfExists_ parameter. The options are used to create the result HashSet and all the keys are added accordingly.
When _overwriteIfExists_ is true and a key from the second HashSet already exists in the first HashSet the key is overwritten in the result.
If _overwriteIfExists_ is false then the key from the second HashSet is ignored.
###statics object
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.
You may override the functions of this object but this is an advanced use-case.

@@ -152,2 +185,6 @@

## ChangeLog
0.1.1 -> 0.1.2
* Added static intersection, difference and symmetricDiffrence functions to both HashTable and HashSet
0.1.0 -> 0.1.1

@@ -154,0 +191,0 @@

@@ -163,3 +163,53 @@ /*global describe:true, it:true*/

it('should intersect two HashSets using the static method', function () {
var hashset1 = new jsHash.HashSet(),
hashset2 = new jsHash.HashSet(),
result;
hashset1.add("a");
hashset1.add("e");
hashset2.add("a");
hashset2.add("c");
result = jsHash.HashSet.intersection(hashset1, hashset2);
should.exist(result);
result.count().should.equal(1);
result.get("a").should.equal("a");
});
it('should calculate the difference of two HashSets using the static method', function () {
var hashset1 = new jsHash.HashSet(),
hashset2 = new jsHash.HashSet(),
result;
hashset1.add("a");
hashset1.add("e");
hashset2.add("a");
hashset2.add("c");
result = jsHash.HashSet.difference(hashset1, hashset2);
should.exist(result);
result.count().should.equal(1);
result.get("e").should.equal("e");
});
it('should calculate the symmetric difference of two HashSets using the static method', function () {
var hashset1 = new jsHash.HashSet(),
hashset2 = new jsHash.HashSet(),
result;
hashset1.add("a");
hashset1.add("e");
hashset2.add("a");
hashset2.add("c");
result = jsHash.HashSet.symmetricDifference(hashset1, hashset2);
should.exist(result);
result.count().should.equal(2);
result.get("e").should.equal("e");
result.get("c").should.equal("c");
});
});

@@ -214,2 +214,52 @@ /*global describe:true, it:true*/

});
it('should intersect two HashTables using the static method', function () {
var hashtable1 = new jsHash.HashTable(),
hashtable2 = new jsHash.HashTable(),
result;
hashtable1.add("a", "b");
hashtable1.add("e", "f");
hashtable2.add("a", "b");
hashtable2.add("c", "d");
result = jsHash.HashTable.intersection(hashtable1, hashtable2);
should.exist(result);
result.count().should.equal(1);
result.get("a").value.should.equal("b");
});
it('should calculate the difference of two HashTables using the static method', function () {
var hashtable1 = new jsHash.HashTable(),
hashtable2 = new jsHash.HashTable(),
result;
hashtable1.add("a", "b");
hashtable1.add("e", "f");
hashtable2.add("a", "b");
hashtable2.add("c", "d");
result = jsHash.HashTable.difference(hashtable1, hashtable2);
should.exist(result);
result.count().should.equal(1);
result.get("e").value.should.equal("f");
});
it('should calculate the symmetric difference of two HashTables using the static method', function () {
var hashtable1 = new jsHash.HashTable(),
hashtable2 = new jsHash.HashTable(),
result;
hashtable1.add("a", "b");
hashtable1.add("e", "f");
hashtable2.add("a", "ff");
hashtable2.add("c", "d");
result = jsHash.HashTable.symmetricDifference(hashtable1, hashtable2);
should.exist(result);
result.count().should.equal(2);
result.get("e").value.should.equal("f");
result.get("c").value.should.equal("d");
});
});

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