Struct sparse_bitfield::Bitfield[][src]

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

Bitfield instance.

Fields

A memory-pager instance.

Methods

impl Bitfield
[src]

Create a new instance.

Panics

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

Create a new instance from a File.

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

Get the value of a bit.

Get a byte from our internal buffers.

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

Get the memory page size in bytes.

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);

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);

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);

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());

Important traits for Iter<'a>

Create an Iterator that iterates over all pages.

Trait Implementations

impl Debug for Bitfield
[src]

Formats the value using the given formatter. Read more

impl Default for Bitfield
[src]

Create a new instance with a page_size of 1kb.

Returns the "default value" for a type. Read more

Auto Trait Implementations

impl Send for Bitfield

impl Sync for Bitfield