I have a small set of positive integers (roughly 10 numbers), each of which is a power of two.
How can I map each number to some other number as quickly as possible?
Here are two solutions that would work but, considering the simplicity of the problem (and how few keys I have), they both seem needlessly sluggish (am I wrong?):
- Use a
std::map
- Compute the log-base-2 of the key (7 operations for 32-bit numbers, 9 for 64-bit) and then use this to lookup the corresponding value in an array
Avoiding the mapping problem altogether by, e.g., replacing my integers with a struct that carries the pairs together would probably be the fastest solution but it would complicate much of my code, so I'm not willing to do this.