This commit is contained in:
@ -13,7 +13,7 @@ export interface NodeRegistry {
|
||||
* @throws An error if the nodes could not be loaded
|
||||
* @remarks This method should be called before calling getNode or getAllNodes
|
||||
*/
|
||||
load: (nodeIds: (NodeId | string)[]) => Promise<NodeDefinition[]>;
|
||||
load: (nodeIds: NodeId[]) => Promise<NodeDefinition[]>;
|
||||
/**
|
||||
* Get a node by id
|
||||
* @param id - The id of the node to get
|
||||
|
@ -14,10 +14,10 @@ test("fastHashArray doesnt product collisions", () => {
|
||||
|
||||
const a = new Int32Array(1000);
|
||||
|
||||
const hash_a = fastHashArray(a);
|
||||
const hash_a = fastHashArray(a.buffer);
|
||||
a[0] = 1;
|
||||
|
||||
const hash_b = fastHashArray(a);
|
||||
const hash_b = fastHashArray(a.buffer);
|
||||
|
||||
expect(hash_a).not.toEqual(hash_b);
|
||||
|
||||
@ -28,13 +28,13 @@ test('fastHashArray is fast(ish) < 20ms', () => {
|
||||
const a = new Int32Array(10_000);
|
||||
|
||||
const t0 = performance.now();
|
||||
fastHashArray(a);
|
||||
fastHashArray(a.buffer);
|
||||
|
||||
const t1 = performance.now();
|
||||
|
||||
a[0] = 1;
|
||||
|
||||
fastHashArray(a);
|
||||
fastHashArray(a.buffer);
|
||||
|
||||
const t2 = performance.now();
|
||||
|
||||
@ -48,7 +48,7 @@ test('fastHashArray is deterministic', () => {
|
||||
a[42] = 69;
|
||||
const b = new Int32Array(1000);
|
||||
b[42] = 69;
|
||||
const hashA = fastHashArray(a);
|
||||
const hashB = fastHashArray(b);
|
||||
const hashA = fastHashArray(a.buffer);
|
||||
const hashB = fastHashArray(b.buffer);
|
||||
expect(hashA).toEqual(hashB);
|
||||
});
|
||||
|
@ -83,8 +83,8 @@ function sha256(data?: string | Uint8Array) {
|
||||
return { add, digest };
|
||||
}
|
||||
|
||||
export function fastHashArray(arr: Int32Array): string {
|
||||
return sha256(new Uint8Array(arr.buffer)).digest();
|
||||
export function fastHashArrayBuffer(buffer: ArrayBuffer): string {
|
||||
return sha256(new Uint8Array(buffer)).digest();
|
||||
}
|
||||
|
||||
// Shamelessly copied from
|
||||
|
Reference in New Issue
Block a user