Assume the following is a 2d array that we are operating on
a b c d
e f g h
i j k l
m n o p
The surrounding neighbor of 'f' are [a b c e g i j k]. I'm trying to create a cache friendly data structure to store the neighbor of a node. Right now I have something like so
struct Neighbor{
size_t neighborPosition[8][2];
size_t size;
};
typedef size_t Position[2];
typedef Neighbor** NeighborTable;
Note that the max neighbor a node could have is 8. Anyone have any advice? I need the structure to be a constant time neighbor lookup so I will be pre-calculating the neighbor of each node.
Every cell has the same neighbors, in terms of their relative location, except for the edge cells. But if you add a border (an extra row & column at the start and end), and fill it with a value that lets you know it is a border, the you don't need any data structure at all to identify neighbors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With