3

I would like a "symbol alphabet" to have a bi-directional map with weak/soft references. Something like an Apache's Common BidiMap (or Guava's BiMap) with a WeakMap-like interface.

A solution would be to use BiMap<WeakReference<K>,V> and once in a while clean-up entries, but it's not optimal. Any suggestions?

miltos
  • 89
  • 1
  • 6
  • Doable, but your proposed solution isn't really a solution at all, because you can't look up a `K` in a map of `WeakReference`. – Louis Wasserman Dec 23 '12 at 16:16
  • If you filed a feature request with Guava with more explanation of why you actually want such a structure, that might also help. – Louis Wasserman Dec 23 '12 at 16:38
  • Yes, you're right about the 'BiMap,V>'. I dropped that solution. I have now implemented something on the 'AbstractDualBidiMap' of Apache commons (with two 'ReferenceMaps') but I am still testing it to see if it works as expected. Thanks – miltos Dec 23 '12 at 23:50

1 Answers1

3

If you're up for building a custom implementation, almost certainly the right way to do it will be to build your own custom hash table and maintain a ReferenceQueue that's used to track removals.

Louis Wasserman
  • 191,574
  • 25
  • 345
  • 413