3

I am looking for a map-like data structure with the following properties:

  • it uses subsets of some set S as keys. The size of S is potentially unbounded, but does not change during the runtime
  • the values associated with the keys are generic objects - poiters/references. Their properties are not important for the data structure
  • the size of the subsets, used as keys, can vary between keys, i.e. one key can be a 3 element subset, while another might be a 7 element subset
  • it must support insertion of new entries (key - value pairs) into the "map"
  • it does not need to support removal of entries from the "map"
  • if I have some subset B of S and want to get a value from the map using B, I want the following:
    • find the largest key (the key with the larges cardinality) in the map that is a subset of B, and return it along with the value associated with it
    • if B itself is a key in the map, I want to return the entry for B
    • if there are multiple keys that satisfy this condition, I don't care which one gets returned
    • if there are multiple keys that satisfy this condition, I don't care if a different one is returned for consecutive read operations
  • if neccessary, I can guarantee that the entries with the atoms (one element subsets of S) as keys are always present in the map

My understanding is, that the keys form a partially ordered set based on set inclusion, and the read opperation is to find some sort of an infimum.

I looked at the disjoint-set (union-find) data strcutrue, but as far as I understand, this is not what I am looking for.

I have also looked at other questions around here with similar keywords, but could not find anything that would fit my requirements:

Any help is greatly appriciated. Doubly so, if I would be pointed in the dirrection of a javascript/typescript implementation of the data structure.

Minop
  • 131
  • 3
  • What do you mean by "insertion and reading of elements", and how does that relate to the sets that are the keys currently stored in the data structure? – D.W. Mar 23 '23 at 18:57
  • What do you mean by "largest" key? Largest by what metric? Meaning the subset of B whose cardinality is largest? Or that maps to the largest value? Or something else? – D.W. Mar 23 '23 at 18:58
  • 1
    Take a look at these: https://cs.stackexchange.com/q/75915/755, https://cs.stackexchange.com/q/74833/755, https://cs.stackexchange.com/q/109399/755, https://cs.stackexchange.com/q/156831/755, https://cs.stackexchange.com/q/7701/755, https://cs.stackexchange.com/q/39976/755, https://cs.stackexchange.com/q/70405/755. That's probably about as good as you're going to get, without further information about your workload (sizes of sets, number of sets, number of subsets for any one lookup, etc.) – D.W. Mar 23 '23 at 19:03
  • @D.W. thank you for the links! I will look trough them and post an update, should I have more questions – Minop Mar 24 '23 at 12:21
  • @D.W. I went over the links you posted and found something in https://cs.stackexchange.com/q/39976/159434. The answer https://cs.stackexchange.com/a/40004/159434 links to a paper from Savnik (https://osebje.famnit.upr.si/~savnik/papers/cdares13.pdf), that describes a set-trie datastructure, that can be adapted to my needs. Thank you for the help! – Minop Mar 27 '23 at 11:10

0 Answers0