6

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?

Alexander Ljungberg
  • 6,302
  • 4
  • 31
  • 37

3 Answers3

3

There is the Apache commons IntRange

michaelok
  • 1,124
  • 1
  • 13
  • 20
Navi
  • 8,580
  • 4
  • 34
  • 32
  • Actually there are also other types of ranges http://commons.apache.org/lang/api-2.5/index.html?org/apache/commons/lang/math/Range.html – Navi Jan 10 '11 at 15:19
0

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.

michaelok
  • 1,124
  • 1
  • 13
  • 20