1
0
Fork 0
forked from AbleOS/ableos
ableos/sysdata/programs/test/src/tests/stn/hashers.hb
Jakub Doka 47d727855d
adding instruction log
Signed-off-by: Jakub Doka <jakub.doka2@gmail.com>
2024-12-22 22:10:24 +01:00

27 lines
842 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
}