Important: The information in this document is obsolete and should not be used for new development.
Inherits from | |
Implements | |
Package | com.apple.cocoa.foundation |
Availability | Available in Mac OS X v10.3 and later. |
Companion guide |
NSIndexSet manages an immutable collection of unique unsigned integers, also known as indexes because of the way they are used. You use NSIndexSet in your code to store indexes into some other data structure. For example, given an NSArray object, you could use an index set to identify a subset of objects in that array.
Each index value can appear only once in the index set. This is an important concept to understand and is why you would not use NSIndexSet to store an arbitrary collection of integer values. To illustrate how this works, if you created a new NSIndexSet with the values 4, 5, 2, and 5, the resulting set would only have the values 4, 5, and 2 in it. Because index values are always maintained in sorted order, the actual order of the values when you created the set would be 2, 4, and then 5.
In most cases, using an NSIndexSet is more efficient than storing a collection of individual integers. Internally, indexes are represented using ranges. For maximum performance and efficiency, overlapping ranges in an index set are automatically coalesced—that is, ranges merge rather than overlap. Thus, the more contiguous the indexes in the set, the fewer ranges are required to specify those indexes.
NSIndexSet is not intended to be subclassed.
The mutable subclass of NSIndexSet is NSMutableIndexSet.
firstIndex
lastIndex
indexGreaterThanIndex
indexLessThanIndex
indexGreaterThanOrEqualToIndex
indexLessThanOrEqualToIndex
Creates and returns an NSIndexSet containing the indexes specified by NSRange.ZeroRange
.
public NSIndexSet
()
Creates and returns an NSIndexSet containing a single index, value.
public NSIndexSet
(int value)
Creates and returns an NSIndexSet containing the indexes specified by range.
public NSIndexSet
(NSRange range)
Creates and returns an NSIndexSet containing the indexes in indexSet.
public NSIndexSet
(NSIndexSet indexSet)
Returns true
if the receiver contains the index represented by value.
public boolean containsIndex
(int value)
Returns true
if the receiver contains all of the indexes present in indexSet.
public boolean containsIndexes
(NSIndexSet indexSet)
Returns true
if the receiver contains all the indexes in the range specified by range.
public boolean containsIndexesInRange
(NSRange range)
For example, if an index set contains indexes 20 through 30, this method would return true
for the range (20, 8) and false
for the range (20, 14).
Returns the number of indexes in the receiver or 0 if it is empty.
public int count
()
Returns the first index in the index set or NotFound
if the index set is empty.
public int firstIndex
()
Returns the next closest index that is greater than value or NotFound
if value is equal to or beyond the last index in the set.
public int indexGreaterThanIndex
(int value)
Returns the next closest index that is greater than or equal to value or NotFound
if value is beyond the last index in the set.
public int indexGreaterThanOrEqualToIndex
(int value)
Returns the next closest index that is less than value or NotFound
if value is equal to or before the first index in the set.
public int indexLessThanIndex
(int value)
Returns the next closest index that is less than or equal to value or NotFound
if value is before the first index in the set.
public int indexLessThanOrEqualToIndex
(int value)
Returns true
if the receiver contains any indexes in the range specified by range.
public boolean intersectsIndexesInRange
(NSRangerange
Returns true
if the receiver contains the same indexes as indexSet.
public boolean isEqualToIndexSet
(NSIndexSet indexSet)
Returns the last index in the index set or NotFound
if the index set is empty.
public int lastIndex
()
NSIndexSet provides the following constant as a convenience; you can use it to compare to values returned by some NSIndexSet methods:
© 1997, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-07-24)