This commit is contained in:
Achim D. Brucker 2005-09-21 18:22:50 +00:00
parent 2f78b7aeeb
commit 078abb3d2d
1 changed files with 30 additions and 0 deletions

30
src/contrib/HashTable.sml Normal file
View File

@ -0,0 +1,30 @@
structure HashString =
struct
fun hashString _ = ()
end
structure HashTable =
struct
datatype ('a, 'b) hash_table = HT of {
eq_pred : ('a * 'a) -> bool,
not_found : exn,
table: (('a*'b) list) ref
}
fun mkTable (_, eq) (_, notFound) = HT{
eq_pred = eq,
not_found = notFound,
table = ref ([])
}
fun find (HT{table,...}) key =
Option.map (fn (a,b) => b) ((List.find (fn (x,y) => x =key) (!table)))
fun insert (HT{table,...}) (k,v) = (table:=([(k,v)]@ (!(table))))
end