Comparing version 0.0.3 to 0.1.0
@@ -123,2 +123,3 @@ /*jslint node: true */ | ||
var seed = randomInteger(); | ||
var seed2 = randomInteger(); | ||
console.log('Using seed ' + seed); | ||
@@ -132,15 +133,55 @@ | ||
(new Benchmark.Suite()).add('murmurhash3', function() { | ||
(new Benchmark.Suite()) | ||
.add('murmurhash3', function() { | ||
murmurhash3.murmur32Sync(input); | ||
}).add('murmurhash3+seed', function() { | ||
}) | ||
.add('murmurhash3+seed', function() { | ||
murmurhash3.murmur32Sync(input, seed); | ||
}).add('farmhash-hash', function() { | ||
}) | ||
.add('farmhash-hash32-string', function() { | ||
farmhash.hash32(input); | ||
}).add('farmhash-hash+seed', function() { | ||
}) | ||
.add('farmhash-hash32-buffer', function() { | ||
farmhash.hash32(inputBuffer); | ||
}) | ||
.add('farmhash-hash32+seed-string', function() { | ||
farmhash.hash32WithSeed(input, seed); | ||
}).add('farmhash-fingerprint', function() { | ||
}) | ||
.add('farmhash-hash32+seed-buffer', function() { | ||
farmhash.hash32WithSeed(inputBuffer, seed); | ||
}) | ||
.add('farmhash-fingerprint32-string', function() { | ||
farmhash.fingerprint32(input); | ||
}).add('xxhash+seed', function() { | ||
}) | ||
.add('farmhash-fingerprint32-buffer', function() { | ||
farmhash.fingerprint32(inputBuffer); | ||
}) | ||
.add('farmhash-fingerprint64-string', function() { | ||
farmhash.fingerprint64(input); | ||
}) | ||
.add('farmhash-fingerprint64-buffer', function() { | ||
farmhash.fingerprint64(inputBuffer); | ||
}) | ||
.add('farmhash-hash64-string', function() { | ||
farmhash.hash64(input); | ||
}) | ||
.add('farmhash-hash64-buffer', function() { | ||
farmhash.hash64(inputBuffer); | ||
}) | ||
.add('farmhash-hash64+seed-string', function() { | ||
farmhash.hash64WithSeed(input, seed); | ||
}) | ||
.add('farmhash-hash64+seed-buffer', function() { | ||
farmhash.hash64WithSeed(inputBuffer, seed); | ||
}) | ||
.add('farmhash-hash64+seeds-string', function() { | ||
farmhash.hash64WithSeeds(input, seed, seed2); | ||
}) | ||
.add('farmhash-hash64+seeds-buffer', function() { | ||
farmhash.hash64WithSeeds(inputBuffer, seed, seed2); | ||
}) | ||
.add('xxhash+seed', function() { | ||
xxhash.hash(inputBuffer, seed); | ||
}).on('cycle', function(event) { | ||
}) | ||
.on('cycle', function(event) { | ||
console.log(String(event.target)); | ||
@@ -147,0 +188,0 @@ }).run(); |
69
index.js
@@ -7,8 +7,2 @@ /*jslint node: true */ | ||
// Input validation | ||
var verifyString = function(input) { | ||
if (typeof input !== 'string') { | ||
throw new Error('Expected a string for input'); | ||
} | ||
}; | ||
var verifyInteger = function(input) { | ||
@@ -24,24 +18,49 @@ if (typeof input !== 'number' || (input % 1) !== 0) { | ||
hash32: function(input) { | ||
verifyString(input); | ||
return farmhash.Hash32(input); | ||
if (typeof input === 'string') { | ||
return farmhash.Hash32String(input); | ||
} | ||
if (Buffer.isBuffer(input)) { | ||
return farmhash.Hash32Buffer(input); | ||
} | ||
throw new Error('Expected a String or Buffer for input'); | ||
}, | ||
hash32WithSeed: function(input, seed) { | ||
verifyString(input); | ||
verifyInteger(seed); | ||
return farmhash.Hash32WithSeed(input, seed); | ||
if (typeof input === 'string') { | ||
return farmhash.Hash32WithSeedString(input, seed); | ||
} | ||
if (Buffer.isBuffer(input)) { | ||
return farmhash.Hash32WithSeedBuffer(input, seed); | ||
} | ||
throw new Error('Expected a String or Buffer for input'); | ||
}, | ||
hash64: function(input) { | ||
verifyString(input); | ||
return farmhash.Hash64(input); | ||
if (typeof input === 'string') { | ||
return farmhash.Hash64String(input); | ||
} | ||
if (Buffer.isBuffer(input)) { | ||
return farmhash.Hash64Buffer(input); | ||
} | ||
throw new Error('Expected a String or Buffer for input'); | ||
}, | ||
hash64WithSeed: function(input, seed) { | ||
verifyString(input); | ||
verifyInteger(seed); | ||
return farmhash.Hash64WithSeed(input, seed); | ||
if (typeof input === 'string') { | ||
return farmhash.Hash64WithSeedString(input, seed); | ||
} | ||
if (Buffer.isBuffer(input)) { | ||
return farmhash.Hash64WithSeedBuffer(input, seed); | ||
} | ||
throw new Error('Expected a String or Buffer for input'); | ||
}, | ||
hash64WithSeeds: function(input, seed1, seed2) { | ||
verifyString(input); | ||
verifyInteger(seed1); | ||
verifyInteger(seed2); | ||
return farmhash.Hash64WithSeeds(input, seed1, seed2); | ||
if (typeof input === 'string') { | ||
return farmhash.Hash64WithSeedsString(input, seed1, seed2); | ||
} | ||
if (Buffer.isBuffer(input)) { | ||
return farmhash.Hash64WithSeedsBuffer(input, seed1, seed2); | ||
} | ||
throw new Error('Expected a String or Buffer for input'); | ||
}, | ||
@@ -51,10 +70,18 @@ | ||
fingerprint32: function(input) { | ||
verifyString(input); | ||
return farmhash.Fingerprint32(input); | ||
if (typeof input === 'string') { | ||
return farmhash.Fingerprint32String(input); | ||
} | ||
if (Buffer.isBuffer(input)) { | ||
return farmhash.Fingerprint32Buffer(input); | ||
} | ||
throw new Error('Expected a String or Buffer for input'); | ||
}, | ||
fingerprint64: function(input) { | ||
verifyString(input); | ||
return farmhash.Fingerprint64(input); | ||
if (typeof input === 'string') { | ||
return farmhash.Fingerprint64String(input); | ||
} | ||
if (Buffer.isBuffer(input)) { | ||
return farmhash.Fingerprint64Buffer(input); | ||
} | ||
} | ||
}; |
{ | ||
"name": "farmhash", | ||
"version": "0.0.3", | ||
"version": "0.1.0", | ||
"author": "Lovell Fuller <npm@lovell.info>", | ||
"contributors": [ | ||
"Matt Ranney <mjr@ranney.com>" | ||
], | ||
"description": "Node.js implementation of FarmHash, Google's family of high performance hash functions for strings", | ||
@@ -6,0 +9,0 @@ "scripts": { |
@@ -29,3 +29,3 @@ # farmhash | ||
```javascript | ||
var hash = farmhash.hash64('test'); | ||
var hash = farmhash.hash64(new Buffer('test')); | ||
console.log(typeof hash); // 'string' | ||
@@ -40,3 +40,3 @@ ``` | ||
```javascript | ||
var hash = farmhash.fingerprint32('test'); | ||
var hash = farmhash.fingerprint32(new Buffer('test')); | ||
console.log(typeof hash); // 'number' | ||
@@ -58,3 +58,3 @@ ``` | ||
* `input` is the String to hash. | ||
* `input` is the Buffer or String to hash. | ||
@@ -65,3 +65,3 @@ Returns a Number containing the 32-bit unsigned integer hash value of `input`. | ||
* `input` is the String to hash. | ||
* `input` is the Buffer or String to hash. | ||
* `seed` is an integer Number to use as a seed. | ||
@@ -73,3 +73,3 @@ | ||
* `input` is the String to hash. | ||
* `input` is the Buffer or String to hash. | ||
@@ -80,3 +80,3 @@ Returns a String representing the 64-bit unsigned integer hash value of `input`. | ||
* `input` is the String to hash. | ||
* `input` is the Buffer or String to hash. | ||
* `seed` is an integer Number to use as a seed. | ||
@@ -88,3 +88,3 @@ | ||
* `input` is the String to hash. | ||
* `input` is the Buffer or String to hash. | ||
* `seed1` and `seed2` are integer Numbers to use as seeds. | ||
@@ -100,3 +100,3 @@ | ||
* `input` is the String to fingerprint. | ||
* `input` is the Buffer or String to fingerprint. | ||
@@ -107,3 +107,3 @@ Returns a Number containing the 32-bit unsigned integer fingerprint value of `input`. | ||
* `input` is the String to fingerprint. | ||
* `input` is the Buffer or String to fingerprint. | ||
@@ -122,3 +122,3 @@ Returns a String representing the 64-bit unsigned integer fingerprint value of `input`. | ||
Copyright 2014 Lovell Fuller | ||
Copyright 2014 Lovell Fuller and contributors. | ||
@@ -125,0 +125,0 @@ Licensed under the Apache License, Version 2.0 (the "License"); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
223244
374