TIntSet
is "sorted set" by sense, i.e. it's elements have natural order.
Unfortunately, I can't find any methods similar to first()
and last()
.
Is it possible to overcome this lack somehow?
Why do you think this set is sorted? It looks like it's not. It doesn't implement SortedSet or NavigableSet interfaces from JDK collections framework - there are no such methods there.
first() and last() methods are actually inherited from interface SortedSet https://docs.oracle.com/javase/7/docs/api/java/util/SortedSet.html#first%28%29
If you want first/last/cell/floor etc type of option then Tree based set is required and trove does not have anything like that. If you want to extend TIntSet to have such thing then
one of the simple option can be maintaining sorted values in parallel int array and use that to serve first/last type of request, but this will required extra memory.
another option is that you can use just one array for values but keep is sorted and use binary search to support map API. This can be little slow for get/put as compared to trove but you can save memory because trove has .5 loadfactor
So you can make decision based on trade off you want .
fastutil is all ways better than Trove. There is
IntSortedSet
interface withfirstInt()
andlastInt()
methods.