-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNSIndexSet+SetOperations.m
More file actions
44 lines (38 loc) · 1.17 KB
/
NSIndexSet+SetOperations.m
File metadata and controls
44 lines (38 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// NSIndexSet+SetOperations.m
// tablution
//
// Created by Ian Mccowan on 6/24/12.
// Copyright (c) 2012 Nuance, Inc. All rights reserved.
//
#import "NSIndexSet+SetOperations.h"
@implementation NSIndexSet (SetOperations)
- (NSMutableIndexSet *)indexSetByAddingIndexes:(NSIndexSet *)indexes
{
NSMutableIndexSet *newIndexSet = [[NSMutableIndexSet alloc] initWithIndexSet:self];
[newIndexSet addIndexes:indexes];
return newIndexSet;
}
- (NSMutableIndexSet *)indexSetByRemovingIndexes:(NSIndexSet *)indexes
{
NSMutableIndexSet *newIndexSet = [[NSMutableIndexSet alloc] initWithIndexSet:self];
[newIndexSet removeIndexes:indexes];
return newIndexSet;
}
- (BOOL)intersectsIndexes:(NSIndexSet *)otherIndexes
{
// Could maybe make more efficient using technique described here:
// http://www.cocoabuilder.com/archive/cocoa/82348-nsindexset.html
NSUInteger intersectIndex = [self indexPassingTest:^BOOL(NSUInteger idx, BOOL *stop) {
if ([otherIndexes containsIndex:idx]) {
*stop = YES;
return YES;
}
return NO;
}];
if (intersectIndex == NSNotFound) {
return NO;
}
return YES;
}
@end