Is there any way that I can mathematically determine a unique index number for 2D points that increases the further away I get from the origin? I do not know how far out that this coordinate system extends to.
I am working on a system where I need random access to data indexed by a 2D point.
In other words, I need a function that will always return a unique integer given the same two integers, but not conflict with other sets of numbers. Think of it like a hash. However, I need the indices generated to increase as the distance from the origin increases - this is so that my index growth remains constant as I add more data.
EDIT:
Here is some procedurally generated data that would work as a solution. I simply need a function that I can execute in constant time that produces something to the effect of:
0, 0 = 0
-1, 0 = 1
0, -1 = 2
0, 1 = 3
1, 0 = 4
-1, -1 = 5
-1, 1 = 6
1, -1 = 7
1, 1 = 8
-2, 0 = 9
0, -2 = 10
0, 2 = 11
2, 0 = 12
-2, -1 = 13
-2, 1 = 14
-1, -2 = 15
-1, 2 = 16
1, -2 = 17
1, 2 = 18
2, -1 = 19
2, 1 = 20
-2, -2 = 21
-2, 2 = 22
2, -2 = 23
2, 2 = 24
-3, 0 = 25
0, -3 = 26
-3, -1 = 27
-3, 1 = 28
-1, -3 = 29
1, -3 = 30
-3, -2 = 31
-3, 2 = 32
-2, -3 = 33
2, -3 = 34
-3, -3 = 35