A typeclass for hash tables in the ST monad. The operations on these hash tables are typically both key- and value-strict.
Methods
new :: ST s (h s k v)Creates a new, default-sized hash table. O(1).
newSized :: Int -> ST s (h s k v)Creates a new hash table sized to hold
nelements. O(n).mutate :: (Eq k, Hashable k) => h s k v -> k -> (Maybe v -> (Maybe v, a)) -> ST s aGeneralized update. Given a key k, and a user function f, calls:
`f Nothing` if the key did not exist in the hash table
`f (Just v)` otherwise
If the user function returns
(Nothing, _), then the value is deleted from the hash table. Otherwise the mapping for k is inserted or replaced with the provided value.Returns the second part of the tuple returned by f.
mutateST :: (Eq k, Hashable k) => h s k v -> k -> (Maybe v -> ST s (Maybe v, a)) -> ST s aAs mutate, except that the action can perform additional side effects.
insert :: (Eq k, Hashable k) => h s k v -> k -> v -> ST s ()Inserts a key/value mapping into a hash table, replacing any existing mapping for that key.
O(n) worst case, O(1) amortized.
delete :: (Eq k, Hashable k) => h s k v -> k -> ST s ()Deletes a key-value mapping from a hash table. O(n) worst case, O(1) amortized.
lookup :: (Eq k, Hashable k) => h s k v -> k -> ST s (Maybe v)Looks up a key-value mapping in a hash table. O(n) worst case, (O(1) for cuckoo hash), O(1) amortized.
foldM :: (a -> (k, v) -> ST s a) -> a -> h s k v -> ST s aA strict fold over the key-value records of a hash table in the ST monad. O(n).
mapM_ :: ((k, v) -> ST s b) -> h s k v -> ST s ()A side-effecting map over the key-value records of a hash table. O(n).
lookupIndex :: (Eq k, Hashable k) => h s k v -> k -> ST s (Maybe Word)Looks up the index of a key-value mapping in a hash table suitable for passing to nextByIndex.
nextByIndex :: h s k v -> Word -> ST s (Maybe (Word, k, v))Returns the next key-value mapping stored at the given index or at a greater index. The index, key, and value of the next record are returned.
computeOverhead :: h s k v -> ST s DoubleComputes the overhead (in words) per key-value mapping. Used for debugging, etc; time complexity depends on the underlying hash table implementation. O(n).