1 个不稳定版本
| 0.1.1 | 2023年4月11日 |
|---|---|
| 0.1.0 |
|
7 在 #bit-array
25KB
539 代码行
位向量。
一个动态大小的 bit 数组,其底层实现为 Vec<u8>,旨在灵活地存储大量 bool 类型,以更小的空间。
- 注意,这不包括压缩算法。
- 使用位操作进行操作。
信息
示例
use bits_array::BitsArray;
let mut a = BitsArray::from([true, false, true, true, false]);
assert_eq!(a.get(4), Some(false));
assert_eq!(a.get(5), None);
assert_eq!(format!("{:b}", &a), "[10110000]");
a.push(true);
assert_eq!(format!("{:b}", &a), "[10110100]");
a.extend(a.clone());
assert_eq!(format!("{:b}", &a), "[10110110, 11010000]");
lib.rs:
示例
let mut a = BitsArray::from([true, false, true, true, false]);
assert_eq!(a.get(4), Some(false));
assert_eq!(a.get(5), None);
assert_eq!(format!("{:b}", &a), "[10110000]");
a.push(true);
assert_eq!(format!("{:b}", &a), "[10110100]");
a.extend(a.clone());
assert_eq!(format!("{:b}", &a), "[10110110, 11010000]");