unthbuf 1.0.0

Unsigned N-bit Buffer: A structure that holds a fixed buffer of `bits`-sized unsigned integer elements.
Documentation
  • Coverage
  • 100%
    45 out of 45 items documented1 out of 38 items with examples
  • Size
  • Source code size: 51.88 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 4.56 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Longor1996/unthbuf
    1 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Longor1996

UnthBuf

The UnthBuf is a data-structure that holds a fixed buffer of unsigned integers, just like a Box<[usize]> would... except that the bit-size of the integers can be adjusted from 1 to 64 bits, effectively making it a Box<[uN]>!

For example:

use unthbuf::{UnthBuf, Bits, aligned::AlignedLayout};
let mut buf = UnthBuf::<AlignedLayout>::new(4096, Bits::new(5).unwrap());
buf.set(21, 5).unwrap();

Internally the buffer is a boxed slice of usized cells, with the integer elements being stored within the cells according to the chosen [CellLayout].

This will result in a bit-pattern like this:

0101101101101101101101101101101101101101101101101101101101101101
0000000000000000000000000000000000000000000000000000000000000101
                            integer aligned to word boundary ^^^

Or, if the PackedLayout/[PackedUnthBuf] is used instead:

1101101101101101101101101101101101101101101101101101101101101101
^              integer packed across word boundary            vv
0000000000000000000000000000000000000000000000000000000000000010

While the PackedLayout is certainly more compact, it is also roughly ~20% slower; use it when every bit counts.

You can use the UnthBuf::get_padding_bit_count-function to determine how much space is lost.