Background: In my project, I have a custom class called Tile representing a position in a grid. All these objects have a unique combination of coordinates, being X and Z.
As part of my work, I now have a collection of tiles, objects of type Tile. For all these tiles, I have to efficiently index them somewhere to be able to check if a tile is present in the collection. The complexity of that should be better than the linear complexity O(n) because I have to use all of this in a very time-critical environment. Memory usage is secondary.
Idea: From my studies, I know that trees are very efficient data structures for looking up something, as well as that hashing is something one can do to generate a pseudo-unique key, allowing to use something like Dictionary<TKey, TValue>.
Problem: My problem is, however, that I donât know how to hash a complex object to get a pseudo-unique key. I have seen it plenty of times for value types like bool, int and string, but now I have to objects, a coordinate in X space and a coordinate in Z space. How do I efficiently (!) generate a key from that? Something like $"{tile.x}_{tile.y}" is not performant enough and thus not an option.
My other problem concerns trees, if I do not use hashing and a dictionary. Since I have to coordinates, how do I index something into a binary search tree? I came up with something like MyBinaryTree<TValue, TNode> and MySimpleBinaryTree<TValue> and then combining these two into a field MyBinaryTree<int, MySimpleBinaryTree<int>> myLookUpStructure, with the first int being the X coordinate and the second int in the simple binary tree being the Z coordinate. However, not being very good with complexity, I think I would lose the O(log(n)) of a binary search tree if I do it like this.
Has someone a suggestion regarding my problem and how I could solve this? Should I use hashing and a dictionary or a binary search tree? How could I solve the problems being mentioned above?