# Simple Lookup Equation

This topic is 2805 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

The problem is pretty simple I think, for some reason I'm just not sure how to approach it.
I've written a container similar to a deque which resizes similar to std::vector (newSize = oldSize*2 + 1).
I want to make my lookup time O(N).

I need to be able to determine my chunk and chunk sub-index.
For instance, if I look up Container1[4] I would find chunk 1 sub-index 2, and Container2[4]
would find chunk 0 sub-index 4.

 [Container] [CHUNK] [ELEMENTS] Container1 0 1 2 3 4 5 6 7 1 3 7 15 31 63 127 255 Container2 0 1 2 3 4 5 6 7 5 11 23 47 95 191 383 767 

It is also important to note that the initial chunk size is arbitrary.

I'm a little embarrassed to ask such a simple math question, but I have been stuck on this one.
Thanks in advance for any help!

##### Share on other sites
I seem to have accidentally doubleposted this.

Until a moderator can delete this thread, please refer to this one.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 11
• 23
• 42
• 75