Wish Multi key list

Troberg

Well-Known Member
Licensed User
Longtime User
A construct I quite often would find useful is a multi key list, ie the ability to have multiple keys for each item. Sure, it can be done by using several lists and object references, but it is non-trivial work and quite error prone before you get it right.

For example, I'm currently fiddling around with a program to generate mazes. For that, I need a list of walls, and I need to be able to quickly search them by each end point coordinate (each wall has two ends).
 

Troberg

Well-Known Member
Licensed User
Longtime User
Sorry, I was thinking about a map, but somehow my brain misconnected.

Still, a map can only have one key.

In my current case, I'd like something like this:

Type Walls(StartCoord as string, EndCoord as string, Status as Boolean)

Then, I want to add a bunch of those to a map with both StartCoord and EndCoord as keys, so I'm able to quickly get all walls that has a certain coord as either end point.

It would also be very useful in various database shells where you convert a data set to objects.

Another typical use case is bi-directional translation/mapping tables.

Sure, I could loop through all objects in the map, but that's slow and makes for less neat code. Sure, I could have two maps, where one only holds object references to the other, but that makes for even less neat code.

I'm not saying it can't be done, just that it would be much neater if the tool handled this fairly common case.
 

Informatix

Expert
Licensed User
Longtime User
A possible solution is two create two maps with one pointing on the other:
Dim M1 As Map
Dim M2 As Map
Key of M1 = first index
Value of M1 = value
Key of M2 = second index
Value of M2 = Key of M1 (so you update only the first map when the value changes)

With this solution, you can create as many indexes as you wish. The value of additional maps is always the key of M1.
 
Top