[−][src]Struct hypercore::bitfield::SparseBitfield
Bitfield instance.
Fields
pages: Pager
A memory-pager instance.
Implementations
impl Bitfield
[src]
pub fn new(page_size: usize) -> Bitfield
[src]
pub fn from_file(
file: &mut File,
page_size: usize,
offset: Option<usize>
) -> Result<Bitfield, Error>
[src]
file: &mut File,
page_size: usize,
offset: Option<usize>
) -> Result<Bitfield, Error>
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]
Based on Bitfield.prototype.toBuffer
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
impl RefUnwindSafe for Bitfield
impl Send for Bitfield
impl Sync for Bitfield
impl Unpin for Bitfield
impl UnwindSafe for Bitfield
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Clear for T where
T: InitializableFromZeroed + ?Sized,
T: InitializableFromZeroed + ?Sized,
fn clear(&mut self)
impl<T> From<T> for T
[src]
impl<T> InitializableFromZeroed for T where
T: Default,
T: Default,
unsafe fn initialize(place: *mut T)
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,