string-hash
Advanced tools
Comparing version 1.1.2 to 1.1.3
13
index.js
@@ -1,7 +0,10 @@ | ||
module.exports = function(str) { | ||
"use strict"; | ||
function hash(str) { | ||
var hash = 5381, | ||
i = str.length | ||
i = str.length; | ||
while(i) | ||
hash = (hash * 33) ^ str.charCodeAt(--i) | ||
while(i) { | ||
hash = (hash * 33) ^ str.charCodeAt(--i); | ||
} | ||
@@ -13,1 +16,3 @@ /* JavaScript does bitwise operations (like XOR, above) on 32-bit signed | ||
} | ||
module.exports = hash; |
{ | ||
"name": "string-hash", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "fast string hashing function", | ||
@@ -22,4 +22,7 @@ "license": "CC0-1.0", | ||
"devDependencies": { | ||
"mocha": "1.3.x" | ||
"mocha": "*" | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
} | ||
} |
13
test.js
@@ -0,12 +1,13 @@ | ||
"use strict"; | ||
var assert = require("assert"), | ||
hash = require("./") | ||
hash = require("./"); | ||
describe("hash", function() { | ||
it("should hash \"Mary had a little lamb.\" to 1766333550", function() { | ||
assert.equal(hash("Mary had a little lamb."), 1766333550) | ||
}) | ||
assert.equal(hash("Mary had a little lamb."), 1766333550); | ||
}); | ||
it("should hash \"Hello, world!\" to 343662184", function() { | ||
assert.equal(hash("Hello, world!"), 343662184) | ||
}) | ||
}) | ||
assert.equal(hash("Hello, world!"), 343662184); | ||
}); | ||
}); |
2477
43