[][src]Struct hypercore::bitfield::SparseBitfield

pub struct SparseBitfield {
    pub pages: Pager,
    // some fields omitted
}

Bitfield instance.

Fields

pages: Pager

A memory-pager instance.

Implementations

impl Bitfield[src]

pub fn new(page_size: usize) -> Bitfield[src]

Create a new instance.

Panics

The page size must be a multiple of 2, and bigger than 0.

pub fn from_file(
    file: &mut File,
    page_size: usize,
    offset: Option<usize>
) -> Result<Bitfield, Error>
[src]

Create a new instance from a File.

pub fn set(&mut self, index: usize, value: bool) -> Change[src]

Set a bit to true or false. Returns a boolean indicating if the value was changed.

pub fn get(&mut self, index: usize) -> bool[src]

Get the value of a bit.

pub fn get_byte(&self, index: usize) -> u8[src]

Get a byte from our internal buffers.

pub fn set_byte(&mut self, index: usize, byte: u8) -> Change[src]

Set a byte to the right value inside our internal buffers.

pub fn page_size(&self) -> usize[src]

Get the memory page size in bytes.

pub fn len(&self) -> usize[src]

Get the amount of bits in the bitfield.

Examples

let mut bits = Bitfield::new(1024);
assert_eq!(bits.len(), 0);
bits.set(0, true);
assert_eq!(bits.len(), 8);
bits.set(1, true);
assert_eq!(bits.len(), 8);
bits.set(9, false);
assert_eq!(bits.len(), 16);

pub fn byte_len(&self) -> usize[src]

Get the amount of bytes in the bitfield.

Examples

let mut bits = Bitfield::new(1024);
assert_eq!(bits.byte_len(), 0);
bits.set(0, true);
assert_eq!(bits.byte_len(), 1);
bits.set(1, true);
assert_eq!(bits.byte_len(), 1);
bits.set(9, false);
assert_eq!(bits.byte_len(), 2);

pub fn page_len(&self) -> usize[src]

Get the amount of memory pages in the bitfield.

Examples

let mut bits = Bitfield::new(1024);
assert_eq!(bits.page_len(), 0);
bits.set(0, true);
assert_eq!(bits.page_len(), 1);
bits.set(1, true);
assert_eq!(bits.page_len(), 1);
bits.set(2, false);
assert_eq!(bits.page_len(), 1);
bits.set(1024 * 8 + 1, true);
assert_eq!(bits.page_len(), 2);

pub fn is_empty(&self) -> bool[src]

Returns true if no bits are stored.

Examples

let mut bits = Bitfield::new(1024);
assert!(bits.is_empty());
bits.set(0, true);
assert!(!bits.is_empty());

pub fn iter(&mut self) -> Iter[src]

Create an Iterator that iterates over all pages.

pub fn to_bytes(&self) -> Result<Vec<u8>, Error>[src]

Trait Implementations

impl Debug for Bitfield[src]

impl Default for Bitfield[src]

Create a new instance with a page_size of 1kb.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Clear for T where
    T: InitializableFromZeroed + ?Sized

impl<T> From<T> for T[src]

impl<T> InitializableFromZeroed for T where
    T: Default

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,