I've created a data structure that is a hash of arrays with a special property: the hash keeps track of the combined order in which items are appended to its arrays.
For example (pseudocode):
h = HashOfArray()
h["a"].append(1) // accessing an unset key returns an empty array
h["b"].append(2)
h["a"].append(3)
h["b"].append(4)
h["a"]
>>> [1, 3]
h["b"]
>>> [2, 4]
h.items()
>>> [1, 2, 3, 4]
I'm struggling with coming up with a good name for this data structure. Does it have a commonly used name? I've called it HashOfArray
but that fails to convey its main property: that it maintains the combined append order of the arrays.
Example implementation in Ruby: https://gist.github.com/kajic/7981533
parent
array, and insert into in whenever you insert into a child... $\endgroup$parent
variable is a reference to the parent hash which contains the arrays. Every time an object is appended to any one of the hashes, a reference to the object is also appended to the items array on the parent. The items array therefore has the combined append order of the objects inserted into all the arrays. $\endgroup$