Is there an IndexSet and a Range class for Java?

醉酒当歌 提交于 2019-12-10 13:24:11

问题


In Objective-C Cocoa we have the NSIndexSet class which stores a series of unique indexes efficiently by keeping an array of ranges. E.g. the set 1, 2, ... 30, 57 would be stored as the ranges 1-30 and 57 rather than an array of 32 numbers. This facilitates huge selections to be stored in a simple and fast way. For example, if all rows between 1 and a million in a table selected, the index set collapses to just a tiny range and is fast to compare and intersect with.

Unfortunately this turns out to be rather hard to Google for. Is there an equivalent class for Java?


回答1:


It seems a useful class, and I don't recall a standard implementation.

Here's a bunch of some -perhaps useful- pointers.

A range intersection algorithm better than O(n)?

http://www.codeproject.com/KB/recipes/rangeset.aspx

http://healpix-rangeset.googlecode.com/svn/trunk/healpix-rangeset/src/org/asterope/healpix/LongRangeSet.java

http://pcj.sourceforge.net/docs/api/bak/pcj/set/IntRangeSet.html

Data structure to build and lookup set of integer ranges

Representing sparse integer sets?

http://www.iis.uni-stuttgart.de/intset/doc/intset/TreeIntegerSet.html




回答2:


There is the Apache commons IntRange




回答3:


Certainly not last and not least, there is a Range class in the Guava library. This article does a nice job of illustrating how you might use it.



来源:https://stackoverflow.com/questions/4648261/is-there-an-indexset-and-a-range-class-for-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!