新增hash
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
class WebGLUtils {
|
||||
/**
|
||||
* 获取webgl context
|
||||
*/
|
||||
public static getContext() {
|
||||
const canvas = document.getElementsByTagName('canvas')[0];
|
||||
return canvas.getContext('2d');
|
||||
}
|
||||
}
|
||||
22
source/src/Utils/Hash.ts
Normal file
22
source/src/Utils/Hash.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
module es {
|
||||
export class Hash {
|
||||
/**
|
||||
* 从一个字节数组中计算一个哈希值
|
||||
* @param data
|
||||
*/
|
||||
public static computeHash(...data: number[]) {
|
||||
const p: number = 16777619;
|
||||
let hash = 2166136261;
|
||||
|
||||
for (let i = 0; i < data.length; i++)
|
||||
hash = (hash ^ data[i]) * p;
|
||||
|
||||
hash += hash << 13;
|
||||
hash ^= hash >> 7;
|
||||
hash += hash << 3;
|
||||
hash ^= hash >> 17;
|
||||
hash += hash << 5;
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user