Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/Foundation.framework |
Availability | Available in iOS 2.0 and later. |
Companion guide | |
Declared in | NSIndexSet.h |
The NSIndexSet
class represents an immutable collection of unique unsigned integers, known as indexes because of the way they are used. This collection is referred to as a index set.
You use index sets 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 index sets to store an arbitrary collection of integer values. To illustrate how this works, if you created an NSIndexSet
object 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 index set is more efficient than storing a collection of individual integers. Internally, the NSIndexSet
class represents indexes 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.
The designated initializers of the NSIndexSet class are: initWithIndexesInRange:
and initWithIndexSet:
.
You must not subclass the NSIndexSet
class.
The mutable subclass of NSIndexSet
is NSMutableIndexSet.
+ indexSet
+ indexSetWithIndex:
+ indexSetWithIndexesInRange:
– init
– initWithIndex:
– initWithIndexesInRange:
– initWithIndexSet:
– containsIndex:
– containsIndexes:
– containsIndexesInRange:
– intersectsIndexesInRange:
– count
– countOfIndexesInRange:
– indexPassingTest:
– indexesPassingTest:
– indexWithOptions:passingTest:
– indexesWithOptions:passingTest:
– indexInRange:options:passingTest:
– indexesInRange:options:passingTest:
– firstIndex
– lastIndex
– indexLessThanIndex:
– indexLessThanOrEqualToIndex:
– indexGreaterThanOrEqualToIndex:
– indexGreaterThanIndex:
– getIndexes:maxCount:inIndexRange:
Creates an empty index set.
+ (id)indexSet
NSIndexSet
object with no members.
NSIndexSet.h
Creates an index set with an index.
+ (id)indexSetWithIndex:(NSUInteger)index
An index.
NSIndexSet
object containing index.
NSIndexSet.h
Creates an index set with an index range.
+ (id)indexSetWithIndexesInRange:(NSRange)indexRange
An index range.
NSIndexSet
object containing indexRange.
NSIndexSet.h
Indicates whether the receiver contains a specific index.
- (BOOL)containsIndex:(NSUInteger)index
Index being inquired about.
YES
when the receiver contains index, NO
otherwise.
NSIndexSet.h
Indicates whether the receiver contains a superset of the indexes in another index set.
- (BOOL)containsIndexes:(NSIndexSet *)indexSet
Index set being inquired about.
YES
when the receiver contains a superset of the indexes in indexSet, NO
otherwise.
NSIndexSet.h
Indicates whether the receiver contains the indexes represented by an index range.
- (BOOL)containsIndexesInRange:(NSRange)indexRange
The index range being inquired about.
YES
when the receiver contains the indexes in indexRange, NO
otherwise.
NSIndexSet.h
Returns the number of indexes in the receiver.
- (NSUInteger)count
Number of indexes in the receiver.
NSIndexSet.h
Returns the number of indexes in the receiver that are members of a given range.
- (NSUInteger)countOfIndexesInRange:(NSRange)indexRange
Index range being inquired about.
Number of indexes in the receiver that are members of indexRange.
NSIndexSet.h
Executes a given Block using the indexes in the specified range, using the specified enumeration options.
- (void)enumerateIndexesInRange:(NSRange)range options:(NSEnumerationOptions)opts usingBlock:(void (^)(NSUInteger idx, BOOL *stop))block
Index to enumerate.
A bitmask that specifies the options for the enumeration (whether it should be performed concurrently and whether it should be performed in reverse order). See NSEnumerationOptions
for the supported values.
The Block to apply to elements in the set.
The Block takes two arguments:
The index of the object.
A reference to a Boolean value. The block can set the value to YES
to stop further processing of the set. The stop
argument is an out-only argument. You should only ever set this Boolean to YES within the Block.
NSIndexSet.h
Executes a given Block using each object in the receiver.
- (void)enumerateIndexesUsingBlock:(void (^)(NSUInteger idx, BOOL *stop))block
The Block to apply to elements in the set.
The Block takes two arguments:
The index of the object.
A reference to a Boolean value. The block can set the value to YES
to stop further processing of the set. The stop
argument is an out-only argument. You should only ever set this Boolean to YES within the Block.
NSIndexSet.h
Executes a given Block over the receiver’s indexes, using the specified enumeration options.
- (void)enumerateIndexesWithOptions:(NSEnumerationOptions)opts usingBlock:(void (^)(NSUInteger idx, BOOL *stop))block
A bitmask that specifies the options for the enumeration (whether it should be performed concurrently and whether it should be performed in reverse order). See NSEnumerationOptions
for the supported values.
The Block to apply to elements in the set.
The Block takes two arguments:
The index of the object.
A reference to a Boolean value. The block can set the value to YES
to stop further processing of the set. The stop
argument is an out-only argument. You should only ever set this Boolean to YES within the Block.
NSIndexSet.h
Returns either the first index in the receiver or the not-found indicator.
- (NSUInteger)firstIndex
First index in the receiver or NSNotFound
when the receiver is empty.
NSIndexSet.h
The receiver fills an index buffer with the indexes contained both in the receiver and in an index range, returning the number of indexes copied.
- (NSUInteger)getIndexes:(NSUInteger *)indexBuffer maxCount:(NSUInteger)bufferSize inIndexRange:(NSRangePointer)indexRangePointer
Index buffer to fill.
Maximum size of indexBuffer.
Index range to compare with indexes in the receiver; nil
represents all the indexes in the receiver. Indexes in the index range and in the receiver are copied to indexBuffer. On output, the range of indexes not copied to indexBuffer.
Number of indexes placed in indexBuffer.
You are responsible for allocating the memory required for indexBuffer and for releasing it later.
Suppose you have an index set with contiguous indexes from 1 to 100. If you use this method to request a range of (1, 100)
—which represents the set of indexes 1 through 100—and specify a buffer size of 20
, this method returns 20 indexes—1 through 20—in indexBuffer and sets indexRange to (21, 80)
—which represents the indexes 21 through 100.
Use this method to retrieve entries quickly and efficiently from an index set. You can call this method repeatedly to retrieve blocks of index values and then process them. When doing so, use the return value and indexRange to determine when you have finished processing the desired indexes. When the return value is less than bufferSize, you have reached the end of the range.
NSIndexSet.h
Returns an NSIndexSet
containing the receiver’s objects in the specified range that pass the Block test.
- (NSIndexSet *)indexesInRange:(NSRange)range options:(NSEnumerationOptions)opts passingTest:(BOOL (^)(NSUInteger idx, BOOL *stop))predicate
The range of indexes to test.
A bitmask that specifies the options for the enumeration (whether it should be performed concurrently and whether it should be performed in reverse order). See NSEnumerationOptions
for the supported values.
The Block to apply to elements in the set.
The Block takes two arguments:
The index of the object.
A reference to a Boolean value. The block can set the value to YES
to stop further processing of the set. The stop
argument is an out-only argument. You should only ever set this Boolean to YES within the Block.
The Block returns a Boolean value that indicates whether obj passed the test.
An NSIndexSet
containing the indexes of the receiver that passed the predicate Block test.
NSIndexSet.h
Returns an NSIndexSet
containing the receiver’s objects that pass the Block test.
- (NSIndexSet *)indexesPassingTest:(BOOL (^)(NSUInteger idx, BOOL *stop))predicate
The Block to apply to elements in the set.
The Block takes two arguments:
The index of the object.
A reference to a Boolean value. The block can set the value to YES
to stop further processing of the set. The stop
argument is an out-only argument. You should only ever set this Boolean to YES within the Block.
The Block returns a Boolean value that indicates whether obj passed the test.
An NSIndexSet
containing the indexes of the receiver that passed the predicate Block test.
NSIndexSet.h
Returns an NSIndexSet
containing the receiver’s objects that pass the Block test using the specified enumeration options.
- (NSIndexSet *)indexesWithOptions:(NSEnumerationOptions)opts passingTest:(BOOL (^)(NSUInteger idx, BOOL *stop))predicate
A bitmask that specifies the options for the enumeration (whether it should be performed concurrently and whether it should be performed in reverse order). See NSEnumerationOptions
for the supported values.
The Block to apply to elements in the set.
The Block takes two arguments:
The index of the object.
A reference to a Boolean value. The block can set the value to YES
to stop further processing of the set. The stop
argument is an out-only argument. You should only ever set this Boolean to YES within the Block.
The Block returns a Boolean value that indicates whether obj passed the test.
An NSIndexSet
containing the indexes of the receiver that passed the predicate Block test.
NSIndexSet.h
Returns either the closest index in the receiver that is greater than a specific index or the not-found indicator.
- (NSUInteger)indexGreaterThanIndex:(NSUInteger)index
Index being inquired about.
Closest index in the receiver greater than index; NSNotFound
when the receiver contains no qualifying index.
NSIndexSet.h
Returns either the closest index in the receiver that is greater than or equal to a specific index or the not-found indicator.
- (NSUInteger)indexGreaterThanOrEqualToIndex:(NSUInteger)index
Index being inquired about.
Closest index in the receiver greater than or equal to index; NSNotFound
when the receiver contains no qualifying index.
NSIndexSet.h
Returns the index of the first object in the specified range that passes the predicate Block test.
- (NSUInteger)indexInRange:(NSRange)range options:(NSEnumerationOptions)opts passingTest:(BOOL (^)(NSUInteger idx, BOOL *stop))predicate
The range of indexes to test.
A bitmask that specifies the options for the enumeration (whether it should be performed concurrently and whether it should be performed in reverse order). See NSEnumerationOptions
for the supported values.
The Block to apply to elements in the set.
The Block takes two arguments:
The index of the object.
A reference to a Boolean value. The block can set the value to YES
to stop further processing of the set. The stop
argument is an out-only argument. You should only ever set this Boolean to YES within the Block.
The Block returns a Boolean value that indicates whether obj passed the test.
The index of the first object that passes the predicate test.
NSIndexSet.h
Returns either the closest index in the receiver that is less than a specific index or the not-found indicator.
- (NSUInteger)indexLessThanIndex:(NSUInteger)index
Index being inquired about.
Closest index in the receiver less than index; NSNotFound
when the receiver contains no qualifying index.
NSIndexSet.h
Returns either the closest index in the receiver that is less than or equal to a specific index or the not-found indicator.
- (NSUInteger)indexLessThanOrEqualToIndex:(NSUInteger)index
Index being inquired about.
Closest index in the receiver less than or equal to index; NSNotFound
when the receiver contains no qualifying index.
NSIndexSet.h
Returns the index of the first object that passes the predicate Block test.
- (NSUInteger)indexPassingTest:(BOOL (^)(NSUInteger idx, BOOL *stop))predicate
The Block to apply to elements in the set.
The Block takes two arguments:
The index of the object.
A reference to a Boolean value. The block can set the value to YES
to stop further processing of the set. The stop
argument is an out-only argument. You should only ever set this Boolean to YES within the Block.
The Block returns a Boolean value that indicates whether obj passed the test.
The index of the first object that passes the predicate test.
NSIndexSet.h
Returns the index of the first object that passes the predicate Block test using the specified enumeration options.
- (NSUInteger)indexWithOptions:(NSEnumerationOptions)opts passingTest:(BOOL (^)(NSUInteger idx, BOOL *stop))predicate
A bitmask that specifies the options for the enumeration (whether it should be performed concurrently and whether it should be performed in reverse order). See NSEnumerationOptions
for the supported values.
The Block to apply to elements in the set.
The Block takes two arguments:
The index of the object.
A reference to a Boolean value. The block can set the value to YES
to stop further processing of the set. The stop
argument is an out-only argument. You should only ever set this Boolean to YES within the Block.
The Block returns a Boolean value that indicates whether obj passed the test.
The index of the first object that passes the predicate test.
NSIndexSet.h
Initializes an allocated NSIndexSet
object.
- (id)init
Initialized, empty NSIndexSet
object.
NSIndexSet.h
Initializes an allocated NSIndexSet
object with an index.
- (id)initWithIndex:(NSUInteger)index
An index.
Initialized NSIndexSet
object with index.
NSIndexSet.h
Initializes an allocated NSIndexSet
object with an index range.
- (id)initWithIndexesInRange:(NSRange)indexRange
An index range. Must include only indexes representable as unsigned integers.
Initialized NSIndexSet
object with indexRange.
This method raises an NSRangeException
when indexRange would add an index that exceeds the maximum allowed value for unsigned integers.
This method is a designated initializer for NSIndexSet
.
NSIndexSet.h
Initializes an allocated NSIndexSet
object with an index set.
- (id)initWithIndexSet:(NSIndexSet *)indexSet
An index set.
Initialized NSIndexSet
object with indexSet.
This method is a designated initializer for NSIndexSet
.
NSIndexSet.h
Indicates whether the receiver contains any of the indexes in a range.
- (BOOL)intersectsIndexesInRange:(NSRange)indexRange
Index range being inquired about.
YES
when the receiver contains one or more of the indexes in indexRange, NO
otherwise.
NSIndexSet.h
Indicates whether the indexes in the receiver are the same indeces contained in another index set.
- (BOOL)isEqualToIndexSet:(NSIndexSet *)indexSet
Index set being inquired about.
YES
when the indexes in the receiver are the same indexes indexSet contains, NO
otherwise.
NSIndexSet.h
Returns either the last index in the receiver or the not-found indicator.
- (NSUInteger)lastIndex
Last index in the receiver or NSNotFound
when the receiver is empty.
NSIndexSet.h
Last updated: 2009-08-28