#bit-set

bittyset

用于操作位集的 BitSet 类型

2 个版本

新版本 0.1.1 2024年8月13日
0.1.0 2020年10月18日

数据结构 中排名第 462

Download history 96/week @ 2024-08-08

每月下载量 96

MIT 许可证

32KB
603

bittyset

crates.io docs.rs

用于操作位集的 BitSet

本项目旨在取代不再活跃开发中的 bit-set

目标

  • 友好的 API。
  • 性能。
bit-set 的性能比较
test insert/bit_set ... bench:       55976 ns/iter (+/- 2456)
test insert/bittyset ... bench:       19206 ns/iter (+/- 1622)

test remove/bit_set ... bench:       26914 ns/iter (+/- 975)
test remove/bittyset ... bench:        9013 ns/iter (+/- 359)

test contains/bit_set ... bench:        8498 ns/iter (+/- 175)
test contains/bittyset ... bench:        4200 ns/iter (+/- 34)

test union/bit_set ... bench:        2897 ns/iter (+/- 483)
test union/bittyset ... bench:        1670 ns/iter (+/- 272)

test intersection/bit_set ... bench:        2654 ns/iter (+/- 130)
test intersection/bittyset ... bench:        1968 ns/iter (+/- 188)

test difference/bit_set ... bench:        2835 ns/iter (+/- 226)
test difference/bittyset ... bench:        1712 ns/iter (+/- 254)

test symmetric_difference/bit_set ... bench:        2616 ns/iter (+/- 131)
test symmetric_difference/bittyset ... bench:        1956 ns/iter (+/- 188)

test is_subset/bit_set ... bench:          88 ns/iter (+/- 19)
test is_subset/bittyset ... bench:          87 ns/iter (+/- 21)

test is_subset(self)/bit_set ... bench:        1344 ns/iter (+/- 95)
test is_subset(self)/bittyset ... bench:          33 ns/iter (+/- 10)

安装

将以下行添加到您的 Cargo.toml 文件中,

[dependencies]
# ...
bittyset = "0.1.0"

cargo-edit 强烈推荐用于管理项目依赖。安装 cargo-edit 后,运行以下命令,

cargo add bittyset

示例

use bittyset::{BitSet, bitset};

// Create an empty BitSet. We use this turbofish form to make compiler happy,
// otherwise we have to write something like `BitSet::<usize>::new()`.
let mut set1 = <BitSet>::new();
assert!(set1.is_empty());

// Insert one element.
set1.insert(76);

// Make use of the Extend trait.
set1.extend(vec![47, 20, 5, 11]);

// Remove an element.
set1.remove(20);

// Create a BitSet with the convenience macro `bitset!`.
let set2 = bitset![5, 12, 47, 104];

// Compute the union of two sets.
assert_eq!(&set1 | &set2, bitset![5, 11, 12, 47, 76, 104]);

// Compute the intersection of two sets.
assert_eq!(&set1 & &set2, bitset![5, 47]);

// Compute the difference of two sets.
assert_eq!(&set1 - &set2, bitset![11, 76]);

// Iterate over the set, producing `usize`s.
for x in set1.iter() {
  println!("{}", x);
}

依赖

~0.6–1MB
~23K SLoC