Two-dimensional map
- Posted by SnakeCharmer Jan 31, 2013
- 1245 views
I need structure similar to two-dimensional array, but with text indexes. How to organize such map? For example, X-keys are employees and Y-keys are assets. Value is deprecation factor.
"John Smith", "Chair" --> 0.50 "John Smith", "Computer" --> 0.99 "Kevin Fogg", "Chair" --> 0.78 "Kevin Fogg", "Computer" --> 1.5 -- he updated software at own expense
I see almost tree ways:
1. Regular map, where each key is concatenated coordinates. So, I need use key User&Stuff. It isn't so silly. I don't need to break a line in the future.
put(Deprecation, "John SmithChair", 0.50) put(Deprecation, "John SmithComputer", 0.99) put(Deprecation, "Kevin FoggChair", 0.78) put(Deprecation, "Kevin FoggComputer", 1.5)
2. The similar way, but keys unite in sequence of lines, instead of in one line.
put(Deprecation, {"John Smith", "Chair"}, 0.50) put(Deprecation, {"John Smith", "Computer"}, 0.99) put(Deprecation, {"Kevin Fogg", "Chair"}, 0.78) put(Deprecation, {"Kevin Fogg", "Computer"}, 1.5)
3. Nested maps. In other words, map of maps. I suspect that this way is ideologically best. However it is the most difficult. I will accept also the first method. I need to thrust data to "cell of array" and then to get them, having both keys. Search all values with only one of keys, search key by value, or something similar isn't required to me. What way you will advise to me?