The Hash2TableFn
functor provides hash tables that are keyed by two
different key types. Items are inserted with two keys, either of
which may be used to lookup the item. Essentially, it is a pair of
hash tables that are kept synchronized.
The tables are implemented as an array of buckets, which are lists of key-value pairs. The number of buckets grows with the number of table entries.
Synopsis
functor Hash2TableFn (
structure Key1 : HASH_KEY
structure Key2 : HASH_KEY
) : MONO_HASH2_TABLE
Functor Argument Interface
structure Key1 : HASH_KEY
structure Key2 : HASH_KEY
Functor Argument Description
Interface
structure Key1 : HASH_KEY
structure Key2 : HASH_KEY
type 'a hash_table
val mkTable : (int * exn) -> 'a hash_table
val clear : 'a hash_table -> unit
val insert : 'a hash_table -> (Key1.hash_key * Key2.hash_key * 'a) -> unit
val inDomain1 : 'a hash_table -> Key1.hash_key -> bool
val inDomain2 : 'a hash_table -> Key2.hash_key -> bool
val lookup1 : 'a hash_table -> Key1.hash_key -> 'a
val lookup2 : 'a hash_table -> Key2.hash_key -> 'a
val find1 : 'a hash_table -> Key1.hash_key -> 'a option
val find2 : 'a hash_table -> Key2.hash_key -> 'a option
val remove1 : 'a hash_table -> Key1.hash_key -> 'a
val remove2 : 'a hash_table -> Key2.hash_key -> 'a
val numItems : 'a hash_table -> int
val listItems : 'a hash_table -> 'a list
val listItemsi : 'a hash_table -> (Key1.hash_key * Key2.hash_key * 'a) list
val app : ('a -> unit) -> 'a hash_table -> unit
val appi : ((Key1.hash_key * Key2.hash_key * 'a) -> unit) -> 'a hash_table
-> unit
val map : ('a -> 'b) -> 'a hash_table -> 'b hash_table
val mapi : ((Key1.hash_key * Key2.hash_key * 'a) -> 'b) -> 'a hash_table
-> 'b hash_table
val fold : (('a * 'b) -> 'b) -> 'b -> 'a hash_table -> 'b
val foldi : ((Key1.hash_key * Key2.hash_key * 'a * 'b) -> 'b) -> 'b
val filter : ('a -> bool) -> 'a hash_table -> unit
val filteri : ((Key1.hash_key * Key2.hash_key * 'a) -> bool) -> 'a hash_table
-> unit
val copy : 'a hash_table -> 'a hash_table
val bucketSizes : 'a hash_table -> (int list * int list)
Interface Description
structure Key1 : HASH_KEY
-
The substructure that specifies the first key type.
structure Key2 : HASH_KEY
-
The substructure that specifies the second key type.
type 'a hash_table
-
The type of imperative hash tables indexed by the key types.
val mkTable : (int * exn) -> 'a hash_table
-
mkTable (n, ex)
creates a new hash table; the table will be initially sized to hold at leastn
items. The exceptionex
is raised by the lookup and remove functions (described below) when the search key is not in the domain. val clear : 'a hash_table -> unit
-
clear tbl
removes all of the entries in the table. val insert : 'a hash_table -> (Key1.hash_key * Key2.hash_key * 'a) -> unit
-
insert tbl (key1, key2, item)
inserts a mappings fromkey1
andkey2
toitem
intotbl
. Any existing mapping of the keys is discarded. val inDomain1 : 'a hash_table -> Key1.hash_key -> bool
-
inDomain1 tbl key
returnstrue
if, and only if,key
is in the first domain of the table val inDomain2 : 'a hash_table -> Key2.hash_key -> bool
-
inDomain2 tbl key
returnstrue
if, and only if,key
is in the second domain of the table
val lookup1 : 'a hash_table -> Key1.hash_key -> 'a
-
lookup1 tbl key
returns the item thatkey
maps to ifkey
is in the first mapping oftbl
. Otherwise, the table’s exception is raised.
val lookup2 : 'a hash_table -> Key2.hash_key -> 'a
-
lookup2 tbl key
returns the item thatkey
maps to ifkey
is in the second mapping oftbl
. Otherwise, the table’s exception is raised. val find1 : 'a hash_table -> Key1.hash_key -> 'a option
-
find1 tbl key
returns theSOME v
ifkey
is in the first domain oftbl
and is mapped tov
. Otherwise, it returnsNONE
. val find2 : 'a hash_table -> Key2.hash_key -> 'a option
-
find2 tbl key
returns theSOME v
ifkey
is in the second domain oftbl
and is mapped tov
. Otherwise, it returnsNONE
.
val remove1 : 'a hash_table -> Key1.hash_key -> 'a
-
remove1 tbl key1
returns the item thatkey1
maps to ifkey1
is in the first mapping oftbl
. Furthermore, if the item was inserted with keyskey1
andkey2
, thenkey1
is removed from the first mapping andkey2
is removed from the second mapping. Ifkey1
is not in the first domain of the table, then the table’s exception is raised.
val remove2 : 'a hash_table -> Key2.hash_key -> 'a
-
remove2 tbl key2
returns the item thatkey2
maps to ifkey2
is in the second mapping oftbl
. Furthermore, if the item was inserted with keyskey1
andkey2
, thenkey1
is removed from the first mapping andkey2
is removed from the second mapping. Ifkey2
is not in the second domain of the table, then the table’s exception is raised. val numItems : 'a hash_table -> int
-
numItems tbl
returns the number of entries in the table. val listItems : 'a hash_table -> 'a list
-
listItems tbl
returns a list of the items in the range oftbl
. val listItemsi : 'a hash_table -> (Key1.hash_key * Key2.hash_key * 'a) list
-
listItemsi tbl
returns a list of the(key1, key2, item)
triples that are intbl
. val app : ('a -> unit) -> 'a hash_table -> unit
-
app f tbl
applies the functionf
to each item intbl
. val appi : ((Key1.hash_key * Key2.hash_key * 'a) -> unit) -> 'a hash_table
-
appi f tbl
applies the functionf
to each(key1, key2, item)
triple intbl
. val map : ('a -> 'b) -> 'a hash_table -> 'b hash_table
-
map f tbl
creates a new table with an entry(key1, key2, f item)
in the new table for every(key1, key2, item)
triple intbl
. The exception for the new table is copied fromtbl
. val mapi : ((Key1.hash_key * Key2.hash_key * 'a) -> 'b) -> 'a hash_table -> 'b hash_table
-
mapi f tbl
creates a new table with an entry(key1, key2, f(key1, key2, item))
in the new table for every(key1, key2, item)
triple intbl
. The exception for the new table is copied fromtbl
. val fold : (('a * 'b) -> 'b) -> 'b -> 'a hash_table -> 'b
-
fold f init tbl
folds the functionf
over the items in the range oftbl
usinginit
as an initial value. val foldi : ((Key1.hash_key * Key2.hash_key * 'a * 'b) -> 'b) -> 'b -> 'a hash_table -> 'b
-
foldi f init tbl
folds the functionf
over the(key1, key2, item)
triples intbl
usinginit
as an initial value. val filter : ('a -> bool) -> 'a hash_table -> unit
-
filter pred tbl
removes any entry(key1, key2, item)
fromtbl
for whichpred item
returnsfalse
. val filteri : ((Key1.hash_key * Key2.hash_key * 'a) -> bool) -> 'a hash_table -> unit
-
filteri pred tbl
removes any entry(key1, key2, item)
fromtbl
for whichpred(key1, key2, item)
returnsfalse
. val copy : 'a hash_table -> 'a hash_table
-
copy tbl
creates a copy oftbl
. This expression is equivalent tomap (fn x => x) tbl
val bucketSizes : 'a hash_table -> (int list * int list)
-
bucketSizes tbl
returns a list of the current number of items per bucket for each of the tables. This function allows users to gauge the quality of their hashing functions.