4

I'm migrating some code over to GNU trove for performance reasons.

However, I do have some TreeSets, where I need rather fast update and lookups along with a sorted iteration - the primary use case of a TreeSet. Of course I will go over the use and check if I can maybe live with a HashSet just as good.

What is the appropriate replacement from GNU Trove for a SortedSet?

Thank you.

Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194
  • @Gray: your comment is all bogus too. This not related at all. You didn't understand OP's question. This shows both in your comment and in your answer. – Cedric Martin Nov 22 '11 at 19:39

1 Answers1

2

Update: I found a related feature request in Trove on Sourceforge: http://sourceforge.net/tracker/index.php?func=detail&aid=1631704&group_id=39235&atid=424685

There doesn't seem to be a SortedSet so far, and the benefits of Trove seem to be less big here: it will save some memory for primitive types (and avoid boxing), but the algorithmic organization of the data will likely be the same, and it will still need entry objects.

Update #2:

For many use cases - depending on your write access patterns -, you should be able to get a decent performance by just using a TIntArrayList and using the binarySearch method for lookup (which assumes the array to be sorted!)

Inserting into a sorted array is O(n), so this is not an option when you perform a ton of modifications to the array, and query after each. But if your changes are bulk additions, just calling sort after each update should give you a surprisingly good performance!

Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194