[英]Highest and lowest elements in trove TIntSet?
TIntSet未排序(它是一个哈希集),因此要找到最小值或最大值,您需要迭代所有值。
fastutil is all ways better than Trove. fastutil在所有方面都比Trove更好。 There is IntSortedSet
interface with firstInt()
and lastInt()
methods. IntSortedSet
接口具有firstInt()
和lastInt()
方法。
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. 它没有实现JDK集合框架中的SortedSet或NavigableSet接口-那里没有这样的方法。
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 first()和last()方法实际上是从接口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. 如果您想要第一个/最后一个/单元格/楼层等类型的选项,则需要基于树的集合,并且trove没有类似的东西。 If you want to extend TIntSet to have such thing then 如果您想扩展TIntSet以拥有这种东西,那么
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. 一个简单的选项是在并行int数组中维护排序后的值,并使用它来满足第一种/最后一种类型的请求,但这将需要额外的内存。
another option is that you can use just one array for values but keep is sorted and use binary search to support map API. 另一个选择是,您只能对值使用一个数组,但对keep进行排序并使用二进制搜索来支持map API。 This can be little slow for get/put as compared to trove but you can save memory because trove has .5 loadfactor 与trove相比,get / put的速度可能有点慢,但由于trove的负载系数为.5,因此可以节省内存
So you can make decision based on trade off you want . 因此,您可以根据需要进行权衡取舍。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.