Debian Codegraph @

third_party/rust/bit-set/README.md

raw
1 <div align="center">
2 <h1>bit-set</h1>
3 <p>
4 <strong>A compact set of bits.</strong>
5 </p>
6 <p>
7
8 [![crates.io][crates.io shield]][crates.io link]
9 [![Documentation][docs.rs badge]][docs.rs link]
10 ![Rust CI][github ci badge]
11 [![rustc 1.0+]][Rust 1.0]
12 <br />
13 <br />
14 [![Dependency Status][deps.rs status]][deps.rs link]
15 [![Download Status][shields.io download count]][crates.io link]
16
17 </p>
18 </div>
19
20 [crates.io shield]: https://img.shields.io/crates/v/bit-set?label=latest
21 [crates.io link]: https://crates.io/crates/bit-set
22 [docs.rs badge]: https://docs.rs/bit-set/badge.svg?version=0.8.0
23 [docs.rs link]: https://docs.rs/bit-set/0.8.0/bit_set/
24 [github ci badge]: https://github.com/contain-rs/linked-hash-map/workflows/Rust/badge.svg?branch=master
25 [rustc 1.0+]: https://img.shields.io/badge/rustc-1.0%2B-blue.svg
26 [Rust 1.0]: https://blog.rust-lang.org/2015/05/15/Rust-1.0.html
27 [deps.rs status]: https://deps.rs/crate/bit-set/0.8.0/status.svg
28 [deps.rs link]: https://deps.rs/crate/bit-set/0.8.0
29 [shields.io download count]: https://img.shields.io/crates/d/bit-set.svg
30
31 ## Usage
32
33 Add this to your Cargo.toml:
34
35 ```toml
36 [dependencies]
37 bit-set = "0.8"
38 ```
39
40 Since Rust 2018, `extern crate` is no longer mandatory. If your edition is old (Rust 2015),
41 add this to your crate root:
42
43 ```rust
44 extern crate bit_set;
45 ```
46
47 If you want to use `serde`, enable it with the `serde` feature:
48
49 ```toml
50 [dependencies]
51 bit-set = { version = "0.8", features = ["serde"] }
52 ```
53
54 If you want to use bit-set in a program that has `#![no_std]`, just drop default features:
55
56 ```toml
57 [dependencies]
58 bit-set = { version = "0.8", default-features = false }
59 ```
60
61 <!-- cargo-rdme start -->
62
63 ### Description
64
65 An implementation of a set using a bit vector as an underlying
66 representation for holding unsigned numerical elements.
67
68 It should also be noted that the amount of storage necessary for holding a
69 set of objects is proportional to the maximum of the objects when viewed
70 as a `usize`.
71
72 ### Examples
73
74 ```rust
75 use bit_set::BitSet;
76
77 // It's a regular set
78 let mut s = BitSet::new();
79 s.insert(0);
80 s.insert(3);
81 s.insert(7);
82
83 s.remove(7);
84
85 if !s.contains(7) {
86 println!("There is no 7");
87 }
88
89 // Can initialize from a `BitVec`
90 let other = BitSet::from_bytes(&[0b11010000]);
91
92 s.union_with(&other);
93
94 // Print 0, 1, 3 in some order
95 for x in s.iter() {
96 println!("{}", x);
97 }
98
99 // Can convert back to a `BitVec`
100 let bv = s.into_bit_vec();
101 assert!(bv[3]);
102 ```
103
104 <!-- cargo-rdme end -->
105
106 ## License
107
108 Dual-licensed for compatibility with the Rust project.
109
110 Licensed under the Apache License Version 2.0: http://www.apache.org/licenses/LICENSE-2.0,
111 or the MIT license: http://opensource.org/licenses/MIT, at your option.