bin-pool 0.1.1

A small crate for interning binary slices.
Documentation
  • Coverage
  • 100%
    18 out of 18 items documented1 out of 15 items with examples
  • Size
  • Source code size: 31.79 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.39 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • dragazo/bin-pool
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • dragazo

bin-pool is a small crate for interning binary slices. A type called [BinPool] is provided which represents a collection of binary slices; however, the content is highly optimized for space by allowing slices to overlap in memory. The data is backed by a smaller subset of "large" slices that have been added previously.

Note that interning is not a cheap operation, and in the worst case every backing slice must be examined when adding a new slice. Interning is only recommended when memory is very limited, or for storage optimization in areas where time is not critical (e.g., compiler output).

Example

# use bin_pool::*;
let mut b = BinPool::new();

b.add(b"hello world".as_slice());  // add first slice - backed by itself
b.add(b"hello".as_slice());        // add another slice - backed by first
b.add(b"world".as_slice());        // add another slice - backed by first
assert_eq!(b.bytes(), 21);         // 21 bytes stored
assert_eq!(b.backing_bytes(), 11); // but only 11 bytes needed to represent them

b.add(b"hello world!".as_slice()); // add another slice - becomes the backer for others
assert_eq!(b.bytes(), 33);         // now 33 bytes stored
assert_eq!(b.backing_bytes(), 12); // but only 12 bytes to represent them

no_std

bin-pool supports building in no_std environments by disabling default features. Note that the alloc crate is required.

[dependencies]
bin-pool = { version = "...", default-features = false }