TIntSet未排序(它是一个哈希集),因此要找到最小值或最大值,您需要迭代所有值。
fastutil is all ways better than Trove. There is IntSortedSet
interface with firstInt()
and lastInt()
methods.
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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.