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 *;
let mut b = new;
b.add; // add first slice - backed by itself
b.add; // add another slice - backed by first
b.add; // add another slice - backed by first
assert_eq!; // 21 bytes stored
assert_eq!; // but only 11 bytes needed to represent them
b.add; // add another slice - becomes the backer for others
assert_eq!; // now 33 bytes stored
assert_eq!; // 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.
[]
= { = "...", = false }