mapdb
mapdb copied to clipboard
Use case about Map having Sets as values
I'm trying to refactor an application that uses a lot of Map<K, Set<V>>
data stores in memory, ie, keeps indices of multiple values per key. I'd like to move all those data to disk, but I'm having issues.
Initially, I've tried to DB.hashSet()
to get new values for keys that haven't yet, so the attempt was to have a HTreeMap
of HTreeSet
(s). But I've soon discovered that HTreeMap
isn't serialisable (as per #837).
So, now I'm thinking of writing a Map
wrapper that is backed by an HTreeSet<String>
, where the latter will contain names for HTreeSets
kept by MapDB, ie, whenever needed, the implementation would get the name of a set that is associated to a key (assuming such names are created via some 1-1 association to the keys) and use that to fetch the corresponding set from DB.hashSet( <name> )
.
Does this make sense? Would it be performant enough?
Moreover, since I'm going to have many mutable keys, I would also need to be able to remove a given MapDB set when the corresponding key is removed. Unfortunately, it seems that there is no way to do so in MapDB anymore, or am I missing something about this?
Thanks in advance for any help.