mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fix fnv a hashes (#1667)
* fix fnv32a * fix fnv64a * Simplify code --------- Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
This commit is contained in:
@@ -8,7 +8,7 @@ distinct Fnv32a = uint;
|
||||
const FNV32A_START @private = 0x811c9dc5;
|
||||
const FNV32A_MUL @private = 0x01000193;
|
||||
|
||||
macro void @update(uint* &h, char x) @private => *h = (*h * FNV32A_MUL) ^ x;
|
||||
macro void @update(&h, char x) @private => *h = (*h ^ ($typeof(*h))x) * FNV32A_MUL;
|
||||
|
||||
fn void Fnv32a.init(&self)
|
||||
{
|
||||
@@ -17,17 +17,17 @@ fn void Fnv32a.init(&self)
|
||||
|
||||
fn void Fnv32a.update(&self, char[] data)
|
||||
{
|
||||
uint h = (uint)*self;
|
||||
Fnv32a h = *self;
|
||||
foreach (char x : data)
|
||||
{
|
||||
@update(h, x);
|
||||
}
|
||||
*self = (Fnv32a)h;
|
||||
*self = h;
|
||||
}
|
||||
|
||||
macro void Fnv32a.update_char(&self, char c)
|
||||
{
|
||||
@update(*self, x);
|
||||
@update(*self, c);
|
||||
}
|
||||
|
||||
fn uint encode(char[] data)
|
||||
@@ -38,4 +38,4 @@ fn uint encode(char[] data)
|
||||
@update(h, x);
|
||||
}
|
||||
return h;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user