pub struct BinPool { /* private fields */ }
Expand description
An append-only pool of auto-overlapping binary slices.
In use, you add binary slices one at a time and it will attempt to create maximum overlapping. Currently, it only guarantees that supersets and subsets will overlap. It’s theoretically possible to do cross-slice overlapping, but this would be complex and even more expensive.
Slices added to the pool are guaranteed to remain in insertion order.
Moreover, the collection is append-only, so once a slice is added it will remain at the same index for the lifetime of the BinPool
.
Implementations§
source§impl BinPool
impl BinPool
sourcepub fn add<'a, T>(&mut self, value: T) -> usizewhere
T: Into<Cow<'a, [u8]>>,
pub fn add<'a, T>(&mut self, value: T) -> usizewhere T: Into<Cow<'a, [u8]>>,
Adds the specified slice to the pool.
If an equivalent slice already exists, does nothing and returns the index of the pre-existing slice;
otherwise, adds value
as a new slice and returns its (new) slice index.
If you are working with strings, you may find str::as_bytes
and [String::into_bytes
] useful.
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Removes all content from the pool. This is the only non-append-only operation, and is just meant to support resource reuse.
sourcepub fn iter(&self) -> Iter<'_> ⓘ
pub fn iter(&self) -> Iter<'_> ⓘ
Iterates over all (distinct) slices contained in the pool in insertion order.
sourcepub fn get(&self, index: usize) -> Option<&[u8]>
pub fn get(&self, index: usize) -> Option<&[u8]>
Gets the slice at the specified index, or None
if index
is not a valid slice index returned by BinPool::add
.
sourcepub fn bytes(&self) -> usize
pub fn bytes(&self) -> usize
Gets the total number of bytes from (distinct) slices that were added to the pool.
Note that the space needed to represent these slices may be significantly smaller (see BinPool::backing_bytes
).
sourcepub fn backing_bytes(&self) -> usize
pub fn backing_bytes(&self) -> usize
Gets the total number of bytes backing the stored slices.