-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
42 lines (30 loc) · 873 Bytes
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Fisher-Yates
function shuffle( array ) {
var counter = array.length, temp, index;
// While there are elements in the array
while (counter > 0) {
// Pick a random index
index = Math.floor(Math.random() * counter);
// Decrease counter by 1
counter--;
// And swap the last element with it
temp = array[counter];
array[counter] = array[index];
array[index] = temp;
}
return array;
}
// kind of sloppy almost murmurhash1-3 but I need this to be a fingerprint in less code.
function hash( data ) {
var hash = 0xdeadbeef;
var k;
for( var i=0; i<data.length; i+=4) {
k = data[i] << 24 | data[i+1] << 16 | data[i+2] << 8 | data[i+3];
k *= 0x5bd1e995;
k ^= k >> 15;
k *= 0x5bd1e995;
hash *= 0x5bd1e995;
hash ^= k;
}
return hash;
}