【Foundation-37-1】#import <Foundation/NSIndexSet.h>不可索引集合
2015-09-29 23:51
369 查看
NSIndexSet 用来让你从某个 data structure 里面提取一部分东西出来成为一个新的东西。
比如你有一个 NSArray, 里面是
(one, two, three, four, five)
然后你造了个 indexSet 的内容是 0,1,2,4
然后你把它套到那个 array 上,就是 (one, two,three,five)
@interface NSIndexSet :NSObject <NSCopying,NSMutableCopying,
NSSecureCoding> {
@protected
【初始化】
+ (instancetype)indexSet;
+ (instancetype)indexSetWithIndex:(NSUInteger)value;
+ (instancetype)indexSetWithIndexesInRange:(NSRange)range;
- (instancetype)initWithIndexSet:(NSIndexSet *)indexSet NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithIndex:(NSUInteger)value;
- (instancetype)initWithIndexesInRange:(NSRange)range NS_DESIGNATED_INITIALIZER;
- (BOOL)isEqualToIndexSet:(NSIndexSet *)indexSet;// 比较
@property (readonly)NSUInteger count;// 数量
@property (readonly)NSUInteger firstIndex;// 第一个
@property (readonly)NSUInteger lastIndex;// 最后一个
- (NSUInteger)getIndexes:(NSUInteger *)indexBuffer maxCount:(NSUInteger)bufferSize inIndexRange:(NSRangePointer)range;// 阿西吧,待研究
- (NSUInteger)countOfIndexesInRange:(NSRange)range NS_AVAILABLE(10_5, 2_0);// 在(x,y)范围内的个数
【大于小于】
- (NSUInteger)indexGreaterThanIndex:(NSUInteger)value;// 大于value
的第一个位置
- (NSUInteger)indexLessThanIndex:(NSUInteger)value;// 小雨value
的第一个位置
- (NSUInteger)indexGreaterThanOrEqualToIndex:(NSUInteger)value;// 大于等于
value 的第一个位置
- (NSUInteger)indexLessThanOrEqualToIndex:(NSUInteger)value;// 小于等于
value 的第一个位置
【判断】
- (BOOL)containsIndex:(NSUInteger)value;// 是否包含
value
- (BOOL)containsIndexesInRange:(NSRange)range;// 是否包含
range
- (BOOL)containsIndexes:(NSIndexSet *)indexSet;// 是否包含
indexSet
- (BOOL)intersectsIndexesInRange:(NSRange)range;// 是否与 range
有交集
【遍历】
- (void)enumerateIndexesUsingBlock:(void (^)(NSUInteger idx,BOOL *stop))block
NS_AVAILABLE(10_6,
4_0);
- (void)enumerateIndexesWithOptions:(NSEnumerationOptions)opts usingBlock:(void (^)(NSUInteger idx,BOOL
*stop))block NS_AVAILABLE(10_6,
4_0);
- (void)enumerateIndexesInRange:(NSRange)range options:(NSEnumerationOptions)opts usingBlock:(void (^)(NSUInteger
idx, BOOL *stop))block
NS_AVAILABLE(10_6,
4_0);
【遍历符合条件的个数】
- (NSUInteger)indexPassingTest:(BOOL (^)(NSUInteger idx,BOOL *stop))predicate
NS_AVAILABLE(10_6,
4_0);
- (NSUInteger)indexWithOptions:(NSEnumerationOptions)opts passingTest:(BOOL (^)(NSUInteger idx,BOOL
*stop))predicate NS_AVAILABLE(10_6,
4_0);
- (NSUInteger)indexInRange:(NSRange)range options:(NSEnumerationOptions)opts passingTest:(BOOL (^)(NSUInteger
idx, BOOL *stop))predicate
NS_AVAILABLE(10_6,
4_0);
【遍历符合条件的索引集合】
- (NSIndexSet *)indexesPassingTest:(BOOL (^)(NSUInteger idx,BOOL *stop))predicate
NS_AVAILABLE(10_6,
4_0);
- (NSIndexSet *)indexesWithOptions:(NSEnumerationOptions)opts passingTest:(BOOL (^)(NSUInteger idx,BOOL
*stop))predicate NS_AVAILABLE(10_6,
4_0);
- (NSIndexSet *)indexesInRange:(NSRange)range options:(NSEnumerationOptions)opts passingTest:(BOOL (^)(NSUInteger
idx, BOOL *stop))predicate
NS_AVAILABLE(10_6,
4_0);
【遍历其中的所有范围】
- (void)enumerateRangesUsingBlock:(void (^)(NSRange range,BOOL *stop))block
NS_AVAILABLE(10_7,
5_0);
- (void)enumerateRangesWithOptions:(NSEnumerationOptions)opts usingBlock:(void (^)(NSRange range,BOOL
*stop))block NS_AVAILABLE(10_7,
5_0);
- (void)enumerateRangesInRange:(NSRange)range options:(NSEnumerationOptions)opts usingBlock:(void (^)(NSRange
range, BOOL *stop))block
NS_AVAILABLE(10_7,
5_0);
@end
比如你有一个 NSArray, 里面是
(one, two, three, four, five)
然后你造了个 indexSet 的内容是 0,1,2,4
然后你把它套到那个 array 上,就是 (one, two,three,five)
@interface NSIndexSet :NSObject <NSCopying,NSMutableCopying,
NSSecureCoding> {
@protected
【初始化】
+ (instancetype)indexSet;
+ (instancetype)indexSetWithIndex:(NSUInteger)value;
+ (instancetype)indexSetWithIndexesInRange:(NSRange)range;
- (instancetype)initWithIndexSet:(NSIndexSet *)indexSet NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithIndex:(NSUInteger)value;
- (instancetype)initWithIndexesInRange:(NSRange)range NS_DESIGNATED_INITIALIZER;
- (BOOL)isEqualToIndexSet:(NSIndexSet *)indexSet;// 比较
@property (readonly)NSUInteger count;// 数量
@property (readonly)NSUInteger firstIndex;// 第一个
@property (readonly)NSUInteger lastIndex;// 最后一个
- (NSUInteger)getIndexes:(NSUInteger *)indexBuffer maxCount:(NSUInteger)bufferSize inIndexRange:(NSRangePointer)range;// 阿西吧,待研究
- (NSUInteger)countOfIndexesInRange:(NSRange)range NS_AVAILABLE(10_5, 2_0);// 在(x,y)范围内的个数
【大于小于】
- (NSUInteger)indexGreaterThanIndex:(NSUInteger)value;// 大于value
的第一个位置
- (NSUInteger)indexLessThanIndex:(NSUInteger)value;// 小雨value
的第一个位置
- (NSUInteger)indexGreaterThanOrEqualToIndex:(NSUInteger)value;// 大于等于
value 的第一个位置
- (NSUInteger)indexLessThanOrEqualToIndex:(NSUInteger)value;// 小于等于
value 的第一个位置
【判断】
- (BOOL)containsIndex:(NSUInteger)value;// 是否包含
value
- (BOOL)containsIndexesInRange:(NSRange)range;// 是否包含
range
- (BOOL)containsIndexes:(NSIndexSet *)indexSet;// 是否包含
indexSet
- (BOOL)intersectsIndexesInRange:(NSRange)range;// 是否与 range
有交集
【遍历】
- (void)enumerateIndexesUsingBlock:(void (^)(NSUInteger idx,BOOL *stop))block
NS_AVAILABLE(10_6,
4_0);
- (void)enumerateIndexesWithOptions:(NSEnumerationOptions)opts usingBlock:(void (^)(NSUInteger idx,BOOL
*stop))block NS_AVAILABLE(10_6,
4_0);
- (void)enumerateIndexesInRange:(NSRange)range options:(NSEnumerationOptions)opts usingBlock:(void (^)(NSUInteger
idx, BOOL *stop))block
NS_AVAILABLE(10_6,
4_0);
NSRange myRange = NSMakeRange(1, 4); NSIndexSet *indexset = [[NSIndexSet alloc]initWithIndexesInRange:myRange]; [indexset enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) { NSLog(@"%ld",idx); }];
【遍历符合条件的个数】
- (NSUInteger)indexPassingTest:(BOOL (^)(NSUInteger idx,BOOL *stop))predicate
NS_AVAILABLE(10_6,
4_0);
- (NSUInteger)indexWithOptions:(NSEnumerationOptions)opts passingTest:(BOOL (^)(NSUInteger idx,BOOL
*stop))predicate NS_AVAILABLE(10_6,
4_0);
- (NSUInteger)indexInRange:(NSRange)range options:(NSEnumerationOptions)opts passingTest:(BOOL (^)(NSUInteger
idx, BOOL *stop))predicate
NS_AVAILABLE(10_6,
4_0);
NSArray *arr = @[@"0",@"1",@"2",@"3",@"4"]; NSRange myRange = NSMakeRange(1, 4); NSIndexSet *indexset = [[NSIndexSet alloc]initWithIndexesInRange:myRange]; NSUInteger test = [indexset indexPassingTest:^BOOL(NSUInteger idx, BOOL *stop) { if ([[arr objectAtIndex:idx]isEqualToString:@"3"]) { NSLog(@"ok");//test +1; return YES; }else{ NSLog(@"no"); return NO;//结束 } }];
【遍历符合条件的索引集合】
- (NSIndexSet *)indexesPassingTest:(BOOL (^)(NSUInteger idx,BOOL *stop))predicate
NS_AVAILABLE(10_6,
4_0);
- (NSIndexSet *)indexesWithOptions:(NSEnumerationOptions)opts passingTest:(BOOL (^)(NSUInteger idx,BOOL
*stop))predicate NS_AVAILABLE(10_6,
4_0);
- (NSIndexSet *)indexesInRange:(NSRange)range options:(NSEnumerationOptions)opts passingTest:(BOOL (^)(NSUInteger
idx, BOOL *stop))predicate
NS_AVAILABLE(10_6,
4_0);
NSArray *arr = @[@"0",@"2",@"2",@"3",@"4"]; NSRange myRange = NSMakeRange(1, 4); NSIndexSet *indexset = [[NSIndexSet alloc]initWithIndexesInRange:myRange]; NSIndexSet *test1 = [indexset indexesPassingTest:^BOOL(NSUInteger idx, BOOL *stop) { if ([[arr objectAtIndex:idx]isEqualToString:@"2"]) { NSLog(@"ok");//test +1; return YES; }else{ NSLog(@"no"); return NO;//结束 } }];
【遍历其中的所有范围】
- (void)enumerateRangesUsingBlock:(void (^)(NSRange range,BOOL *stop))block
NS_AVAILABLE(10_7,
5_0);
- (void)enumerateRangesWithOptions:(NSEnumerationOptions)opts usingBlock:(void (^)(NSRange range,BOOL
*stop))block NS_AVAILABLE(10_7,
5_0);
- (void)enumerateRangesInRange:(NSRange)range options:(NSEnumerationOptions)opts usingBlock:(void (^)(NSRange
range, BOOL *stop))block
NS_AVAILABLE(10_7,
5_0);
NSMutableIndexSet *muindex = [NSMutableIndexSet indexSet]; [muindex addIndex:1]; [muindex addIndex:3]; [muindex addIndex:4]; [muindex addIndex:5]; [muindex addIndex:5]; [muindex addIndex:7]; [muindex enumerateRangesUsingBlock:^(NSRange range, BOOL *stop) { NSLog(@"%lu",(unsigned long)range.location); NSLog(@"%lu",range.length); }];
@end
相关文章推荐
- 系统吞吐量(TPS)、用户并发量、性能测试概念和公式
- swift关于UIView设置frame值的extension
- LeetCode "Find the Duplicate Number"
- 芒果TV真实视频地址解析
- 项目里出现的问题05(自定义DEBUG)
- 等比数列二分求和
- Handler,Message,Looper深入系统学习
- 折腾kali linux2.0
- python中lambda函数
- Linux学习笔记之 pstree,htop,glances,dstat 命令使用
- JDBC Dao的实现与测试
- windows如何方便快速在指定文件夹打开命令行
- Mac下获取AppStore安装包文件路径
- PDO事务处理
- ios开发 17个常用代码整理
- 第1章 Mysql启动与关闭
- 5、Android编译安装过程
- android新控件之toolbar,floatingActionButton,SnackBar,CollapsingToolbarLayout
- 如何私有化路由器
- 怎么样把一个大的文件压缩成几部分