黑科技--位集--bitset
std::bitset
template <size_t N> class bitset;
Abtsetstores bits (elements with only two possible values: 0 or 1, true or false, ...). //位集用于存储0、1元素。
The class emulates an array of bool elements, but optimized for space allocation: generally, each element occupies only one bit (which, on most systems, is eight times less than the smallest elemental type: char). //这种类模拟了bool数组,但是单个元素占空间只有1bit。(!!好东西有木有!!)
Each bit position can be accessed individually: for example, for a given bitset named foo, the expression foo[3] accesses its fourth bit, just like a regular array accesses its elements. But because no elemental type is a single bit in most C++ environments, the individual elements are accessed as special references type (seebitset::reference). //每个位都能被独立访问。(!!好东西有木有!!)
Bitsets have the feature of being able to be constructed from and converted to both integer values and binary strings (see its constructor and membersto_ulong andto_string ). They can also be directly inserted and extracted from streams in binary format (see applicable operators). //这货还提供转化成其他类型的函数(!!好东西有木有!!)
Thesize of a bitset is fixed at compile-time (determined by its template parameter). For a class that also optimizes for space allocation and allows for dynamic resizing, see the bool specialization ofvector (vector<bool>).
Template parameters
- N
- Size of the bitset, in terms of number of bits. It is returned by member functionbitset::size.size_t is an unsigned integral type. //大小由位数决定,并且可以引用内置函数直接查询某一bitset的大小
Member types
- reference
- Reference-like type (public member class )
Member functions
- (constructor)
- Construct bitset (public member function )
- applicable operators
- Bitset operators (function )
Bit access
- operator[]
- Access bit (public member function ) //访问位集中的元素可以直接像访问数组一样完成
- count
- Count bits set (public member function ) //计数有多少位
- size
- Return size (public member function ) //返回空间大小
- test
- Return bit value (public member function ) //返回...这什么东西?
- any
- Test if any bit is set (public member function ) //返回位集中是否有元素1
- none
- Test if no bit is set (public member function ) //返回位集是否全空
- all
- Test if all bits are set (public member function ) //返回位集是否全满
Bit operations
- set
- Set bits (public member function ) //设置位
- reset
- Reset bits (public member function ) //清空位集
- flip
- Flip bits (public member function ) //位集元素置反
Bitset operations
- to_string
- Convert to string (public member function )
- to_ulong
- Convert to unsigned long integer (public member function )
- to_ullong
- Convert to unsigned long long (public member function )
Non-member function overloads
- applicable operators
- Bitset operators (function )
Non-member class specializations
- hash<bitset>
- Hash for bitset (class template specialization )
【主要操作测试】
#include<iostream>
#include<cstdio>
#include<bitset> using namespace std; int main()
{
bitset<> a; a[]=; //直接赋值
cout << a.count() << endl; //计数1的个数
cout << a.size() << endl; //返回空间大小
cout << a.test() << endl;
cout << a.test() << endl; //判断第i位是否为1
cout << a.any() << endl; //是否非空
cout << a.none() << endl; //是否全空
cout << a.all() << endl; //是否全满 a.set(); //与赋值相同
cout << a[] << endl; //直接访问,与test相同 a.reset(); //清空
cout << a.count() << endl;
cout << a.none() << endl; a.flip(); //反置
cout << a.count() << endl;
cout << a.all() << endl;
}
【结果如下】
黑科技--位集--bitset的更多相关文章
- ACM: FZU 2105 Digits Count - 位运算的线段树【黑科技福利】
FZU 2105 Digits Count Time Limit:10000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- 微软AI发布会,集齐六大亮点召唤黑科技!
7月12日,微软合作伙伴大会Inspire在华盛顿特区如火如荼地举行.同一天,在相隔5个时区的伦敦,微软还举办了一场关于人工智能的发布会.这是一场智能技术和情感体验两相交融的科技盛宴,既有黑科技,也有 ...
- 【转载】史上最全:TensorFlow 好玩的技术、应用和你不知道的黑科技
[导读]TensorFlow 在 2015 年年底一出现就受到了极大的关注,经过一年多的发展,已经成为了在机器学习.深度学习项目中最受欢迎的框架之一.自发布以来,TensorFlow 不断在完善并增加 ...
- 一文带你了解 HTTP 黑科技
这是 HTTP 系列的第三篇文章,此篇文章为 HTTP 的进阶文章. 在前面两篇文章中我们讲述了 HTTP 的入门,HTTP 所有常用标头的概述,这篇文章我们来聊一下 HTTP 的一些 黑科技. HT ...
- 黑科技项目:英雄无敌III Mod <<Fallen Angel>>介绍
英雄无敌三简介(Heroes of Might and Magic III) 英3是1999年由New World Computing在Windows平台上开发的回合制策略魔幻游戏,其出版商是3DO. ...
- C++的黑科技
周二面了腾讯,之前只投了TST内推,貌似就是TST面试了 其中有一个问题,"如何产生一个不能被继承的类",这道题我反反复复只想到,将父类的构造函数私有,让子类不能调用,最后归结出一 ...
- 基于Twitter的Snowflake算法实现分布式高效有序ID生产黑科技(无懈可击)
参考美团文档:https://tech.meituan.com/2017/04/21/mt-leaf.html Twitter-Snowflake算法产生的背景相当简单,为了满足Twitter每秒上万 ...
- 这些JavaScript编程黑科技
1.单行写一个评级组件 "★★★★★☆☆☆☆☆".slice(5 - rate, 10 - rate);定义一个变量rate是1到5的值,然后执行上面代码,看图 才发现插件什么的都 ...
- 优云亮相GOPS2017全球运维大会 “黑科技”获全场最高关注
2017年4月21日,GOPS――2017全球运维大会于深圳・圣淘沙酒店拉开帷幕.GOPS全球运维大会由高效运维社区(GreatOPS)和开放运维联盟(OOPSA)联合主办,由工信部信通院数据中心联盟 ...
随机推荐
- Qt之中文显示(QMessageBox、QLineEdit右键菜单等)
来源:http://blog.sina.com.cn/s/blog_a6fb6cc90101art3.html 在编写Qt程序的时候,总会碰到中文问题,一直都很困惑,原本在使用QLineEdit的时候 ...
- memcached的安装(server、client)、magent整合
声明:本编文章基于网络上的文章(90%),基本就是把我的安装步骤写一下,遇到问题记录一下 1.背景:项目需要多台服务器负载均衡,我们的应用有付费会员,不能让一个账号随便登陆,一个时间段只能一个账号,这 ...
- 工控中的windows
今后的windows如何在工业应用中发展,之前的windows如何保证安全的运行,如果只专注于消费,生产上是否还需要windows,如果那样,windows真的只有windows了
- Glusterfs 分布式存储安装部署
Glusterfs 分布式存储部署 是存储当中可以选择的一种 现在很多虚拟化 云计算都在用软件存储 例如 ceph Glusterfs 等等 今天我们部署一下Glusterfs环境 GlusterFs ...
- 32位Intel CPU所含有的寄存器
4个数据寄存器(EAX.EBX.ECX和EDX)2个变址和指针寄存器(ESI和EDI) 2个指针寄存器(ESP和EBP)6个段寄存器(ES.CS.SS.DS.FS和GS)1个指令指针寄存器(EIP) ...
- php+redis实现电商秒杀功能
这一次总结和分享用Redis实现分布式锁来完成电商的秒杀功能.先扯点个人观点,之前我看了一篇博文说博客园的文章大部分都是分享代码,博文里强调说分享思路比分享代码更重要(貌似大概是这个意思,若有误请谅解 ...
- Properties集合
Map |--Hashtable |--Properties Properties集合特点: 1.该集合中的键和值都是字符串类型 2.集合中的数据可以保存在IO流中或者从IO流中获取数据. 通常该集合 ...
- SonarQube代码质量管理平台比较好的搭建和使用资料
http://www.voidcn.com/blog/lidujun1028/article/p-3831235.html Sonar (SonarQube)是一个开源平台,用于管理源代码的质量. ...
- C语言EOF
验证表达式getchar()!=EOF的值是1还是0 编写一个打印EOF值的程序 windows下是ctrl-z 就是ctrl和z一起按了,就是结束符linux下是ctrl-d是结束符.这个是一个 ...
- JS定时器的使用--数码时钟
<title>无标题文档</title> <script> function toDou(n){ if(n<10){ return '0'+n; }else{ ...