JavaScript ES6 introduced Map
implemented with hash table. Since hash table look up time is on average O(1), for random accessed data, Map
seems to be a good choice for data storage.
However, JavaScript does not have data structures like struct
in C++ that can be used as keys in the Map to enable "multiple keys mapping". The closest ones are Objects, but their instances do not equal to each other even if "contents are the same".
If I want to save a 2D or 3D tile based game map using the Map
type, is there a way to easily access the blocks given the coordinates? Of course strings like "1,2,3"
(representing x,y,z) would work, but is there a way that we can use integers as keys?
And if I must fall back to using assembled string coordinates, would the performance decrease a lot?
EDIT: I want to use a hash table because there may be "holes" in the maps and tiles may be created randomly in the middle of nowhere.