1
0
Fork 0
forked from AbleOS/ableos
ableos/sysdata/programs/test/src/tests/stn/hashers.hb
2024-12-22 19:48:12 +00:00

26 lines
840 B
Plaintext

.{hashers, log, memory, fmt, string, math} := @use("stn")
test := fn(): uint {
target := "abcdefghijklmnop"
strings := .["abcdefshijklmnop", "abcdefghijklnnop", "abcdefshijklmnop", "abcdefghijklmnop", "abcdefghijflmnop", "dbcdefghijklmnop", "abcdefghijklmnop"]
len := @sizeof(@TypeOf(strings)) / @sizeof(^u8)
// hasher := hashers.foldhash.FoldHasher.new(1)
hasher := hashers.foldhash.FoldHasher.default()
hasher.write(target.ptr, target.len)
correct := hasher.finish()
log.printf("target string: {}, target hash: {}", .(target, correct), .{radix: 16})
i := 0
loop if i == len break else {
defer i += 1
hasher.reset()
hasher.write(strings[i].ptr, strings[i].len)
d := hasher.finish()
log.printf("matches: {}, string: {}, hash: {}", .(d == correct, strings[i], d), .{radix: 16})
}
log.print("done", .{})
return 0
}