initial commit
This commit is contained in:
35
node_modules/xxhashjs/History.md
generated
vendored
Normal file
35
node_modules/xxhashjs/History.md
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
0.1.0 / 2015-03-12
|
||||
==================
|
||||
|
||||
* Fix for issue #5: convert all strings to utf-8
|
||||
|
||||
0.0.5 / 2014-05-19
|
||||
==================
|
||||
|
||||
* Added ArrayBuffer support
|
||||
|
||||
0.0.4 / 2014-04-25
|
||||
==================
|
||||
|
||||
* Fixed undefined Buffer in browsers
|
||||
|
||||
0.0.3 / 2014-03-21
|
||||
==================
|
||||
|
||||
* fixed update() on values < 16
|
||||
|
||||
0.0.2 / 2014-01-19
|
||||
==================
|
||||
|
||||
* added tests
|
||||
* updated README
|
||||
|
||||
0.0.1 / 2014-01-01
|
||||
==================
|
||||
|
||||
* Improved performance on large inputs (112Mb sample file in 4s instead of 4.6s)
|
||||
|
||||
0.0.0 / 2013-12-31
|
||||
==================
|
||||
|
||||
* Initial release
|
||||
17
node_modules/xxhashjs/LICENSE
generated
vendored
Normal file
17
node_modules/xxhashjs/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
90
node_modules/xxhashjs/README.md
generated
vendored
Normal file
90
node_modules/xxhashjs/README.md
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
# Javascript implementation of xxHash
|
||||
|
||||
## Synopsis
|
||||
|
||||
xxHash is a very fast hashing algorithm (see the details [here](https://code.google.com/p/xxhash/)). xxhashjs is a Javascript implementation of it, written in 100% Javascript. Although not as fast as the C version, it does perform pretty well given the current Javascript limitations in handling unsigned 32 bits integers.
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
In nodejs:
|
||||
|
||||
npm install xxhashjs
|
||||
|
||||
In the browser, include the following, and access the constructor with _XXH_:
|
||||
|
||||
```javascript
|
||||
<script src="/your/path/to/xxhash.js"></script>
|
||||
```
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
* In one step:
|
||||
```javascript
|
||||
var h = XXH.h32( 'abcd', 0xABCD ).toString(16) // seed = 0xABCD
|
||||
```
|
||||
> 0xCDA8FAE4
|
||||
|
||||
* In several steps (useful in conjunction of NodeJS streams):
|
||||
```javascript
|
||||
var H = XXH.h32( 0xABCD ) // seed = 0xABCD
|
||||
var h = H.update( 'abcd' ).digest().toString(16)
|
||||
```
|
||||
> 0xCDA8FAE4
|
||||
|
||||
* More examples in the examples directory:
|
||||
* Compute xxHash from a file data
|
||||
* Use xxHashjs in the browser
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
* XXH makes 2 functions available for 32 bits XXH and 64 bits XXH respectively, with the same signature:
|
||||
|
||||
* XXH.h32
|
||||
* XXH.h64
|
||||
|
||||
* In one step:
|
||||
`XXH.h32(<data>, <seed>)`
|
||||
The data can either be a string, an ArrayBuffer or a NodeJS Buffer object.
|
||||
The seed can either be a number or a UINT32 object.
|
||||
|
||||
* In several steps:
|
||||
* instantiate a new XXH object H:
|
||||
`XXH.h32(<seed>)` or `XXH.h32()`
|
||||
The seed can be set later on with the `init` method
|
||||
|
||||
* add data to the hash calculation:
|
||||
`H.update(<data>)`
|
||||
|
||||
* finish the calculations:
|
||||
`H.digest()`
|
||||
|
||||
The object returned can be converted to a string with `toString(<radix>)` or a number `toNumber()`.
|
||||
Once `digest()` has been called, the object can be reused. The same seed will be used or it can be changed with `init(<seed>)`.
|
||||
|
||||
|
||||
## Methods
|
||||
|
||||
* `XXH.h32()`
|
||||
* `.init(<seed>)`
|
||||
Initialize the XXH object with the given seed. The seed can either be a number or a UINT32 object.
|
||||
* `.update(<data>)`
|
||||
Add data for hashing. The data can either be a string, an ArrayBuffer or a NodeJS Buffer object.
|
||||
|
||||
* `digest()` (_UINT32_)
|
||||
Finalize the hash calculations and returns an UINT32 object. The hash value can be retrieved with toString(<radix>).
|
||||
|
||||
* `XXH.h64()`
|
||||
* `.init(<seed>)`
|
||||
Initialize the XXH object with the given seed. The seed can either be a number or a UINT64 object.
|
||||
* `.update(<data>)`
|
||||
Add data for hashing. The data can either be a string, an ArrayBuffer or a NodeJS Buffer object.
|
||||
* `.digest()` (_UINT64_)
|
||||
Finalize the hash calculations and returns an UINT64 object. The hash value can be retrieved with toString(<radix>).
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
27
node_modules/xxhashjs/bower.json
generated
vendored
Normal file
27
node_modules/xxhashjs/bower.json
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "xxhash",
|
||||
"version": "0.2.1",
|
||||
"homepage": "https://github.com/pierrec/js-xxhash",
|
||||
"authors": [
|
||||
"Pierre Curto <pierre.curto@gmail.com>"
|
||||
],
|
||||
"description": "xxHash - fast 32 and 64 bits hashing algorithm",
|
||||
"main": "build/xxhash.js",
|
||||
"moduleType": [
|
||||
"amd"
|
||||
, "globals"
|
||||
, "node"
|
||||
],
|
||||
"keywords": [
|
||||
"hash"
|
||||
, "xxhash"
|
||||
],
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*"
|
||||
, "node_modules"
|
||||
, "bower_components"
|
||||
, "test"
|
||||
, "tests"
|
||||
]
|
||||
}
|
||||
4101
node_modules/xxhashjs/build/xxhash.js
generated
vendored
Normal file
4101
node_modules/xxhashjs/build/xxhash.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2
node_modules/xxhashjs/build/xxhash.min.js
generated
vendored
Normal file
2
node_modules/xxhashjs/build/xxhash.min.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
9
node_modules/xxhashjs/examples/from_file.js
generated
vendored
Normal file
9
node_modules/xxhashjs/examples/from_file.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
var XXH = require('..')
|
||||
var buf = require('fs').readFileSync( process.argv[2] )
|
||||
|
||||
// var buf = buf.toString()
|
||||
console.log('data loaded:', buf.length, 'bytes')
|
||||
var startTime = Date.now()
|
||||
var h = XXH.h32(0).update(buf).digest()
|
||||
var delta = Date.now() - startTime
|
||||
console.log( '0x' + h.toString(16).toUpperCase(), 'in', delta, 'ms' )
|
||||
9
node_modules/xxhashjs/examples/from_file64.js
generated
vendored
Normal file
9
node_modules/xxhashjs/examples/from_file64.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
var XXH = require('..')
|
||||
var buf = require('fs').readFileSync( process.argv[2] )
|
||||
|
||||
// var buf = buf.toString()
|
||||
console.log('data loaded:', buf.length, 'bytes')
|
||||
var startTime = Date.now()
|
||||
var h = XXH.h64(0).update(buf).digest()
|
||||
var delta = Date.now() - startTime
|
||||
console.log( '0x' + h.toString(16).toUpperCase(), 'in', delta, 'ms' )
|
||||
5
node_modules/xxhashjs/examples/one_step.js
generated
vendored
Normal file
5
node_modules/xxhashjs/examples/one_step.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
var XXH = require('..')
|
||||
|
||||
var h = XXH.h32( 'abcd', 0xABCD ).toString(16)
|
||||
|
||||
console.log( '0x' + h.toUpperCase() )
|
||||
23
node_modules/xxhashjs/examples/xxhash.html
generated
vendored
Normal file
23
node_modules/xxhashjs/examples/xxhash.html
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
<html>
|
||||
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
|
||||
<body>
|
||||
<div>
|
||||
Result:
|
||||
<div id='input'></div>
|
||||
<div id='seed'></div>
|
||||
<div id='xxhash'></div>
|
||||
<div id='xxhash64'></div>
|
||||
</div>
|
||||
<script type="text/javascript" src="../build/xxhash.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
var input='heiå'
|
||||
var seed = '0'
|
||||
var h = XXH.h32( input, seed ).toString(16)
|
||||
var h64 = XXH.h64( input, seed ).toString(16)
|
||||
document.getElementById('input').innerHTML = "input ='" + input + "'"
|
||||
document.getElementById('seed').innerHTML = "seed='" + seed + "'"
|
||||
document.getElementById('xxhash').innerHTML = "xxHash='" + h + "'"
|
||||
document.getElementById('xxhash64').innerHTML = "xxHash64='" + h64 + "'"
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
4
node_modules/xxhashjs/lib/index.js
generated
vendored
Normal file
4
node_modules/xxhashjs/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
h32: require("./xxhash")
|
||||
, h64: require("./xxhash64")
|
||||
}
|
||||
389
node_modules/xxhashjs/lib/xxhash.js
generated
vendored
Normal file
389
node_modules/xxhashjs/lib/xxhash.js
generated
vendored
Normal file
@@ -0,0 +1,389 @@
|
||||
/**
|
||||
xxHash implementation in pure Javascript
|
||||
|
||||
Copyright (C) 2013, Pierre Curto
|
||||
MIT license
|
||||
*/
|
||||
var UINT32 = require('cuint').UINT32
|
||||
|
||||
/*
|
||||
Merged this sequence of method calls as it speeds up
|
||||
the calculations by a factor of 2
|
||||
*/
|
||||
// this.v1.add( other.multiply(PRIME32_2) ).rotl(13).multiply(PRIME32_1);
|
||||
UINT32.prototype.xxh_update = function (low, high) {
|
||||
var b00 = PRIME32_2._low
|
||||
var b16 = PRIME32_2._high
|
||||
|
||||
var c16, c00
|
||||
c00 = low * b00
|
||||
c16 = c00 >>> 16
|
||||
|
||||
c16 += high * b00
|
||||
c16 &= 0xFFFF // Not required but improves performance
|
||||
c16 += low * b16
|
||||
|
||||
var a00 = this._low + (c00 & 0xFFFF)
|
||||
var a16 = a00 >>> 16
|
||||
|
||||
a16 += this._high + (c16 & 0xFFFF)
|
||||
|
||||
var v = (a16 << 16) | (a00 & 0xFFFF)
|
||||
v = (v << 13) | (v >>> 19)
|
||||
|
||||
a00 = v & 0xFFFF
|
||||
a16 = v >>> 16
|
||||
|
||||
b00 = PRIME32_1._low
|
||||
b16 = PRIME32_1._high
|
||||
|
||||
c00 = a00 * b00
|
||||
c16 = c00 >>> 16
|
||||
|
||||
c16 += a16 * b00
|
||||
c16 &= 0xFFFF // Not required but improves performance
|
||||
c16 += a00 * b16
|
||||
|
||||
this._low = c00 & 0xFFFF
|
||||
this._high = c16 & 0xFFFF
|
||||
}
|
||||
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
var PRIME32_1 = UINT32( '2654435761' )
|
||||
var PRIME32_2 = UINT32( '2246822519' )
|
||||
var PRIME32_3 = UINT32( '3266489917' )
|
||||
var PRIME32_4 = UINT32( '668265263' )
|
||||
var PRIME32_5 = UINT32( '374761393' )
|
||||
|
||||
/**
|
||||
* Convert string to proper UTF-8 array
|
||||
* @param str Input string
|
||||
* @returns {Uint8Array} UTF8 array is returned as uint8 array
|
||||
*/
|
||||
function toUTF8Array (str) {
|
||||
var utf8 = []
|
||||
for (var i=0, n=str.length; i < n; i++) {
|
||||
var charcode = str.charCodeAt(i)
|
||||
if (charcode < 0x80) utf8.push(charcode)
|
||||
else if (charcode < 0x800) {
|
||||
utf8.push(0xc0 | (charcode >> 6),
|
||||
0x80 | (charcode & 0x3f))
|
||||
}
|
||||
else if (charcode < 0xd800 || charcode >= 0xe000) {
|
||||
utf8.push(0xe0 | (charcode >> 12),
|
||||
0x80 | ((charcode>>6) & 0x3f),
|
||||
0x80 | (charcode & 0x3f))
|
||||
}
|
||||
// surrogate pair
|
||||
else {
|
||||
i++;
|
||||
// UTF-16 encodes 0x10000-0x10FFFF by
|
||||
// subtracting 0x10000 and splitting the
|
||||
// 20 bits of 0x0-0xFFFFF into two halves
|
||||
charcode = 0x10000 + (((charcode & 0x3ff)<<10)
|
||||
| (str.charCodeAt(i) & 0x3ff))
|
||||
utf8.push(0xf0 | (charcode >>18),
|
||||
0x80 | ((charcode>>12) & 0x3f),
|
||||
0x80 | ((charcode>>6) & 0x3f),
|
||||
0x80 | (charcode & 0x3f))
|
||||
}
|
||||
}
|
||||
|
||||
return new Uint8Array(utf8)
|
||||
}
|
||||
|
||||
/**
|
||||
* XXH object used as a constructor or a function
|
||||
* @constructor
|
||||
* or
|
||||
* @param {Object|String} input data
|
||||
* @param {Number|UINT32} seed
|
||||
* @return ThisExpression
|
||||
* or
|
||||
* @return {UINT32} xxHash
|
||||
*/
|
||||
function XXH () {
|
||||
if (arguments.length == 2)
|
||||
return new XXH( arguments[1] ).update( arguments[0] ).digest()
|
||||
|
||||
if (!(this instanceof XXH))
|
||||
return new XXH( arguments[0] )
|
||||
|
||||
init.call(this, arguments[0])
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the XXH instance with the given seed
|
||||
* @method init
|
||||
* @param {Number|Object} seed as a number or an unsigned 32 bits integer
|
||||
* @return ThisExpression
|
||||
*/
|
||||
function init (seed) {
|
||||
this.seed = seed instanceof UINT32 ? seed.clone() : UINT32(seed)
|
||||
this.v1 = this.seed.clone().add(PRIME32_1).add(PRIME32_2)
|
||||
this.v2 = this.seed.clone().add(PRIME32_2)
|
||||
this.v3 = this.seed.clone()
|
||||
this.v4 = this.seed.clone().subtract(PRIME32_1)
|
||||
this.total_len = 0
|
||||
this.memsize = 0
|
||||
this.memory = null
|
||||
|
||||
return this
|
||||
}
|
||||
XXH.prototype.init = init
|
||||
|
||||
/**
|
||||
* Add data to be computed for the XXH hash
|
||||
* @method update
|
||||
* @param {String|Buffer|ArrayBuffer} input as a string or nodejs Buffer or ArrayBuffer
|
||||
* @return ThisExpression
|
||||
*/
|
||||
XXH.prototype.update = function (input) {
|
||||
var isString = typeof input == 'string'
|
||||
var isArrayBuffer
|
||||
|
||||
// Convert all strings to utf-8 first (issue #5)
|
||||
if (isString) {
|
||||
input = toUTF8Array(input)
|
||||
isString = false
|
||||
isArrayBuffer = true
|
||||
}
|
||||
|
||||
if (typeof ArrayBuffer !== "undefined" && input instanceof ArrayBuffer)
|
||||
{
|
||||
isArrayBuffer = true
|
||||
input = new Uint8Array(input);
|
||||
}
|
||||
|
||||
var p = 0
|
||||
var len = input.length
|
||||
var bEnd = p + len
|
||||
|
||||
if (len == 0) return this
|
||||
|
||||
this.total_len += len
|
||||
|
||||
if (this.memsize == 0)
|
||||
{
|
||||
if (isString) {
|
||||
this.memory = ''
|
||||
} else if (isArrayBuffer) {
|
||||
this.memory = new Uint8Array(16)
|
||||
} else {
|
||||
this.memory = new Buffer(16)
|
||||
}
|
||||
}
|
||||
|
||||
if (this.memsize + len < 16) // fill in tmp buffer
|
||||
{
|
||||
// XXH_memcpy(this.memory + this.memsize, input, len)
|
||||
if (isString) {
|
||||
this.memory += input
|
||||
} else if (isArrayBuffer) {
|
||||
this.memory.set( input.subarray(0, len), this.memsize )
|
||||
} else {
|
||||
input.copy( this.memory, this.memsize, 0, len )
|
||||
}
|
||||
|
||||
this.memsize += len
|
||||
return this
|
||||
}
|
||||
|
||||
if (this.memsize > 0) // some data left from previous update
|
||||
{
|
||||
// XXH_memcpy(this.memory + this.memsize, input, 16-this.memsize);
|
||||
if (isString) {
|
||||
this.memory += input.slice(0, 16 - this.memsize)
|
||||
} else if (isArrayBuffer) {
|
||||
this.memory.set( input.subarray(0, 16 - this.memsize), this.memsize )
|
||||
} else {
|
||||
input.copy( this.memory, this.memsize, 0, 16 - this.memsize )
|
||||
}
|
||||
|
||||
var p32 = 0
|
||||
if (isString) {
|
||||
this.v1.xxh_update(
|
||||
(this.memory.charCodeAt(p32+1) << 8) | this.memory.charCodeAt(p32)
|
||||
, (this.memory.charCodeAt(p32+3) << 8) | this.memory.charCodeAt(p32+2)
|
||||
)
|
||||
p32 += 4
|
||||
this.v2.xxh_update(
|
||||
(this.memory.charCodeAt(p32+1) << 8) | this.memory.charCodeAt(p32)
|
||||
, (this.memory.charCodeAt(p32+3) << 8) | this.memory.charCodeAt(p32+2)
|
||||
)
|
||||
p32 += 4
|
||||
this.v3.xxh_update(
|
||||
(this.memory.charCodeAt(p32+1) << 8) | this.memory.charCodeAt(p32)
|
||||
, (this.memory.charCodeAt(p32+3) << 8) | this.memory.charCodeAt(p32+2)
|
||||
)
|
||||
p32 += 4
|
||||
this.v4.xxh_update(
|
||||
(this.memory.charCodeAt(p32+1) << 8) | this.memory.charCodeAt(p32)
|
||||
, (this.memory.charCodeAt(p32+3) << 8) | this.memory.charCodeAt(p32+2)
|
||||
)
|
||||
} else {
|
||||
this.v1.xxh_update(
|
||||
(this.memory[p32+1] << 8) | this.memory[p32]
|
||||
, (this.memory[p32+3] << 8) | this.memory[p32+2]
|
||||
)
|
||||
p32 += 4
|
||||
this.v2.xxh_update(
|
||||
(this.memory[p32+1] << 8) | this.memory[p32]
|
||||
, (this.memory[p32+3] << 8) | this.memory[p32+2]
|
||||
)
|
||||
p32 += 4
|
||||
this.v3.xxh_update(
|
||||
(this.memory[p32+1] << 8) | this.memory[p32]
|
||||
, (this.memory[p32+3] << 8) | this.memory[p32+2]
|
||||
)
|
||||
p32 += 4
|
||||
this.v4.xxh_update(
|
||||
(this.memory[p32+1] << 8) | this.memory[p32]
|
||||
, (this.memory[p32+3] << 8) | this.memory[p32+2]
|
||||
)
|
||||
}
|
||||
|
||||
p += 16 - this.memsize
|
||||
this.memsize = 0
|
||||
if (isString) this.memory = ''
|
||||
}
|
||||
|
||||
if (p <= bEnd - 16)
|
||||
{
|
||||
var limit = bEnd - 16
|
||||
|
||||
do
|
||||
{
|
||||
if (isString) {
|
||||
this.v1.xxh_update(
|
||||
(input.charCodeAt(p+1) << 8) | input.charCodeAt(p)
|
||||
, (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2)
|
||||
)
|
||||
p += 4
|
||||
this.v2.xxh_update(
|
||||
(input.charCodeAt(p+1) << 8) | input.charCodeAt(p)
|
||||
, (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2)
|
||||
)
|
||||
p += 4
|
||||
this.v3.xxh_update(
|
||||
(input.charCodeAt(p+1) << 8) | input.charCodeAt(p)
|
||||
, (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2)
|
||||
)
|
||||
p += 4
|
||||
this.v4.xxh_update(
|
||||
(input.charCodeAt(p+1) << 8) | input.charCodeAt(p)
|
||||
, (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2)
|
||||
)
|
||||
} else {
|
||||
this.v1.xxh_update(
|
||||
(input[p+1] << 8) | input[p]
|
||||
, (input[p+3] << 8) | input[p+2]
|
||||
)
|
||||
p += 4
|
||||
this.v2.xxh_update(
|
||||
(input[p+1] << 8) | input[p]
|
||||
, (input[p+3] << 8) | input[p+2]
|
||||
)
|
||||
p += 4
|
||||
this.v3.xxh_update(
|
||||
(input[p+1] << 8) | input[p]
|
||||
, (input[p+3] << 8) | input[p+2]
|
||||
)
|
||||
p += 4
|
||||
this.v4.xxh_update(
|
||||
(input[p+1] << 8) | input[p]
|
||||
, (input[p+3] << 8) | input[p+2]
|
||||
)
|
||||
}
|
||||
p += 4
|
||||
} while (p <= limit)
|
||||
}
|
||||
|
||||
if (p < bEnd)
|
||||
{
|
||||
// XXH_memcpy(this.memory, p, bEnd-p);
|
||||
if (isString) {
|
||||
this.memory += input.slice(p)
|
||||
} else if (isArrayBuffer) {
|
||||
this.memory.set( input.subarray(p, bEnd), this.memsize )
|
||||
} else {
|
||||
input.copy( this.memory, this.memsize, p, bEnd )
|
||||
}
|
||||
|
||||
this.memsize = bEnd - p
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalize the XXH computation. The XXH instance is ready for reuse for the given seed
|
||||
* @method digest
|
||||
* @return {UINT32} xxHash
|
||||
*/
|
||||
XXH.prototype.digest = function () {
|
||||
var input = this.memory
|
||||
var isString = typeof input == 'string'
|
||||
var p = 0
|
||||
var bEnd = this.memsize
|
||||
var h32, h
|
||||
var u = new UINT32
|
||||
|
||||
if (this.total_len >= 16)
|
||||
{
|
||||
h32 = this.v1.rotl(1).add( this.v2.rotl(7).add( this.v3.rotl(12).add( this.v4.rotl(18) ) ) )
|
||||
}
|
||||
else
|
||||
{
|
||||
h32 = this.seed.clone().add( PRIME32_5 )
|
||||
}
|
||||
|
||||
h32.add( u.fromNumber(this.total_len) )
|
||||
|
||||
while (p <= bEnd - 4)
|
||||
{
|
||||
if (isString) {
|
||||
u.fromBits(
|
||||
(input.charCodeAt(p+1) << 8) | input.charCodeAt(p)
|
||||
, (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2)
|
||||
)
|
||||
} else {
|
||||
u.fromBits(
|
||||
(input[p+1] << 8) | input[p]
|
||||
, (input[p+3] << 8) | input[p+2]
|
||||
)
|
||||
}
|
||||
h32
|
||||
.add( u.multiply(PRIME32_3) )
|
||||
.rotl(17)
|
||||
.multiply( PRIME32_4 )
|
||||
p += 4
|
||||
}
|
||||
|
||||
while (p < bEnd)
|
||||
{
|
||||
u.fromBits( isString ? input.charCodeAt(p++) : input[p++], 0 )
|
||||
h32
|
||||
.add( u.multiply(PRIME32_5) )
|
||||
.rotl(11)
|
||||
.multiply(PRIME32_1)
|
||||
}
|
||||
|
||||
h = h32.clone().shiftRight(15)
|
||||
h32.xor(h).multiply(PRIME32_2)
|
||||
|
||||
h = h32.clone().shiftRight(13)
|
||||
h32.xor(h).multiply(PRIME32_3)
|
||||
|
||||
h = h32.clone().shiftRight(16)
|
||||
h32.xor(h)
|
||||
|
||||
// Reset the state
|
||||
this.init( this.seed )
|
||||
|
||||
return h32
|
||||
}
|
||||
|
||||
module.exports = XXH
|
||||
444
node_modules/xxhashjs/lib/xxhash64.js
generated
vendored
Normal file
444
node_modules/xxhashjs/lib/xxhash64.js
generated
vendored
Normal file
@@ -0,0 +1,444 @@
|
||||
/**
|
||||
xxHash64 implementation in pure Javascript
|
||||
|
||||
Copyright (C) 2016, Pierre Curto
|
||||
MIT license
|
||||
*/
|
||||
var UINT64 = require('cuint').UINT64
|
||||
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
var PRIME64_1 = UINT64( '11400714785074694791' )
|
||||
var PRIME64_2 = UINT64( '14029467366897019727' )
|
||||
var PRIME64_3 = UINT64( '1609587929392839161' )
|
||||
var PRIME64_4 = UINT64( '9650029242287828579' )
|
||||
var PRIME64_5 = UINT64( '2870177450012600261' )
|
||||
|
||||
/**
|
||||
* Convert string to proper UTF-8 array
|
||||
* @param str Input string
|
||||
* @returns {Uint8Array} UTF8 array is returned as uint8 array
|
||||
*/
|
||||
function toUTF8Array (str) {
|
||||
var utf8 = []
|
||||
for (var i=0, n=str.length; i < n; i++) {
|
||||
var charcode = str.charCodeAt(i)
|
||||
if (charcode < 0x80) utf8.push(charcode)
|
||||
else if (charcode < 0x800) {
|
||||
utf8.push(0xc0 | (charcode >> 6),
|
||||
0x80 | (charcode & 0x3f))
|
||||
}
|
||||
else if (charcode < 0xd800 || charcode >= 0xe000) {
|
||||
utf8.push(0xe0 | (charcode >> 12),
|
||||
0x80 | ((charcode>>6) & 0x3f),
|
||||
0x80 | (charcode & 0x3f))
|
||||
}
|
||||
// surrogate pair
|
||||
else {
|
||||
i++;
|
||||
// UTF-16 encodes 0x10000-0x10FFFF by
|
||||
// subtracting 0x10000 and splitting the
|
||||
// 20 bits of 0x0-0xFFFFF into two halves
|
||||
charcode = 0x10000 + (((charcode & 0x3ff)<<10)
|
||||
| (str.charCodeAt(i) & 0x3ff))
|
||||
utf8.push(0xf0 | (charcode >>18),
|
||||
0x80 | ((charcode>>12) & 0x3f),
|
||||
0x80 | ((charcode>>6) & 0x3f),
|
||||
0x80 | (charcode & 0x3f))
|
||||
}
|
||||
}
|
||||
|
||||
return new Uint8Array(utf8)
|
||||
}
|
||||
|
||||
/**
|
||||
* XXH64 object used as a constructor or a function
|
||||
* @constructor
|
||||
* or
|
||||
* @param {Object|String} input data
|
||||
* @param {Number|UINT64} seed
|
||||
* @return ThisExpression
|
||||
* or
|
||||
* @return {UINT64} xxHash
|
||||
*/
|
||||
function XXH64 () {
|
||||
if (arguments.length == 2)
|
||||
return new XXH64( arguments[1] ).update( arguments[0] ).digest()
|
||||
|
||||
if (!(this instanceof XXH64))
|
||||
return new XXH64( arguments[0] )
|
||||
|
||||
init.call(this, arguments[0])
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the XXH64 instance with the given seed
|
||||
* @method init
|
||||
* @param {Number|Object} seed as a number or an unsigned 32 bits integer
|
||||
* @return ThisExpression
|
||||
*/
|
||||
function init (seed) {
|
||||
this.seed = seed instanceof UINT64 ? seed.clone() : UINT64(seed)
|
||||
this.v1 = this.seed.clone().add(PRIME64_1).add(PRIME64_2)
|
||||
this.v2 = this.seed.clone().add(PRIME64_2)
|
||||
this.v3 = this.seed.clone()
|
||||
this.v4 = this.seed.clone().subtract(PRIME64_1)
|
||||
this.total_len = 0
|
||||
this.memsize = 0
|
||||
this.memory = null
|
||||
|
||||
return this
|
||||
}
|
||||
XXH64.prototype.init = init
|
||||
|
||||
/**
|
||||
* Add data to be computed for the XXH64 hash
|
||||
* @method update
|
||||
* @param {String|Buffer|ArrayBuffer} input as a string or nodejs Buffer or ArrayBuffer
|
||||
* @return ThisExpression
|
||||
*/
|
||||
XXH64.prototype.update = function (input) {
|
||||
var isString = typeof input == 'string'
|
||||
var isArrayBuffer
|
||||
|
||||
// Convert all strings to utf-8 first (issue #5)
|
||||
if (isString) {
|
||||
input = toUTF8Array(input)
|
||||
isString = false
|
||||
isArrayBuffer = true
|
||||
}
|
||||
|
||||
if (typeof ArrayBuffer !== "undefined" && input instanceof ArrayBuffer)
|
||||
{
|
||||
isArrayBuffer = true
|
||||
input = new Uint8Array(input);
|
||||
}
|
||||
|
||||
var p = 0
|
||||
var len = input.length
|
||||
var bEnd = p + len
|
||||
|
||||
if (len == 0) return this
|
||||
|
||||
this.total_len += len
|
||||
|
||||
if (this.memsize == 0)
|
||||
{
|
||||
if (isString) {
|
||||
this.memory = ''
|
||||
} else if (isArrayBuffer) {
|
||||
this.memory = new Uint8Array(32)
|
||||
} else {
|
||||
this.memory = new Buffer(32)
|
||||
}
|
||||
}
|
||||
|
||||
if (this.memsize + len < 32) // fill in tmp buffer
|
||||
{
|
||||
// XXH64_memcpy(this.memory + this.memsize, input, len)
|
||||
if (isString) {
|
||||
this.memory += input
|
||||
} else if (isArrayBuffer) {
|
||||
this.memory.set( input.subarray(0, len), this.memsize )
|
||||
} else {
|
||||
input.copy( this.memory, this.memsize, 0, len )
|
||||
}
|
||||
|
||||
this.memsize += len
|
||||
return this
|
||||
}
|
||||
|
||||
if (this.memsize > 0) // some data left from previous update
|
||||
{
|
||||
// XXH64_memcpy(this.memory + this.memsize, input, 16-this.memsize);
|
||||
if (isString) {
|
||||
this.memory += input.slice(0, 32 - this.memsize)
|
||||
} else if (isArrayBuffer) {
|
||||
this.memory.set( input.subarray(0, 32 - this.memsize), this.memsize )
|
||||
} else {
|
||||
input.copy( this.memory, this.memsize, 0, 32 - this.memsize )
|
||||
}
|
||||
|
||||
var p64 = 0
|
||||
if (isString) {
|
||||
var other
|
||||
other = UINT64(
|
||||
(this.memory.charCodeAt(p64+1) << 8) | this.memory.charCodeAt(p64)
|
||||
, (this.memory.charCodeAt(p64+3) << 8) | this.memory.charCodeAt(p64+2)
|
||||
, (this.memory.charCodeAt(p64+5) << 8) | this.memory.charCodeAt(p64+4)
|
||||
, (this.memory.charCodeAt(p64+7) << 8) | this.memory.charCodeAt(p64+6)
|
||||
)
|
||||
this.v1.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
|
||||
p64 += 8
|
||||
other = UINT64(
|
||||
(this.memory.charCodeAt(p64+1) << 8) | this.memory.charCodeAt(p64)
|
||||
, (this.memory.charCodeAt(p64+3) << 8) | this.memory.charCodeAt(p64+2)
|
||||
, (this.memory.charCodeAt(p64+5) << 8) | this.memory.charCodeAt(p64+4)
|
||||
, (this.memory.charCodeAt(p64+7) << 8) | this.memory.charCodeAt(p64+6)
|
||||
)
|
||||
this.v2.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
|
||||
p64 += 8
|
||||
other = UINT64(
|
||||
(this.memory.charCodeAt(p64+1) << 8) | this.memory.charCodeAt(p64)
|
||||
, (this.memory.charCodeAt(p64+3) << 8) | this.memory.charCodeAt(p64+2)
|
||||
, (this.memory.charCodeAt(p64+5) << 8) | this.memory.charCodeAt(p64+4)
|
||||
, (this.memory.charCodeAt(p64+7) << 8) | this.memory.charCodeAt(p64+6)
|
||||
)
|
||||
this.v3.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
|
||||
p64 += 8
|
||||
other = UINT64(
|
||||
(this.memory.charCodeAt(p64+1) << 8) | this.memory.charCodeAt(p64)
|
||||
, (this.memory.charCodeAt(p64+3) << 8) | this.memory.charCodeAt(p64+2)
|
||||
, (this.memory.charCodeAt(p64+5) << 8) | this.memory.charCodeAt(p64+4)
|
||||
, (this.memory.charCodeAt(p64+7) << 8) | this.memory.charCodeAt(p64+6)
|
||||
)
|
||||
this.v4.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
|
||||
} else {
|
||||
var other
|
||||
other = UINT64(
|
||||
(this.memory[p64+1] << 8) | this.memory[p64]
|
||||
, (this.memory[p64+3] << 8) | this.memory[p64+2]
|
||||
, (this.memory[p64+5] << 8) | this.memory[p64+4]
|
||||
, (this.memory[p64+7] << 8) | this.memory[p64+6]
|
||||
)
|
||||
this.v1.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
|
||||
p64 += 8
|
||||
other = UINT64(
|
||||
(this.memory[p64+1] << 8) | this.memory[p64]
|
||||
, (this.memory[p64+3] << 8) | this.memory[p64+2]
|
||||
, (this.memory[p64+5] << 8) | this.memory[p64+4]
|
||||
, (this.memory[p64+7] << 8) | this.memory[p64+6]
|
||||
)
|
||||
this.v2.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
|
||||
p64 += 8
|
||||
other = UINT64(
|
||||
(this.memory[p64+1] << 8) | this.memory[p64]
|
||||
, (this.memory[p64+3] << 8) | this.memory[p64+2]
|
||||
, (this.memory[p64+5] << 8) | this.memory[p64+4]
|
||||
, (this.memory[p64+7] << 8) | this.memory[p64+6]
|
||||
)
|
||||
this.v3.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
|
||||
p64 += 8
|
||||
other = UINT64(
|
||||
(this.memory[p64+1] << 8) | this.memory[p64]
|
||||
, (this.memory[p64+3] << 8) | this.memory[p64+2]
|
||||
, (this.memory[p64+5] << 8) | this.memory[p64+4]
|
||||
, (this.memory[p64+7] << 8) | this.memory[p64+6]
|
||||
)
|
||||
this.v4.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
|
||||
}
|
||||
|
||||
p += 32 - this.memsize
|
||||
this.memsize = 0
|
||||
if (isString) this.memory = ''
|
||||
}
|
||||
|
||||
if (p <= bEnd - 32)
|
||||
{
|
||||
var limit = bEnd - 32
|
||||
|
||||
do
|
||||
{
|
||||
if (isString) {
|
||||
var other
|
||||
other = UINT64(
|
||||
(input.charCodeAt(p+1) << 8) | input.charCodeAt(p)
|
||||
, (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2)
|
||||
, (input.charCodeAt(p+5) << 8) | input.charCodeAt(p+4)
|
||||
, (input.charCodeAt(p+7) << 8) | input.charCodeAt(p+6)
|
||||
)
|
||||
this.v1.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
|
||||
p += 8
|
||||
other = UINT64(
|
||||
(input.charCodeAt(p+1) << 8) | input.charCodeAt(p)
|
||||
, (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2)
|
||||
, (input.charCodeAt(p+5) << 8) | input.charCodeAt(p+4)
|
||||
, (input.charCodeAt(p+7) << 8) | input.charCodeAt(p+6)
|
||||
)
|
||||
this.v2.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
|
||||
p += 8
|
||||
other = UINT64(
|
||||
(input.charCodeAt(p+1) << 8) | input.charCodeAt(p)
|
||||
, (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2)
|
||||
, (input.charCodeAt(p+5) << 8) | input.charCodeAt(p+4)
|
||||
, (input.charCodeAt(p+7) << 8) | input.charCodeAt(p+6)
|
||||
)
|
||||
this.v3.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
|
||||
p += 8
|
||||
other = UINT64(
|
||||
(input.charCodeAt(p+1) << 8) | input.charCodeAt(p)
|
||||
, (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2)
|
||||
, (input.charCodeAt(p+5) << 8) | input.charCodeAt(p+4)
|
||||
, (input.charCodeAt(p+7) << 8) | input.charCodeAt(p+6)
|
||||
)
|
||||
this.v4.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
|
||||
} else {
|
||||
var other
|
||||
other = UINT64(
|
||||
(input[p+1] << 8) | input[p]
|
||||
, (input[p+3] << 8) | input[p+2]
|
||||
, (input[p+5] << 8) | input[p+4]
|
||||
, (input[p+7] << 8) | input[p+6]
|
||||
)
|
||||
this.v1.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
|
||||
p += 8
|
||||
other = UINT64(
|
||||
(input[p+1] << 8) | input[p]
|
||||
, (input[p+3] << 8) | input[p+2]
|
||||
, (input[p+5] << 8) | input[p+4]
|
||||
, (input[p+7] << 8) | input[p+6]
|
||||
)
|
||||
this.v2.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
|
||||
p += 8
|
||||
other = UINT64(
|
||||
(input[p+1] << 8) | input[p]
|
||||
, (input[p+3] << 8) | input[p+2]
|
||||
, (input[p+5] << 8) | input[p+4]
|
||||
, (input[p+7] << 8) | input[p+6]
|
||||
)
|
||||
this.v3.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
|
||||
p += 8
|
||||
other = UINT64(
|
||||
(input[p+1] << 8) | input[p]
|
||||
, (input[p+3] << 8) | input[p+2]
|
||||
, (input[p+5] << 8) | input[p+4]
|
||||
, (input[p+7] << 8) | input[p+6]
|
||||
)
|
||||
this.v4.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
|
||||
}
|
||||
p += 8
|
||||
} while (p <= limit)
|
||||
}
|
||||
|
||||
if (p < bEnd)
|
||||
{
|
||||
// XXH64_memcpy(this.memory, p, bEnd-p);
|
||||
if (isString) {
|
||||
this.memory += input.slice(p)
|
||||
} else if (isArrayBuffer) {
|
||||
this.memory.set( input.subarray(p, bEnd), this.memsize )
|
||||
} else {
|
||||
input.copy( this.memory, this.memsize, p, bEnd )
|
||||
}
|
||||
|
||||
this.memsize = bEnd - p
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalize the XXH64 computation. The XXH64 instance is ready for reuse for the given seed
|
||||
* @method digest
|
||||
* @return {UINT64} xxHash
|
||||
*/
|
||||
XXH64.prototype.digest = function () {
|
||||
var input = this.memory
|
||||
var isString = typeof input == 'string'
|
||||
var p = 0
|
||||
var bEnd = this.memsize
|
||||
var h64, h
|
||||
var u = new UINT64
|
||||
|
||||
if (this.total_len >= 32)
|
||||
{
|
||||
h64 = this.v1.clone().rotl(1)
|
||||
h64.add( this.v2.clone().rotl(7) )
|
||||
h64.add( this.v3.clone().rotl(12) )
|
||||
h64.add( this.v4.clone().rotl(18) )
|
||||
|
||||
h64.xor( this.v1.multiply(PRIME64_2).rotl(31).multiply(PRIME64_1) )
|
||||
h64.multiply(PRIME64_1).add(PRIME64_4)
|
||||
|
||||
h64.xor( this.v2.multiply(PRIME64_2).rotl(31).multiply(PRIME64_1) )
|
||||
h64.multiply(PRIME64_1).add(PRIME64_4)
|
||||
|
||||
h64.xor( this.v3.multiply(PRIME64_2).rotl(31).multiply(PRIME64_1) )
|
||||
h64.multiply(PRIME64_1).add(PRIME64_4)
|
||||
|
||||
h64.xor( this.v4.multiply(PRIME64_2).rotl(31).multiply(PRIME64_1) )
|
||||
h64.multiply(PRIME64_1).add(PRIME64_4)
|
||||
}
|
||||
else
|
||||
{
|
||||
h64 = this.seed.clone().add( PRIME64_5 )
|
||||
}
|
||||
|
||||
h64.add( u.fromNumber(this.total_len) )
|
||||
|
||||
while (p <= bEnd - 8)
|
||||
{
|
||||
if (isString) {
|
||||
u.fromBits(
|
||||
(input.charCodeAt(p+1) << 8) | input.charCodeAt(p)
|
||||
, (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2)
|
||||
, (input.charCodeAt(p+5) << 8) | input.charCodeAt(p+4)
|
||||
, (input.charCodeAt(p+7) << 8) | input.charCodeAt(p+6)
|
||||
)
|
||||
} else {
|
||||
u.fromBits(
|
||||
(input[p+1] << 8) | input[p]
|
||||
, (input[p+3] << 8) | input[p+2]
|
||||
, (input[p+5] << 8) | input[p+4]
|
||||
, (input[p+7] << 8) | input[p+6]
|
||||
)
|
||||
}
|
||||
u.multiply(PRIME64_2).rotl(31).multiply(PRIME64_1)
|
||||
h64
|
||||
.xor(u)
|
||||
.rotl(27)
|
||||
.multiply( PRIME64_1 )
|
||||
.add( PRIME64_4 )
|
||||
p += 8
|
||||
}
|
||||
|
||||
if (p + 4 <= bEnd) {
|
||||
if (isString) {
|
||||
u.fromBits(
|
||||
(input.charCodeAt(p+1) << 8) | input.charCodeAt(p)
|
||||
, (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2)
|
||||
, 0
|
||||
, 0
|
||||
)
|
||||
} else {
|
||||
u.fromBits(
|
||||
(input[p+1] << 8) | input[p]
|
||||
, (input[p+3] << 8) | input[p+2]
|
||||
, 0
|
||||
, 0
|
||||
)
|
||||
}
|
||||
h64
|
||||
.xor( u.multiply(PRIME64_1) )
|
||||
.rotl(23)
|
||||
.multiply( PRIME64_2 )
|
||||
.add( PRIME64_3 )
|
||||
p += 4
|
||||
}
|
||||
|
||||
while (p < bEnd)
|
||||
{
|
||||
u.fromBits( isString ? input.charCodeAt(p++) : input[p++], 0, 0, 0 )
|
||||
h64
|
||||
.xor( u.multiply(PRIME64_5) )
|
||||
.rotl(11)
|
||||
.multiply(PRIME64_1)
|
||||
}
|
||||
|
||||
h = h64.clone().shiftRight(33)
|
||||
h64.xor(h).multiply(PRIME64_2)
|
||||
|
||||
h = h64.clone().shiftRight(29)
|
||||
h64.xor(h).multiply(PRIME64_3)
|
||||
|
||||
h = h64.clone().shiftRight(32)
|
||||
h64.xor(h)
|
||||
|
||||
// Reset the state
|
||||
this.init( this.seed )
|
||||
|
||||
return h64
|
||||
}
|
||||
|
||||
module.exports = XXH64
|
||||
32
node_modules/xxhashjs/package.json
generated
vendored
Normal file
32
node_modules/xxhashjs/package.json
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "xxhashjs",
|
||||
"version": "0.2.2",
|
||||
"description": "xxHash in Javascript",
|
||||
"main": "./lib/index.js",
|
||||
"scripts": {
|
||||
"test": "mocha",
|
||||
"prepublish": "webpack && uglifyjs -m -c -o build/xxhash.min.js build/xxhash.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/pierrec/js-xxhash"
|
||||
},
|
||||
"keywords": [
|
||||
"xxhash",
|
||||
"xxh"
|
||||
],
|
||||
"author": "Pierre Curto",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/pierrec/js-xxhash/issues"
|
||||
},
|
||||
"homepage": "https://github.com/pierrec/js-xxhash",
|
||||
"dependencies": {
|
||||
"cuint": "^0.2.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"benchmark": "*",
|
||||
"uglifyjs": "^2.4.11",
|
||||
"webpack": "^3.10.0"
|
||||
}
|
||||
}
|
||||
172
node_modules/xxhashjs/test/XXH-test.js
generated
vendored
Normal file
172
node_modules/xxhashjs/test/XXH-test.js
generated
vendored
Normal file
@@ -0,0 +1,172 @@
|
||||
var assert = require('assert')
|
||||
var XXH = require('..')
|
||||
|
||||
describe('XXH', function () {
|
||||
var seed = 0
|
||||
|
||||
describe('with small input multiple of 4', function () {
|
||||
var input = 'abcd'
|
||||
var expected = 'A3643705' // Computed with xxHash C version
|
||||
|
||||
it('should return hash in a single step', function (done) {
|
||||
var h = XXH.h32( input, seed ).toString(16).toUpperCase()
|
||||
|
||||
assert.equal( h, expected )
|
||||
done()
|
||||
})
|
||||
|
||||
it('should return hash in many steps', function (done) {
|
||||
var H = XXH.h32( seed )
|
||||
var h = H.update( input ).digest().toString(16).toUpperCase()
|
||||
|
||||
assert.equal( h, expected )
|
||||
done()
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe('with medium input multiple of 4', function () {
|
||||
var input = Array(1001).join('abcd')
|
||||
var expected = 'E18CBEA'
|
||||
|
||||
it('should return hash in a single step', function (done) {
|
||||
var h = XXH.h32( input, seed ).toString(16).toUpperCase()
|
||||
|
||||
assert.equal( h, expected )
|
||||
done()
|
||||
})
|
||||
|
||||
it('should return hash in many steps', function (done) {
|
||||
var H = XXH.h32( seed )
|
||||
var h = H.update( input ).digest().toString(16).toUpperCase()
|
||||
|
||||
assert.equal( h, expected )
|
||||
done()
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe('with small input', function () {
|
||||
var input = 'abc'
|
||||
var expected = '32D153FF' // Computed with xxHash C version
|
||||
|
||||
it('should return hash in a single step', function (done) {
|
||||
var h = XXH.h32( input, seed ).toString(16).toUpperCase()
|
||||
|
||||
assert.equal( h, expected )
|
||||
done()
|
||||
})
|
||||
|
||||
it('should return hash in many steps', function (done) {
|
||||
var H = XXH.h32( seed )
|
||||
var h = H.update( input ).digest().toString(16).toUpperCase()
|
||||
|
||||
assert.equal( h, expected )
|
||||
done()
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe('with medium input', function () {
|
||||
var input = Array(1000).join('abc')
|
||||
var expected = '89DA9B6E'
|
||||
|
||||
it('should return hash in a single step', function (done) {
|
||||
var h = XXH.h32( input, seed ).toString(16).toUpperCase()
|
||||
|
||||
assert.equal( h, expected )
|
||||
done()
|
||||
})
|
||||
|
||||
it('should return hash in many steps', function (done) {
|
||||
var H = XXH.h32( seed )
|
||||
var h = H.update( input ).digest().toString(16).toUpperCase()
|
||||
|
||||
assert.equal( h, expected )
|
||||
done()
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe('with split medium input', function () {
|
||||
var input = Array(1000).join('abc')
|
||||
var expected = '89DA9B6E'
|
||||
|
||||
it('should return hash with split input < 16', function (done) {
|
||||
var H = XXH.h32( seed )
|
||||
var h = H
|
||||
.update( input.slice(0, 10) )
|
||||
.update( input.slice(10) )
|
||||
.digest().toString(16).toUpperCase()
|
||||
|
||||
assert.equal( h, expected )
|
||||
done()
|
||||
})
|
||||
|
||||
it('should return hash with split input = 16', function (done) {
|
||||
var H = XXH.h32( seed )
|
||||
var h = H
|
||||
.update( input.slice(0, 16) )
|
||||
.update( input.slice(16) )
|
||||
.digest().toString(16).toUpperCase()
|
||||
|
||||
assert.equal( h, expected )
|
||||
done()
|
||||
})
|
||||
|
||||
it('should return hash with split input > 16', function (done) {
|
||||
var H = XXH.h32( seed )
|
||||
var h = H
|
||||
.update( input.slice(0, 20) )
|
||||
.update( input.slice(20) )
|
||||
.digest().toString(16).toUpperCase()
|
||||
|
||||
assert.equal( h, expected )
|
||||
done()
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe('with utf-8 strings', function () {
|
||||
var input = 'heiå'
|
||||
var expected = 'DB5ABCCC' // Computed with xxHash C version
|
||||
|
||||
it('should return hash', function (done) {
|
||||
var h = XXH.h32( input, seed ).toString(16).toUpperCase()
|
||||
|
||||
assert.equal( h, expected )
|
||||
done()
|
||||
})
|
||||
|
||||
it('should return hash in many steps', function (done) {
|
||||
var H = XXH.h32( seed )
|
||||
var h = H.update( input ).digest().toString(16).toUpperCase()
|
||||
|
||||
assert.equal( h, expected )
|
||||
done()
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe('with utf-8 strings', function () {
|
||||
var input = 'κόσμε'
|
||||
var expected = 'D855F606' // Computed with xxHash C version
|
||||
|
||||
it('should return hash', function (done) {
|
||||
var h = XXH.h32( input, seed ).toString(16).toUpperCase()
|
||||
|
||||
assert.equal( h, expected )
|
||||
done()
|
||||
})
|
||||
|
||||
it('should return hash in many steps', function (done) {
|
||||
var H = XXH.h32( seed )
|
||||
var h = H.update( input ).digest().toString(16).toUpperCase()
|
||||
|
||||
assert.equal( h, expected )
|
||||
done()
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
11
node_modules/xxhashjs/webpack.config.js
generated
vendored
Normal file
11
node_modules/xxhashjs/webpack.config.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
var path = require("path")
|
||||
|
||||
module.exports = {
|
||||
"entry": "./lib/index.js"
|
||||
, "output": {
|
||||
"path": __dirname + "/build"
|
||||
, "filename": "xxhash.js"
|
||||
, "library": "XXH"
|
||||
, "libraryTarget": "umd"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user