Trait bitstring::bit_string::BitString [−][src]
pub trait BitString {
fn get(&self, ndx: usize) -> bool;
fn set(&mut self, ndx: usize, bit: bool);
fn flip(&mut self, ndx: usize);
fn len(&self) -> usize;
fn clip(&mut self, len: usize);
fn append(&mut self, bit: bool);
fn null() -> Self;
fn shared_prefix_len(&self, other: &Self) -> usize { ... }
fn shared_prefix(&self, other: &Self) -> Self
where
Self: Clone,
{ ... }
fn subset_cmp(&self, other: &Self) -> Option<Ordering> { ... }
fn lexicographic_cmp(&self, other: &Self) -> Ordering { ... }
}
Expand description
A bit string with variable (but possibly limited) length.
The length limit might depend on the current string; that is why writing a bit might truncate the string (but not the bit that was just modified). “Writing” a bit also includes writing without actually changing it.
This special case is needed to handle variants with different (maximum) lengths: a small prefix indicates the variant, then follows the actual data of the variant.
As an example one might want to combine IPv4 and IPv6 cidr
representations into one BitString
type; the empty bit string
would represent 0.0.0.0/0
+ ::/0
.
Apart from this special case writing a bit must not modify any other bits or change the length.
Required methods
Set current length to len
.
Does nothing if len <= self.len()
.
If necessary should also zero the underlying storage if Eq
needs it to work properly.
Provided methods
Length of the longest shared prefix of two bit strings.
Longest shared prefix of two bit strings.
fn subset_cmp(&self, other: &Self) -> Option<Ordering>
fn subset_cmp(&self, other: &Self) -> Option<Ordering>
Partial ordering on bit strings.
Formal definition:
`a < b` iff `a != b` and `b` is a prefix of `a`
If you view a bit string as a set including all bit strings starting with it, this is the subset relation.
fn lexicographic_cmp(&self, other: &Self) -> Ordering
fn lexicographic_cmp(&self, other: &Self) -> Ordering
Lexicographic ordering on bit strings.
Formal definition:
`a < b` iff `a != b` and (
`b` is a prefix of `a`
or `a[s] < b[s]`
where s is the smallest index with `a[s] != b[s]`)
Or, if you define _|_ < false < true
:
`a < b` iff `a[s] < b[s]`
where s is the smallest index with `a[s] != b[s]`