mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Change all hash functions to have a common hash function.
This commit is contained in:
@@ -434,8 +434,8 @@ macro uint int128.hash(int128 i) => @generic_hash(i);
|
|||||||
macro uint uint128.hash(uint128 i) => @generic_hash(i);
|
macro uint uint128.hash(uint128 i) => @generic_hash(i);
|
||||||
macro uint bool.hash(bool b) => @generic_hash(b);
|
macro uint bool.hash(bool b) => @generic_hash(b);
|
||||||
macro uint typeid.hash(typeid t) => @generic_hash(((ulong)(uptr)t));
|
macro uint typeid.hash(typeid t) => @generic_hash(((ulong)(uptr)t));
|
||||||
macro uint String.hash(String c) => (uint)fnv32a::encode(c);
|
macro uint String.hash(String c) => (uint)fnv32a::hash(c);
|
||||||
macro uint char[].hash(char[] c) => (uint)fnv32a::encode(c);
|
macro uint char[].hash(char[] c) => (uint)fnv32a::hash(c);
|
||||||
macro uint void*.hash(void* ptr) => @generic_hash(((ulong)(uptr)ptr));
|
macro uint void*.hash(void* ptr) => @generic_hash(((ulong)(uptr)ptr));
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ fn uint Adler32.final(&self)
|
|||||||
return (self.b << 16) | self.a;
|
return (self.b << 16) | self.a;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn uint encode(char[] data)
|
fn uint hash(char[] data)
|
||||||
{
|
{
|
||||||
uint a = 1;
|
uint a = 1;
|
||||||
uint b = 0;
|
uint b = 0;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ fn uint Crc32.final(&self)
|
|||||||
return ~self.result;
|
return ~self.result;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn uint encode(char[] data)
|
fn uint hash(char[] data)
|
||||||
{
|
{
|
||||||
uint result = ~(uint)(0);
|
uint result = ~(uint)(0);
|
||||||
foreach (char x : data)
|
foreach (char x : data)
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ fn ulong Crc64.final(&self)
|
|||||||
return self.result;
|
return self.result;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ulong encode(char[] data)
|
fn ulong hash(char[] data)
|
||||||
{
|
{
|
||||||
ulong result = (ulong)(0);
|
ulong result = (ulong)(0);
|
||||||
foreach (char x : data)
|
foreach (char x : data)
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ macro void Fnv32a.update_char(&self, char c)
|
|||||||
update(self, c);
|
update(self, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn uint encode(char[] data)
|
fn uint hash(char[] data)
|
||||||
{
|
{
|
||||||
uint h = FNV32A_START;
|
uint h = FNV32A_START;
|
||||||
foreach (char x : data)
|
foreach (char x : data)
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ macro void Fnv64a.update_char(&self, char c)
|
|||||||
update(self, c);
|
update(self, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ulong encode(char[] data)
|
fn ulong hash(char[] data)
|
||||||
{
|
{
|
||||||
ulong h = FNV64A_START;
|
ulong h = FNV64A_START;
|
||||||
foreach (char x : data)
|
foreach (char x : data)
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ fn void seeder(char[] input, char[] out_buffer)
|
|||||||
|
|
||||||
macro uint hash(value) @local
|
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)
|
fn char[8 * 4] entropy() @if(!env::WASM_NOLIBC)
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
- `mem::temp_new_array` changed to `mem::temp_array`.
|
- `mem::temp_new_array` changed to `mem::temp_array`.
|
||||||
- Add `ONHEAP` variants for List/HashMap for initializing global maps on the heap.
|
- 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()`
|
- 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
|
## 0.6.8 Change list
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,6 @@ fn void test_fnv32a()
|
|||||||
assert ((uint)hash == want, "got: %d, want: %d", hash, want);
|
assert ((uint)hash == want, "got: %d, want: %d", hash, want);
|
||||||
|
|
||||||
// encode
|
// encode
|
||||||
uint encoded = fnv32a::encode(input);
|
uint encoded = fnv32a::hash(input);
|
||||||
assert (encoded == want, "got: %d, want: %d", encoded, want);
|
assert (encoded == want, "got: %d, want: %d", encoded, want);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,6 @@ fn void test_fnv64a()
|
|||||||
assert ((ulong)hash == want, "got: %d, want: %d", hash, want);
|
assert ((ulong)hash == want, "got: %d, want: %d", hash, want);
|
||||||
|
|
||||||
// encode
|
// encode
|
||||||
ulong encoded = fnv64a::encode(input);
|
ulong encoded = fnv64a::hash(input);
|
||||||
assert (encoded == want, "got: %d, want: %d", encoded, want);
|
assert (encoded == want, "got: %d, want: %d", encoded, want);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user