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 leastnitems. The exceptionexis 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 tblremoves 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 fromkey1andkey2toitemintotbl. Any existing mapping of the keys is discarded. val inDomain1 : 'a hash_table -> Key1.hash_key -> bool-
inDomain1 tbl keyreturnstrueif, and only if,keyis in the first domain of the table val inDomain2 : 'a hash_table -> Key2.hash_key -> bool-
inDomain2 tbl keyreturnstrueif, and only if,keyis in the second domain of the table
val lookup1 : 'a hash_table -> Key1.hash_key -> 'a-
lookup1 tbl keyreturns the item thatkeymaps to ifkeyis in the first mapping oftbl. Otherwise, the table’s exception is raised.
val lookup2 : 'a hash_table -> Key2.hash_key -> 'a-
lookup2 tbl keyreturns the item thatkeymaps to ifkeyis in the second mapping oftbl. Otherwise, the table’s exception is raised. val find1 : 'a hash_table -> Key1.hash_key -> 'a option-
find1 tbl keyreturns theSOME vifkeyis in the first domain oftbland is mapped tov. Otherwise, it returnsNONE. val find2 : 'a hash_table -> Key2.hash_key -> 'a option-
find2 tbl keyreturns theSOME vifkeyis in the second domain oftbland is mapped tov. Otherwise, it returnsNONE.
val remove1 : 'a hash_table -> Key1.hash_key -> 'a-
remove1 tbl key1returns the item thatkey1maps to ifkey1is in the first mapping oftbl. Furthermore, if the item was inserted with keyskey1andkey2, thenkey1is removed from the first mapping andkey2is removed from the second mapping. Ifkey1is 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 key2returns the item thatkey2maps to ifkey2is in the second mapping oftbl. Furthermore, if the item was inserted with keyskey1andkey2, thenkey1is removed from the first mapping andkey2is removed from the second mapping. Ifkey2is not in the second domain of the table, then the table’s exception is raised. val numItems : 'a hash_table -> int-
numItems tblreturns the number of entries in the table. val listItems : 'a hash_table -> 'a list-
listItems tblreturns a list of the items in the range oftbl. val listItemsi : 'a hash_table -> (Key1.hash_key * Key2.hash_key * 'a) list-
listItemsi tblreturns a list of the(key1, key2, item)triples that are intbl. val app : ('a -> unit) -> 'a hash_table -> unit-
app f tblapplies the functionfto each item intbl. val appi : ((Key1.hash_key * Key2.hash_key * 'a) -> unit) -> 'a hash_table-
appi f tblapplies the functionfto each(key1, key2, item)triple intbl. val map : ('a -> 'b) -> 'a hash_table -> 'b hash_table-
map f tblcreates 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 tblcreates 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 tblfolds the functionfover the items in the range oftblusinginitas an initial value. val foldi : ((Key1.hash_key * Key2.hash_key * 'a * 'b) -> 'b) -> 'b -> 'a hash_table -> 'b-
foldi f init tblfolds the functionfover the(key1, key2, item)triples intblusinginitas an initial value. val filter : ('a -> bool) -> 'a hash_table -> unit-
filter pred tblremoves any entry(key1, key2, item)fromtblfor whichpred itemreturnsfalse. val filteri : ((Key1.hash_key * Key2.hash_key * 'a) -> bool) -> 'a hash_table -> unit-
filteri pred tblremoves any entry(key1, key2, item)fromtblfor whichpred(key1, key2, item)returnsfalse. val copy : 'a hash_table -> 'a hash_table-
copy tblcreates a copy oftbl. This expression is equivalent tomap (fn x => x) tbl val bucketSizes : 'a hash_table -> (int list * int list)-
bucketSizes tblreturns 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.