位集或具有位图按位运算的本机数据类型?
我想实现 64 位、128 位和 256 位的位图。我正在考虑为这三个人使用专门的课程。我需要设置这些位并查找它们。位集不是动态的,将使用 64、128 和 256 位的静态实现。
与使用 long long 等本机类型以及使用按位运算操作位相比,使用 c++ 位集有何优缺点?
在初始化或任何其他因素中使用位集是否有任何开销?
谢谢
I would like to implement bitmaps of 64 bits, 128 bits and 256 bits. I was thinking of using specialized classes for these three. I need to set the bits and also look them up. The bitset will not be dynamic, static implementations of 64, 128 and 256 bits will be used.
What are the pros and cons of using the c++ bitset over using a native type like long long and manipulating the bits using bitwise operations?
Is there any overhead in using bitset in initialization or in any other factor?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,标准位集中肯定存在一些开销。您的实施将会更快(但您需要投入一些精力进行编码并使其高效且无错误)。
然而,我会使用标准位集,并且不会与该开销作斗争,直到这是一个经过验证的瓶颈。您知道人们经常引用的关于过早优化的说法吗?
Well, definitely there is some overhead in standard bitsets. Your implementation is going to be faster (but you need to invest some effort in coding it and making it efficient and bug-free).
I would however use standard bitsets and not fight against that overhead until this is a proven bottleneck. You know the often cited saying about about premature optimization, right?