Jump to content
  • Advertisement
Sign in to follow this  
SeiryuEnder

Simple Lookup Equation

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!