3

Is there any Java library with TreeMap-like data structure which also supports all of these:

  • lookup by value (like Guava's BiMap)
  • possibility of non-unique keys as well as non unique values (like Guava's Multimap)
  • keeps track of sorted values as well as sorted keys

If it exists, it would probaby be called SortedBiTreeMultimap, or similar :)

This can be produced using a few data structures together, but I never took time to unite them in one nice class, so I was wondering if someone else has done it already.

Ognjen
  • 2,508
  • 2
  • 31
  • 47

1 Answers1

3

I think you are looking for a "Graph". You might be interested in this slightly similar question asked a while ago, as well as this discussion thread on BiMultimaps / Graphs. Google has a BiMultimap in its internal code base, but they haven't yet decided whether to open source it.

Community
  • 1
  • 1
Etienne Neveu
  • 12,604
  • 9
  • 36
  • 59
  • 1
    Thanks for an answer! Yes, a sort of graph... *graph* would be *BiMultimap* and I am looking for *BiMultimap*, that also has keys sorted, therefore *Tree* implementation. I once implemented it as two TreeMaps with Sets as values, but it was a little ugly code... – Ognjen Oct 27 '11 at 07:21
  • 1
    A Guava BiHashMap just wraps two HashMaps. Your own code need not be any uglier than that. It's not magically beautiful just because it came from Google :). – Tom Anderson Oct 27 '11 at 07:58