summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas Gabriel Vuotto <lvuotto92@gmail.com>2017-09-08 01:19:42 -0300
committerOri Bernstein <ori@mmarkovcorp.com>2017-09-08 11:00:44 -0700
commit63b175e2da14c72d77f329f05385402104ef0fc7 (patch)
tree7a532c1e5cbc8e9c08eeff1f61077cda2b734907
parente5b424be893e7f771456a548ab66e1bcb7ed50d3 (diff)
downloadmc-63b175e2da14c72d77f329f05385402104ef0fc7.tar.gz
Replace murmurhash with siphash
Signed-off-by: Lucas Gabriel Vuotto <lvuotto92@gmail.com>
-rw-r--r--lib/std/bitset.myr2
-rw-r--r--lib/std/hashfuncs.myr20
-rw-r--r--lib/std/htab.myr8
-rw-r--r--lib/std/test/bitset.myr6
-rw-r--r--lib/std/test/hashfuncs.myr4
5 files changed, 20 insertions, 20 deletions
diff --git a/lib/std/bitset.myr b/lib/std/bitset.myr
index b173d87..afc66b4 100644
--- a/lib/std/bitset.myr
+++ b/lib/std/bitset.myr
@@ -30,7 +30,7 @@ pkg std =
const bsunion : (a : bitset#, b : bitset# -> void)
const bseq : (a : bitset#, b : bitset# -> bool)
const bsissubset : (a : bitset#, b : bitset# -> bool)
- const bshash : (a : bitset# -> uint32)
+ const bshash : (a : bitset# -> uint64)
type bsiter = struct
idx : size
diff --git a/lib/std/hashfuncs.myr b/lib/std/hashfuncs.myr
index 1fb949c..023f63a 100644
--- a/lib/std/hashfuncs.myr
+++ b/lib/std/hashfuncs.myr
@@ -8,25 +8,25 @@ use "types"
use "utf"
pkg std =
- const strhash : (s : byte[:] -> uint32)
+ const strhash : (s : byte[:] -> uint64)
const streq : (a : byte[:], b : byte[:] -> bool)
- const strcasehash : (s : byte[:] -> uint32)
+ const strcasehash : (s : byte[:] -> uint64)
const strcaseeq : (a : byte[:], b : byte[:] -> bool)
- generic ptrhash : (p : @a# -> uint32)
+ generic ptrhash : (p : @a# -> uint64)
generic ptreq : (a : @a#, b : @a# -> bool)
- generic inthash : (v : @a::(integral,numeric) -> uint32)
+ generic inthash : (v : @a::(integral,numeric) -> uint64)
generic inteq : (a : @a::(integral,numeric), b : @a::(integral,numeric) -> bool)
const murmurhash2 : (data : byte[:], seed : uint32 -> uint32)
const siphash24 : (data : byte[:], seed : byte[16] -> uint64)
- generic slhash : (sl : @a[:] -> uint32)
+ generic slhash : (sl : @a[:] -> uint64)
;;
-const Seed = 1234
+const Seed : byte[16] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
generic slhash = {data : @a[:]
-> strhash(slbytes(data))
@@ -40,7 +40,7 @@ generic slbytes = {data : @a[:]
}
const strhash = {s
- -> murmurhash2(s, Seed)
+ -> siphash24(s, Seed)
}
const strcaseeq = {a, b
@@ -68,7 +68,7 @@ const strcasehash = {s
(c, s) = std.strstep(s)
std.slpush(&chars, std.tolower(c))
;;
- h = murmurhash2(slbytes(chars), Seed)
+ h = siphash24(slbytes(chars), Seed)
slfree(chars)
-> h
}
@@ -81,7 +81,7 @@ generic ptrhash = {p : @a#
var x
x = (&p : byte#)
- -> murmurhash2(x[0:sizeof(@a#)], Seed)
+ -> siphash24(x[0:sizeof(@a#)], Seed)
}
generic ptreq = {a, b
@@ -92,7 +92,7 @@ generic inthash = {v : @a::(integral,numeric)
var p
p = (&v : byte#)
- -> murmurhash2(p[0:sizeof(@a)], Seed)
+ -> siphash24(p[0:sizeof(@a)], Seed)
}
generic inteq = {a, b
diff --git a/lib/std/htab.myr b/lib/std/htab.myr
index ec4ce72..b728124 100644
--- a/lib/std/htab.myr
+++ b/lib/std/htab.myr
@@ -6,19 +6,19 @@ use "types"
pkg std =
type htab(@k, @v) = struct
- hash : (k : @k -> uint32)
+ hash : (k : @k -> uint64)
eq : (a : @k, b : @k -> bool)
nelt : size
ndead : size
keys : @k[:]
vals : @v[:]
- hashes : uint32[:]
+ hashes : uint64[:]
dead : bool[:]
;;
- generic mkht : (h : (k : @k -> uint32), eq : (a : @k, b : @k -> bool) -> htab(@k, @v)#)
- generic htinit : (ht : htab(@k, @v)#, h : (k : @k -> uint32), eq : (a : @k, b : @k -> bool) -> void)
+ generic mkht : (h : (k : @k -> uint64), eq : (a : @k, b : @k -> bool) -> htab(@k, @v)#)
+ generic htinit : (ht : htab(@k, @v)#, h : (k : @k -> uint64), eq : (a : @k, b : @k -> bool) -> void)
generic htfree : (ht : htab(@k, @v)# -> void)
generic htput : (ht : htab(@k, @v)#, k : @k, v : @v -> void)
generic htdel : (ht : htab(@k, @v)#, k : @k -> void)
diff --git a/lib/std/test/bitset.myr b/lib/std/test/bitset.myr
index 9112537..6936cba 100644
--- a/lib/std/test/bitset.myr
+++ b/lib/std/test/bitset.myr
@@ -49,11 +49,11 @@ const main = {
}],
[.name="hash", .fn={ctx
var bs = mkset([][:])
- testr.check(ctx, std.bshash(bs) == 2580988821, "wrong hash, got {}", std.bshash(bs))
+ testr.check(ctx, std.bshash(bs) == 0x726fdb47dd0e0e31, "wrong hash, got {}", std.bshash(bs))
std.bsput(bs, 123456)
- testr.check(ctx, std.bshash(bs) == 2020624217, "wrong hash, got {}", std.bshash(bs))
+ testr.check(ctx, std.bshash(bs) == 0x778abc1d7706143b, "wrong hash, got {}", std.bshash(bs))
std.bsdel(bs, 123456)
- testr.check(ctx, std.bshash(bs) == 2580988821, "wrong hash, got {}", std.bshash(bs))
+ testr.check(ctx, std.bshash(bs) == 0x726fdb47dd0e0e31, "wrong hash, got {}", std.bshash(bs))
std.bsfree(bs)
}]
][:])
diff --git a/lib/std/test/hashfuncs.myr b/lib/std/test/hashfuncs.myr
index ee10ad7..94313b0 100644
--- a/lib/std/test/hashfuncs.myr
+++ b/lib/std/test/hashfuncs.myr
@@ -4,7 +4,7 @@ use testr
const main = {
testr.run([
[.name="string hash and equality", .fn={ctx
- testr.check(ctx, std.strhash("abc") == 1241861192, "wrong hash\n")
+ testr.check(ctx, std.strhash("abc") == 0x5dbcfa53aa2007a5, "wrong hash\n")
testr.check(ctx, std.streq("abc\0def", "abc\0def"), "equal strings not equal\n")
testr.check(ctx, !std.streq("abc\0def", "abcdef"), "unequal strings are equal\n")
}],
@@ -20,7 +20,7 @@ const main = {
testr.check(ctx, !std.ptreq(&x, &y), "unequal pointers are equal")
}],
[.name="int hash and equality", .fn={ctx
- testr.check(ctx, std.inthash(123) == 3497506805, "wrong int hash")
+ testr.check(ctx, std.inthash(123) == 0x5671db246859d5b6, "wrong int hash")
testr.check(ctx, std.inteq(123, 123), "equal integers not equal")
testr.check(ctx, !std.inteq(123, 456), "unequal integers are equal")
}],