Skip to content

Commit

Permalink
Merge pull request #3 from duhaime/math-pow
Browse files Browse the repository at this point in the history
Math pow
  • Loading branch information
duhaime committed Jun 2, 2018
2 parents 1a257cd + a53914d commit 2ac5d1a
Show file tree
Hide file tree
Showing 3 changed files with 757 additions and 933 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "minhash",
"version": "0.0.8",
"version": "0.0.9",
"author": "Douglas Duhaime <douglas.duhaime@gmail.com>",
"description": "Find similar documents quickly",
"license": "MIT",
"main": "index.js",
"scripts": {
"test": "./node_modules/mocha/bin/mocha ./tests/*.js",
Expand All @@ -22,8 +24,7 @@
"webpack": "^4.1.1",
"webpack-cli": "^2.0.10"
},
"author": "Douglas Duhaime <douglas.duhaime@gmail.com>",
"license": "MIT",
"dependencies": {},
"babel": {
"presets": [
"env"
Expand Down
6 changes: 3 additions & 3 deletions src/minhash.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var Minhash = function(config) {
// prime is the smallest prime larger than the largest
// possible hash value (max hash = 32 bit int)
this.prime = 4294967311;
this.maxHash = 2**32-1;
this.maxHash = Math.pow(2, 32) - 1;

// initialize the hash values as the maximum value
this.inithashvalues = function() {
Expand Down Expand Up @@ -51,14 +51,14 @@ var Minhash = function(config) {
this.hash = function(str) {
var hash = 0;
if (str.length == 0) {
return hash + (2**32/2-1);
return hash + this.maxHash;
}
for (var i = 0; i < str.length; i++) {
var char = str.charCodeAt(i);
hash = ((hash<<5)-hash)+char;
hash = hash & hash; // convert to a 32bit integer
}
return hash + (2**32/2-1);
return hash + this.maxHash;
}

// estimate the jaccard similarity to another minhash
Expand Down

0 comments on commit 2ac5d1a

Please sign in to comment.