#bitset #bitmask #bit-array #bitmap #set-bit #bitslice

无std bitset-core

简单、与无std兼容、simd优化、BitSet API

2个版本

0.1.1 2020年9月19日
0.1.0 2020年7月9日

数据结构 中排名 952

Download history 367/week @ 2024-03-14 697/week @ 2024-03-21 769/week @ 2024-03-28 499/week @ 2024-04-04 609/week @ 2024-04-11 657/week @ 2024-04-18 344/week @ 2024-04-25 387/week @ 2024-05-02 462/week @ 2024-05-09 538/week @ 2024-05-16 622/week @ 2024-05-23 786/week @ 2024-05-30 761/week @ 2024-06-06 699/week @ 2024-06-13 594/week @ 2024-06-20 612/week @ 2024-06-27

每月下载量 2,877
用于 9 包(直接使用2个)

MIT 许可证

32KB
796

BitSet

MIT License crates.io docs.rs

简单、与无std兼容、simd优化、BitSet API。

示例

此crate通过BitSet trait提供其功能。

use bitset_core::BitSet;

此crate提供的bitset容器是无符号整数、无符号整数的切片以及类似simd的类型,以及当std功能启用时(默认启用)的Vec<_>Box<[_]>

use bitset_core::BitSet;

let mut bits = [0u32; 4];
assert_eq!(bits.bit_len(), 4 * 32);

bits.bit_init(true); // Set all bits to true
assert!(bits.bit_all()); // All bits are set

bits.bit_reset(13); // Reset the 13th bit
assert!(bits.bit_any()); // At least some bits are set

bits.bit_flip(42); // Flip the 42nd bit twice (no change)
bits.bit_flip(42);

bits.bit_cond(1, false); // Set the bit to runtime value

assert_eq!(bits.bit_test(42), true);
assert_eq!(bits.bit_test(13), false);
assert_eq!(bits.bit_test(1), false);

assert_eq!(bits.bit_count(), 4 * 32 - 2);

通过使用底层原语(如[u32; 4])进行simd优化,这些原语与硬件的128位simd寄存器匹配。强烈鼓励编译器对这些原语进行向量化。

use bitset_core::BitSet;

let mut a = [[0x21212121u32; 4]; 16];
let b = [[0x55555555u32; 4]; 16];

a.bit_or(&b);
a.bit_and(&b);
a.bit_xor(&b);
a.bit_not();

assert_eq!(a, [[0xffffffffu32; 4]; 16]);

对于使用std功能的非固定大小容器,还实现了BitSet,用于Vec<T>Box<[T]>(其中[T]BitSet)。

未来的工作包括使所有内容都成为const fn,以在编译时启用所有这些功能,但受到const fn中对特质的支持的阻碍。

许可证

MIT许可证下许可,请参阅license.txt

贡献

除非你明确声明,否则你提交的任何有意包含在作品中的贡献,均应按上述方式许可,不得附加任何其他条款或条件。

无运行时依赖

功能