How to implement a multi-index dictionary?

前端 未结 11 1490
孤独总比滥情好
孤独总比滥情好 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:27

    Two dictionaries, but don't duplicate the items in each.

    You'll have a value dictionary, and a key dictionary.

    When you call your add method, you'll generate a GUID and add it and the key to the keys dictionary.

    Then, use the GUID as a key to the values dictionary.

    If you want to add two keys, you'll add another item to the keys dictionary with the same GUID.

    Of course this means every lookup requires two checks for the data, but never more, even if you have 50 keys for the same value.

    Lookup the guid based on the key from the keys table, then lookup the data based on that guid in the values table.

提交回复
热议问题