How to implement a multi-index dictionary?

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

    So you want a multi-index dictionary, supports lookups based on any key, and supports extensions to multiple keys?

    Maybe you're thinking of the wrong data structure, try a KD-Tree instead. An immutable KD-tree would satisfy the thread-safety requirement.

    KD-trees have some major advantages over the naive Dictionary{Key1, Dictionary{Key2, Value}} approach, namely that you can search for all fields based on Key2 without knowing Key1. Additionally, KD-trees allow you to search for keys which are near some other key. For example, dating sites classify people into dozens of groups (smoker/non-smoker, gender, religion, lifestyle, age, height), then return nearest neighbors based on your query.

    Here's a C# and Java implementation:

    http://home.wlu.edu/~levys/software/kd/ (broken link, archived at https://web.archive.org/web/20190609084214/http://home.wlu.edu/~levys/software/kd/)

提交回复
热议问题