"OrderedHashTable" (Data Structure)
"OrderedHashTable"
represents a hash table where the keys and values are general expressions and the order in which keys are inserted is preserved.
Details


- An ordered hash table is useful for storing individual values that can be retrieved by use of a key where it is important to preserve the order of insertion:
-
CreateDataStructure["OrderedHashTable"] create a new empty "OrderedHashTable" CreateDataStructure["OrderedHashTable",assoc] create a new "OrderedHashTable" containing the rules from assoc Typed[x,"OrderedHashTable"] give x the type "OrderedHashTable" - For a data structure of type "OrderedHashTable", 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)Summary of the most common use cases
A new "OrderedHashTable" can be created with CreateDataStructure:
In[1]:=1

✖
https://wolfram.com/xid/0b5m6os2ktjlyg95rs0yk8nbnyya-ck3oom
Out[1]=1

In[2]:=2

✖
https://wolfram.com/xid/0b5m6os2ktjlyg95rs0yk8nbnyya-84r1md
In[3]:=3

✖
https://wolfram.com/xid/0b5m6os2ktjlyg95rs0yk8nbnyya-tnm4iz
Out[3]=3

In[4]:=4

✖
https://wolfram.com/xid/0b5m6os2ktjlyg95rs0yk8nbnyya-kfcutb
Out[4]=4

In[5]:=5

✖
https://wolfram.com/xid/0b5m6os2ktjlyg95rs0yk8nbnyya-2ymbbr
Out[5]=5

When a key is not found, a Missing object is returned:
In[6]:=6

✖
https://wolfram.com/xid/0b5m6os2ktjlyg95rs0yk8nbnyya-3dkxgf
Out[6]=6

Return an expression version of ds:
In[7]:=7

✖
https://wolfram.com/xid/0b5m6os2ktjlyg95rs0yk8nbnyya-dbekgb
Out[7]=7

A visualization of the data structure can be generated:
In[1]:=1

✖
https://wolfram.com/xid/0b5m6os2ktjlyg95rs0yk8nbnyya-mfljzp
Out[1]=1

The order of insertions is preserved:
In[2]:=2

✖
https://wolfram.com/xid/0b5m6os2ktjlyg95rs0yk8nbnyya-mancrg
Out[2]=2

Scope (1)Survey of the scope of standard use cases
Information (1)
A new "OrderedHashTable" can be created with CreateDataStructure:
In[1]:=1

✖
https://wolfram.com/xid/0b5m6os2ktjlyg95rs0yk8nbnyya-j0wiym
Out[1]=1

Information about the data structure ds:
In[2]:=2

✖
https://wolfram.com/xid/0b5m6os2ktjlyg95rs0yk8nbnyya-5du3om
Out[2]=2
