"HashTable" (Data Structure)
"HashTable"
represents a hash table where the keys and values are general expressions.
Details
- A hash table is useful for storing individual values that can be retrieved by use of a key:
-
CreateDataStructure["HashTable"] create a new empty "HashTable" CreateDataStructure["HashTable",assoc] create a new "HashTable" containing the rules from assoc Typed[x,"HashTable"] give x the type "HashTable" - For a data structure of type "HashTable", the following operations can be used:
-
ds["Copy"] return a copy of ds time: O(n) ds["Elements"] return a list of the elements of ds time: O(n) ds["EmptyQ"] True, if ds has no elements time: O(1) ds["Insert",keyvalue] add key to ds with the associated value and return True if the addition succeeded time: O(1) ds["KeyDrop",key] drop key and its value from ds time: O(1) ds["KeyDropAll"] drop all the keys and their values from ds time: O(n) ds["KeyExistsQ",key] True, if the key exists in ds time: O(1) ds["Keys"] return the keys in ds as a list time: O(n) ds["Length"] the number of key-value pairs stored in ds time: O(1) ds["Lookup",key] return the value stored with key in ds; if the key is not found return a Missing object time: O(1) ds["Lookup",key,defFun] return the value stored with key in ds; if the key is not found return defFun[key] time: O(1) ds["Values"] return the values in ds as a list time: O(n) ds["Visualization"] return a visualization of ds time: O(n) - The following functions are also supported:
-
dsi===dsj True, if dsi equals dsj FullForm[ds] full form of ds Information[ds] information about ds InputForm[ds] input form of ds Normal[ds] convert ds to a normal expression
Examples
open allclose allBasic Examples (2)
A new "HashTable" can be created with CreateDataStructure:
When a key is not found, a Missing object is returned:
Scope (1)
Information (1)
A new "HashTable" can be created with CreateDataStructure: