I have variable-length lists, where each element can be one of four unique ones that I need to use as keys for another object on the map. Suppose that each value can be either 0, 1, 2, or 3 (it is not an integer in my real code, but it is much easier to explain this way), so some examples of key lists could be:
[1, 0, 2, 3] [3, 2, 1] [1, 0, 0, 1, 1, 3] [2, 3, 1, 1, 2] [1, 2]
So, for repeated iteration: each element in the list can be either 0, 1, 2 or 3, and there can be any number of elements in the list.
My first approach was to try to hash the contents of the array using the built-in GetHashCode () in .NET to combine the hash of each element. But since this will return an int, I will have to deal with collisions manually (two identical int values ββare identical to a dictionary).
So, my second approach was to use a square tree, breaking each item in the list into Node, which has four pointers (one for each possible value) to the following four possible values ββ(with Node root representing [] , an empty list), the insert [1, 0, 2] => Foo , [1, 3] => Bar and [1, 0] => Baz in this tree will look like this:
Square tree diagram http://episerversucks.com/upload/Diagram1111.png
Gray node nodes are unused pointers / nodes. Although I worry about the performance of this installation, there will be no need to deal with hash collisions and the tree will not become deep (basically there will be lists with 2-6 stored items, rarely more than 6).
Is there another magic way to store items with lists of values ββas missing keys?