summaryrefslogtreecommitdiff
path: root/lib/inifile
diff options
context:
space:
mode:
authorLucas Gabriel Vuotto <lvuotto92@gmail.com>2017-11-01 16:53:26 -0300
committerOri Bernstein <ori@markovcorp.com>2017-11-14 13:50:39 -0800
commit83d26331a5419033927800760e8a59f1bd84d2b9 (patch)
treed5985e8e5a32e673f549fcaa8eb23b5335f4f74d /lib/inifile
parent8a662861ad3ded8e965ab43e5bc254dd7ee85815 (diff)
downloadmc-83d26331a5419033927800760e8a59f1bd84d2b9.tar.gz
Use new traits to implement hash tables
Signed-off-by: Lucas Gabriel Vuotto <lvuotto92@gmail.com>
Diffstat (limited to 'lib/inifile')
-rw-r--r--lib/inifile/parse.myr19
-rw-r--r--lib/inifile/types.myr23
2 files changed, 24 insertions, 18 deletions
diff --git a/lib/inifile/parse.myr b/lib/inifile/parse.myr
index 6b9be91..6276cf8 100644
--- a/lib/inifile/parse.myr
+++ b/lib/inifile/parse.myr
@@ -44,7 +44,7 @@ const loadf = {fd
var f
ini = std.mk([
- .elts = std.mkht(keyhash, keyeq)
+ .elts = std.mkht()
])
p = std.mk([
.line = 1,
@@ -138,20 +138,3 @@ const parsekvp = {p, ini, ln
-> true
;;
}
-
-const keyhash = {k
- var sect, key
-
- (sect, key) = k
- -> std.strhash(sect) ^ std.strhash(key)
-}
-
-const keyeq = {a, b
- var s1, k1
- var s2, k2
-
- (s1, k1) = a
- (s2, k2) = a
- -> std.streq(s1, s2) && std.streq(k1, k2)
-}
-
diff --git a/lib/inifile/types.myr b/lib/inifile/types.myr
index f573b7b..f2736e0 100644
--- a/lib/inifile/types.myr
+++ b/lib/inifile/types.myr
@@ -11,4 +11,27 @@ pkg inifile =
sects : byte[:][:]
elts : std.htab((byte[:], byte[:]), byte[:])#
;;
+
+ impl std.hashable (byte[:], byte[:])
+ impl std.comparable (byte[:], byte[:])
+;;
+
+impl std.hashable (byte[:], byte[:]) =
+ hash = {k
+ var sect, key
+
+ (sect, key) = k
+ -> std.hash(sect) ^ std.hash(key)
+ }
+;;
+
+impl std.comparable (byte[:], byte[:]) =
+ cmp = {a, b
+ var s1, k1
+ var s2, k2
+
+ (s1, k1) = a
+ (s2, k2) = a
+ -> std.cmp(s1, s2) && std.cmp(k1, k2)
+ }
;;