What is the best method to create a two-dimensional grid of objects that can extend dynamically in any direction, without allocating memory in the empty parts of concave shapes?
I was thinking of having the class contain data members that pointed toward the adjacent objects (one for North, East, South, and West), but this doesn’t seem like it would be the best method, and it also lacks the ability to refer to a certain square with an absolute value (i.e. (6,-5)).
If the question seems confusing ask and I’ll try to explain the problem better.
Just throwing an idea out here:
Take a key/value container, say
std::map, or a self-balancing binary-search tree or similar.Use a 64 bit integer as the key. Use the high 32 bits as an X coordinate, the low 32 bits as a Y coordinate. Thus to find point
(x, y)you look up(((uint64_t)x) << 32) | y.