Fix $$str_hash to use a5hash like String.hash() (#2403)

* Fix `$$str_hash` to use `a5hash` like `String.hash()`
This commit is contained in:
Zack Puhl
2025-08-14 14:24:01 -04:00
committed by GitHub
parent 85dc9c45ab
commit eb8fb8871f
6 changed files with 94 additions and 3 deletions

View File

@@ -174,6 +174,18 @@ fn void test_hash_repeat()
assert(int.typeid.hash() == int.typeid.hash());
}
fn void test_builtin_string_hashing() => @pool()
{
var $x = "";
ulong l;
$for var $i = 0; $i < 65; ++$i: // 65 is a good length to reliably test all branches w/o being excessive
l = string::tformat("%s%s", $x, $i).hash();
var $r = $$str_hash(@sprintf("%s%s", $x, $i));
assert((uint)l == (uint)$r, "Builtin $$str_hash mismatch against String.hash()");
$x = $x +++ "a";
$endfor
}
fn void test_ct_clz()
{
assert(@clz((ulong)0) == ulong.sizeof * 8);