I want to assign every a Integer a unique pair of Integers. My first thought was to use a spiral, or to put it visually:
25 10 11 12 13 (-2, 2) (-1, 2) ( 0, 2) ( 1, 2) ( 2, 2)
24 9 2 3 14 (-2, 1) (-1, 1) ( 0, 1) ( 1, 1) ( 2, 1)
23 8 1 4 15 --> (-2, 0) (-1, 0) ( 0, 0) ( 1, 0) ( 2, 0)
22 7 6 5 16 (-2,-1) (-1,-1) ( 0,-1) ( 1,-1) ( 2,-1)
21 20 19 18 17 (-2,-2) (-1,-2) ( 0,-2) ( 1,-2) ( 2,-2)
or
X Y
------------
|1 |( 0, 0)
------------
|2 |( 0, 1)
------------
|3 |( 1, 1)
------------
|4 |( 1, 0)
------------
|5 |( 1,-1)
------------
|6 |( 0,-1)
------------
|7 |(-1,-1)
------------
|8 |(-1, 0)
------------
|9 |(-1, 1)
------------
|10|(-1, 2)
------------
|11|( 0, 2)
------------
|12|( 1, 2)
------------
but I am not sure how to implement an efficient function that takes a pair and return it's corresponding value, or even if this is the most efficient pattern to use. I heard that Hilbert curves are used for mapping n dimensional things to lines but I am not sure if that is applicable.