Change all hash functions to have a common hash function.

This commit is contained in:
Christoffer Lerno
2025-03-03 20:07:02 +01:00
parent 261bfb97c6
commit 0a905d8458
10 changed files with 11 additions and 10 deletions

View File

@@ -434,8 +434,8 @@ macro uint int128.hash(int128 i) => @generic_hash(i);
macro uint uint128.hash(uint128 i) => @generic_hash(i);
macro uint bool.hash(bool b) => @generic_hash(b);
macro uint typeid.hash(typeid t) => @generic_hash(((ulong)(uptr)t));
macro uint String.hash(String c) => (uint)fnv32a::encode(c);
macro uint char[].hash(char[] c) => (uint)fnv32a::encode(c);
macro uint String.hash(String c) => (uint)fnv32a::hash(c);
macro uint char[].hash(char[] c) => (uint)fnv32a::hash(c);
macro uint void*.hash(void* ptr) => @generic_hash(((ulong)(uptr)ptr));

View File

@@ -40,7 +40,7 @@ fn uint Adler32.final(&self)
return (self.b << 16) | self.a;
}
fn uint encode(char[] data)
fn uint hash(char[] data)
{
uint a = 1;
uint b = 0;

View File

@@ -33,7 +33,7 @@ fn uint Crc32.final(&self)
return ~self.result;
}
fn uint encode(char[] data)
fn uint hash(char[] data)
{
uint result = ~(uint)(0);
foreach (char x : data)

View File

@@ -33,7 +33,7 @@ fn ulong Crc64.final(&self)
return self.result;
}
fn ulong encode(char[] data)
fn ulong hash(char[] data)
{
ulong result = (ulong)(0);
foreach (char x : data)

View File

@@ -30,7 +30,7 @@ macro void Fnv32a.update_char(&self, char c)
update(self, c);
}
fn uint encode(char[] data)
fn uint hash(char[] data)
{
uint h = FNV32A_START;
foreach (char x : data)

View File

@@ -30,7 +30,7 @@ macro void Fnv64a.update_char(&self, char c)
update(self, c);
}
fn ulong encode(char[] data)
fn ulong hash(char[] data)
{
ulong h = FNV64A_START;
foreach (char x : data)

View File

@@ -69,7 +69,7 @@ fn void seeder(char[] input, char[] out_buffer)
macro uint hash(value) @local
{
return fnv32a::encode(&&bitcast(value, char[$sizeof(value)]));
return fnv32a::hash(&&bitcast(value, char[$sizeof(value)]));
}
fn char[8 * 4] entropy() @if(!env::WASM_NOLIBC)

View File

@@ -32,6 +32,7 @@
- `mem::temp_new_array` changed to `mem::temp_array`.
- Add `ONHEAP` variants for List/HashMap for initializing global maps on the heap.
- Remove Vec2 and other aliases from std::math. Replace `.length_sq()` with `sq_magnitude()`
- Change all hash functions to have a common `hash` function.
## 0.6.8 Change list

View File

@@ -19,6 +19,6 @@ fn void test_fnv32a()
assert ((uint)hash == want, "got: %d, want: %d", hash, want);
// encode
uint encoded = fnv32a::encode(input);
uint encoded = fnv32a::hash(input);
assert (encoded == want, "got: %d, want: %d", encoded, want);
}

View File

@@ -19,6 +19,6 @@ fn void test_fnv64a()
assert ((ulong)hash == want, "got: %d, want: %d", hash, want);
// encode
ulong encoded = fnv64a::encode(input);
ulong encoded = fnv64a::hash(input);
assert (encoded == want, "got: %d, want: %d", encoded, want);
}