Skip to content

Commit a2cb917

Browse files
committed
switch to gearhash-wasm package
1 parent 14a9ef4 commit a2cb917

File tree

14 files changed

+78
-8
lines changed

14 files changed

+78
-8
lines changed
File renamed without changes.
File renamed without changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { DEFAULT_TABLE } from "./table";
2+
export { nextMatch } from "./next-match";
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// The entry file of your WebAssembly module.
2+
3+
import { DEFAULT_TABLE } from "./table";
4+
5+
// Function to find the next match in the buffer
6+
export function nextMatch(buf: Uint8Array, mask: u64, hash: u64 = 0, table: StaticArray<u64> = DEFAULT_TABLE): i32 {
7+
for (let i = 0; i < buf.length; i++) {
8+
const b = buf[i];
9+
hash = (hash << 1) + table[b];
10+
11+
if ((hash & mask) == 0) {
12+
return i + 1;
13+
}
14+
}
15+
16+
return -1; // Return -1 to indicate no match found (equivalent to None in Rust)
17+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

packages/gearhash/package.json renamed to packages/gearhash-wasm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@huggingface/gearhash",
2+
"name": "@huggingface/gearhash-wasms",
33
"version": "0.0.1",
44
"scripts": {
55
"build:debug": "asc assembly/index.ts --target debug",
File renamed without changes.

0 commit comments

Comments
 (0)