用PHP表示一组位的最快方法?(Fastest way to represent a collection of bits in PHP?)

编程入门 行业动态 更新时间:2024-10-27 07:16:51
用PHP表示一组位的最快方法?(Fastest way to represent a collection of bits in PHP?)

代表一组比特的好方法是什么?

我有一组各种开/关切换(成千上万)并需要存储和检索其状态。 天真的实现将是一组布尔值,但我想知道是否有更好的方法(更好的访问速度和/或内存要求)。

我发现这个BitArray的实现,但是它限于32位,这对于这种情况是不够的。

What is a good way to represent a collection of bits?

I have a set of various on/off toggles (thousands of them) and need to store and retrieve their state. The naïve implementation would be an array of booleans, but I'm wondering if there's a better way (better in terms of access speed and/or memory requirements).

I've found this BitArray implementation, but it's limited to 32 bits, which is not enough for this case.

最满意答案

另一个选择是将它们以整数存储在PHP_INT_SIZE*8块中,并使用按位运算符来设置/取消设置它们。

我不能评论这种方法的速度或内存消耗,你可能需要做一些基准测试。

Another option is to store them in blocks of PHP_INT_SIZE*8 in integers and use bitwise operators to set/unset them.

I can't comment on speeds or memory consumption of this method, you may have to do some benchmarking.

更多推荐

本文发布于:2023-08-06 05:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1444615.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:最快   方法   PHP   Fastest   bits

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!