Data structure for partial multi-keys mapping?

前端 未结 3 1569
小鲜肉
小鲜肉 2021-02-06 08:52

I have data consists of keys mapped to values, like this:

---------------------
Key          | Value
---------------------
(0, 0, 0, 0) | a
(0, 0, 0, 1) | b
(0,          


        
3条回答
  •  离开以前
    2021-02-06 09:22

    if there exist a maximum(M) value for each part of the keys, you can create a single keyed tree by interpreting the keys as numbers written in base M (or in mixed base)

    • i assume wildcards only appear at one index and all furter are wildcards, this way (x,*,*,*) will be a query for (x*M^3,(x+1)*M^3-1)

    for strings:

    • you can use a separating character and token paste the keys (using |:

    ('ax','bc','a','x') -> 'ax|bc|a|x'

    the separator should not appear in the input strings(it may appear, but in that case it may interfere with accessing the asked results)

    but...if your situation is difficult you can use objects as keys, in java i would create a class for the key, and define a compare oparator between them

    for examples i would quote: How to compare objects by multiple fields

提交回复
热议问题