Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

infinite array in c++

Name: cvtc user 2006-02-25 1:24

i need help making an infinite two dimensional array in c++, in other words, i have no clue how to do it....

can anyone help?

Name: etatoby 2006-03-09 17:53

WTF, am I the only one who understood the OP?
Seriously, these forums are turning to deeper and deeper shit every day.

OP: get a single integer index (i) from the two indices you have in your algorithm (x,y) such that it is a bijection (ie., for every (x,y) there exists only one (i) and vice-versa.) The simplest formula that comes to my mind is:

i = (x+y)*(x+y+1)/2+y

It's based on the same idea as that famous proof that the rationals are coutable (http://fyad.org/bl4y) and yes, that division right there is integer safe (x+y and x+y+1 are adjacent naturals, so one of them is even :-)

Then use that single index (i) as a key in a hash table. Use a good hash table, one that grows as the dataset grows, and you'll be allright.

For bonus points you could use bignums (=integers only limited by the available RAM) instead of plain ints for all the indices and their math, then you'd have a really infinite matrix!

To the trolls who are reading this, 'infinite' in CS means 'only limited by the available RAM', instead of by arbitrary limits (as the ±2 billion limit for common ints.)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List