I have buckets whose size is exponentially increasing by 2. So, the buckets are:
(0-1], (1-2], (2-4], (4-8], (8-16]...
.
Given a number, how can I efficiently tell which bucket index it falls in? One option I can think of is to use log2(N)
and round it up to the next integer. But can a simple mathematical formula be derived that will be faster than using log in C++
? This will be called in a very latency sensitive path so even microseconds matter.