So, basically, I’m making a custom mapping from a known - size Vec of usizes to a usize. e.g.:
[2, 3] maps to 5
[3, 4] maps to 3
[2, 4] maps to 9
etc. But it’s very sparse, most of the
Vec<usize> keys don’t have a value associated with them.
To make things simple, I’ll make the assumption that the Vec is of length 2 (but it can easily be extended to longer lenghts).
So, let’s say the input was this:
[2, 4] -> 2
[3, 5] -> 3
Then, for each “dimension” in the input, I get the maximum, so the maxima would be [3, 5]. Then, I convert each vector to an address (“flattening”), by multiplying each coordinate with it’s respective maxima (so the first one would have address 2 * 3 + 4 * 5 = 26). Then, I store the value for that key at that address in the Vec (so after processing the first line, the vec would be):
[<26 zeros>, 2, ]
So “2” is at address 26. The problem is that that was for mapping Vec to usize, now I have to map Vec<[usize; 16]> to [usize; 16]. I could extend the algorithm (I tried), but now the “map vector” has a few thousand zeroes. Definitely not a good use of memory. Now that I type it, however, it seems that that way is the only way to get the hash without getting collisions (2 different Vec<[usize; 16]>s getting the same “flattened” address). Any ideas?