I'm looking for an equivalent
WeakHashMap<K, V>
except that it maps multiple keys to a value, so it looks more like
WeakHashMap<K1, K2, V> WeakHashMap<K1, K2, K3, V> etc.
The write way get and set will look like a primary key with several columns in the database: you put elements using several keys, for example. (K1, K2) , and to return this element, you need to provide all the same keys that you used to enter it. Given these semantics of get and set , the semantics of GC will be: the record will be GCed if there is no longer access, which means that any of its keys is no longer available.
Has anyone else needed something similar before? How do you approach this requirement? Storing a tuple as a key, as you could do in a weak HashMap, does not work (Tuple receives GCed almost immediately, and no one points to it).
If something like this was done before I was happy to use it, but just try to think about how I would build such a thing from WeakReferences and a regular hash map, and I would come up with a space.
source share