Trait bitstring::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

Get the ndxth bit.

Panics

Should panic if ndx >= self.len().

Set the ndxth bit to bit.

Might clip the length to ndx+1.

Panics

Should panic if ndx >= self.len().

Flips the ndxth bit.

Panics

Should panic if ndx >= self.len().

Current length of the bit string in bits.

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.

Append a bit.

Panics

Might panic if underlying storage can only store a limited number of bits.

Create a new zero-length bit string.

Underlying storage should be zeroed 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.

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.

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]`

Implementors