https://github.com/irrustible/rle-bitset
A no-std compatible trait for querying and manipulating bits in a slice of usize and iterating their run lengths.
https://github.com/irrustible/rle-bitset
Last synced: 5 days ago
JSON representation
A no-std compatible trait for querying and manipulating bits in a slice of usize and iterating their run lengths.
- Host: GitHub
- URL: https://github.com/irrustible/rle-bitset
- Owner: irrustible
- License: mpl-2.0
- Created: 2020-08-12T10:56:11.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2020-08-15T06:08:50.000Z (over 4 years ago)
- Last Synced: 2025-04-01T14:21:18.057Z (25 days ago)
- Language: Rust
- Size: 9.77 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rle-bitset
[](https://github.com/irrustible/rle-bitset/blob/main/LICENSE)
[](https://crates.io/crates/rle-bitset)
[](https://docs.rs/rle-bitset)A no-std, no-alloc trait for querying and manipulating bits in a
[`[usize]`] and iterating their run lengths.## Usage
```rust
use rle_bitset::*;#[test]
fn one_two() {
let mut x: [usize; 4] = [0, 0, 0, 0];
let over = WORD_WIDTH * 4;
x.set_bit(WORD_WIDTH, true).unwrap();
assert_eq!(x.get_bit(WORD_WIDTH).unwrap(), true);
{
let mut iter = x.run_lengths(..).unwrap();
assert_eq!(Some(RL::new(false, 0, WORD_WIDTH)), iter.next());
assert_eq!(Some(RL::new(true, WORD_WIDTH, WORD_WIDTH + 1)), iter.next());
assert_eq!(Some(RL::new(false, WORD_WIDTH + 1, over)), iter.next());
assert_eq!(None, iter.next());
}
x.set_bit(WORD_WIDTH - 1, true).unwrap();
assert_eq!(x.get_bit(WORD_WIDTH - 1).unwrap(), true);
{
let mut iter = x.run_lengths(..).unwrap();
assert_eq!(Some(RL::new(false, 0, WORD_WIDTH - 1)), iter.next());
assert_eq!(Some(RL::new(true, WORD_WIDTH -1, WORD_WIDTH + 1)), iter.next());
assert_eq!(Some(RL::new(false, WORD_WIDTH + 1, over)), iter.next());
assert_eq!(None, iter.next());
}
}
```## Copyright and License
Copyright (c) 2020 James Laver, rle-bitset contributors
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.