Most efficient way to use a 3d vector as HashMap Key?

Hi,
I want to be able to access arrays by a 3d vector. I want to use a HashMap to store the 3d vector as Key and the array as value.

What is the most efficient way to use a 3d vector as Hash Key? Just use the array with the three coordinates? Combine the three values into one i64?

The coordinates will be three i16 integers, no floats. Any suggestions?

If you're wondering about the performance of hashing [i16; 3] versus i64, you're seriously thinking too much about this. Both are going to shove a bunch of bytes into a hasher. Maybe the array is faster because it's fewer bytes. Maybe i64 is faster because... I dunno, something something alignment. Who knows?

Profile your program first to find out whether this hashing is actually performance critical. And if it is, then benchmark each of the alternatives.

You'll probably get a much bigger speedup by swapping the hasher out with e.g. FNV.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.