Need a data structure convenient for caching to store letter neighbors in a 2d array

Suppose the 2d array we are working on

abcd efgh ijkl mnop 

The closest neighbor is 'f' [abceg i jk]. I am trying to create a cache friendly data structure to store a node neighbor. Right now i have something like this

 struct Neighbor{ size_t neighborPosition[8][2]; size_t size; }; typedef size_t Position[2]; typedef Neighbor** NeighborTable; 

Note that the maximum neighbor of a node can have a value of 8. Does anyone have any tips? I need a structure to be a constant search for neighbors in the neighborhood, so I will pre-compute the neighbor of each node.

+4
source share
1 answer

Each cell has the same neighbors in its relative location, with the exception of rib cells. But if you add a border (an additional row and column at the beginning and at the end) and fill it with a value that lets you know that it is a border, you do not need any data structure to identify neighbors.

+5
source

Source: https://habr.com/ru/post/1396080/


All Articles