Map of Maps data structure

后端 未结 3 2050
萌比男神i
萌比男神i 2020-12-11 16:53

The MultiValueMap class (Apache commons collections) makes it easy to work with a Map whose values are Collections. I\'m looking for a a class that makes it easy to work wit

3条回答
  •  -上瘾入骨i
    2020-12-11 17:06

    If you've got a map:{string,map:{string,thing}} (deliberately not using Java syntax to avoid the whole Java1.4/Java5 business) then you should also consider whether you should instead model that as map:{tuple:{string,string},thing}. If multi-level lookups dominate, then that's a good change to make (provided you implement a good tuple that does equals() correctly and hashCode() intelligently) but if you are doing a lot of inserts and deletes then it's less good.

    Intelligence in hashCode probably means just coming up with a reasonable way to mix the bits from the hashCodes of the contents together. If the member values are expected to be from disjoint sets (e.g., names and occupations) then you can just XOR them together – imperfect, but cheap and fast – but if you've less control/certainty then you need to do something else as well (e.g., rotate the bits of one of the values prior to the XOR).

提交回复
热议问题