RE: https://chaos.social/@icing/116974866632587241 We used to use arrays of bits...

@pozorvlak@mathstodon.xyz

RE: chaos.social/@icing/1169748666

We used to use arrays of bitsets at Continuum to represent which types of geographic feature (roads, buildings, forests, sites of special scientific interest...) were present within each grid square in the area of interest. Here's the neat thing: if the size of the array is limited, you can do this with arbitrary-sized sets. The surface area of the Earth is 510,072,000 km², or 566,746,666,667 30m × 30m grid squares; that means there are at most 566,746,666,667 possible combinations of layers in the dataset, which fits into 40 bits. Create a lookup table of all the combinations that actually occur (as bigints), and a uint64 array of indices into that table. But usually you can use a much smaller index type, because many fewer combinations of layers actually occur - usually only a few thousand. For a more realistic 100km × 100km project area, you only need a maximum of 24 bits for the indices. Then, if you want to find out at which points a given layer (or union/intersection of layers!) is present, do the usual bitwise calculation *on the lookup table* to get a Boolean array of combination numbers -> whether the layers are present, and then use the index array to index into the Boolean array. If each layer carries a numeric penalty, you calculate a sum-of-penalties table from the lookup table, and then index right into that.