How to implement a multi-index dictionary?

前端 未结 11 1483
孤独总比滥情好
孤独总比滥情好 2020-12-14 00:32

Basically I want something like Dictionary, but not (as I\'ve seen here in other question) with the keys in AND, but in OR. To better explain: I

11条回答
  •  星月不相逢
    2020-12-14 01:24

    Maybe an option:

    Do as John Kugelman suggests, just add an item twice in the same dictionary. Then you keep a second dictionary that maps values to sets of keys.

    When you add a key,value pair, you just add it as normal to the first dictionary and then retrieve the key set belonging to that value from the second dictionary and add the key.

    Dictionary dict1;
    Dictionary> dict2;

    Removing a value is done by retrieving the key set from dict2 and removing them one by one from dict1.

    The number of keys is dict1.Count and the number of values is dict2.Count

提交回复
热议问题