当前位置:网站首页>OC-NSSet(集合)
OC-NSSet(集合)
2022-08-02 06:50:00 【彭同学她同桌】
与Array的区别
在内存中存储的方式是不连续的
在搜索一个个元素的时候效率更高 因为使用的是hash 比如说找一个元素 set通过hash算法可以直接找到 而Array就需要通过遍历
可以求交集并集
NSSet
初始化
NSSet*set = [[NSSet alloc]initWithObjects:@"a",@"b",nil];
NSSet*set2 = [set2 setWithArray]
查
if([set containsObject:@"a"])NSLog(@"YES");
求交集
//set(a,b,c). set2(a,s,d,)
if([set intersectsSet:set2])NSLog(@"YES");//求是否有相同元素
[set intersectSet:set2];
NSLog(@"%@",set);//a
求并集
//set(a,b,c). set2(a,s,d,)
[set unionSet:set2];//会将set2和se1中共同的都加到set中 会去重
NSLog(@“%@”,set);//a,b,c,s,d
求补集
//set(a,b,c). set2(a,s,d,)
[set minusSet:set2];
NSLog(@“%@”,set);//b,c
NSMutableSet
NSMutableSet*mset = [[NSMutableSet alloc]initWithCapacity:0];
[set addObject:@"a"];
边栏推荐
- See the picture to understand | How to choose sales indicators to measure the health of business growth
- 速看!PMP新考纲、PMBOK第七版解读
- 封装class类一次性解决全屏问题
- MPLS的相关技术
- WebGPU 导入[2] - 核心概念与重要机制解读
- 21 days learning challenge 】 【 sequential search
- 数据库概论-MySQL的数据表的基本操作
- 【机器学习】实验4布置:AAAI会议论文聚类分析
- At age 94, pioneer Turing award winner, computational complexity theory, Juris Hartmanis, died
- The second day HCIP
猜你喜欢
随机推荐
Vscode connect to remote server "Acquiring the lock on the/home / ~ 'problem
hdu1752 copy
(2022牛客多校五)D-Birds in the tree(树形DP)
埋点开发流程
海缆探测仪TSS350(二)
封装class类一次性解决全屏问题
张驰咨询:企业实施精益管理的最大障碍,只把精益作为一种工具和方法
交换--STP协议
以训辅教,以战促学 | 新版攻防世界平台正式上线运营!
有趣的网站
Wuhan 2022 organizing of the high-performance computing added new ecological development of high-performance computing
从云计算到函数计算
笔记本开机黑屏提示:ERROR 0199:System Security-Security password retry count exceeded
入门opencv,欢笑快乐每一天
Leetcode Weekly 304
实验8 VLAN综合实验
SQL server 2014 怎么一次性导出多个查询结果?
张驰课堂:六西格玛测量系统的误差分析与判定
sql 远程访问链接服务器
吃透Chisel语言.31.Chisel进阶之通信状态机(三)——Ready-Valid接口:定义、时序和Chisel中的实现









