Next Page > Hide TOC

Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

NSIndexSet

Inherits from
Implements
Package
com.apple.cocoa.foundation
Availability
Available in Mac OS X v10.3 and later.
Companion guide

Overview

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.

Tasks

Constructors

Testing an Index Set

Getting Information About an Index Set

Accessing Indexes

Constructors

NSIndexSet

Creates and returns an NSIndexSet containing the indexes specified by NSRange.ZeroRange.

public NSIndexSet()

Availability

Creates and returns an NSIndexSet containing a single index, value.

public NSIndexSet(int value)

Availability

Creates and returns an NSIndexSet containing the indexes specified by range.

public NSIndexSet(NSRange range)

Availability

Creates and returns an NSIndexSet containing the indexes in indexSet.

public NSIndexSet(NSIndexSet indexSet)

Availability

Instance Methods

containsIndex

Returns true if the receiver contains the index represented by value.

public boolean containsIndex(int value)

Availability
See Also

containsIndexes

Returns true if the receiver contains all of the indexes present in indexSet.

public boolean containsIndexes(NSIndexSet indexSet)

Availability
See Also

containsIndexesInRange

Returns true if the receiver contains all the indexes in the range specified by range.

public boolean containsIndexesInRange(NSRange range)

Discussion

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).

Availability
See Also

count

Returns the number of indexes in the receiver or 0 if it is empty.

public int count()

Availability

firstIndex

Returns the first index in the index set or NotFound if the index set is empty.

public int firstIndex()

Availability
See Also

indexGreaterThanIndex

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)

Availability
See Also

indexGreaterThanOrEqualToIndex

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)

Availability
See Also

indexLessThanIndex

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)

Availability
See Also

indexLessThanOrEqualToIndex

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)

Availability
See Also

intersectsIndexesInRange

Returns true if the receiver contains any indexes in the range specified by range.

public boolean intersectsIndexesInRange(NSRangerange

Availability
See Also

isEqualToIndexSet

Returns true if the receiver contains the same indexes as indexSet.

public boolean isEqualToIndexSet(NSIndexSet indexSet)

Availability

lastIndex

Returns the last index in the index set or NotFound if the index set is empty.

public int lastIndex()

Availability
See Also

Constants

NSIndexSet provides the following constant as a convenience; you can use it to compare to values returned by some NSIndexSet methods:

Constant

Description

NotFound

Returned when an object is not found in an NSIndexSet.



Next Page > Hide TOC


© 1997, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-07-24)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.