I am blanking right now, is there any faster way of retrieving an item from an array by the value of one of its properties than simply iterating through each value and checking?
ie:
foreach(Something s in collection){
if(s.value == valueToCheckAgainst)
return s;
}
Mainly concerned because said collection could be quite large. Order is not guaranteed (specifically, this is dealing with a ComponentDataArray in Unity ECS)
@lyon Since we’re talking about spatial data and I _think_ you’re trying to generalize this outside of storing the entire 2D grid, a quadtree is probably what you’re looking for: https://en.m.wikipedia.org/wiki/Quadtree
Some other possible approaches here are B+ trees (for entity-relational data) or applying a Bloom filter to the entire set if it is very large. If your grid is very small, using a hash approach like you mention is also optimal.
@lyon No prob!
@Goldkin this is incredibly helpful, thank you so much!