pub struct CompactVector { /* private fields */ }
Expand description

Compact vector in which each integer is represented in a fixed number of bits.

Examples

use sucds::CompactVector;

let cv = CompactVector::from_slice(&[5, 256, 0, 10]);

assert_eq!(cv.get(0), 5);
assert_eq!(cv.get(1), 256);
assert_eq!(cv.get(2), 0);
assert_eq!(cv.get(3), 10);

assert_eq!(cv.len(), 4);
assert_eq!(cv.width(), 9);

let mut bytes = vec![];
let size = cv.serialize_into(&mut bytes).unwrap();
let other = CompactVector::deserialize_from(&bytes[..]).unwrap();
assert_eq!(cv, other);
assert_eq!(size, bytes.len());
assert_eq!(size, cv.size_in_bytes());

Implementations

Creates a new empty CompactVector.

Arguments
  • width: Number of bits to represent an integer.

Creates a new CompactVector of len integers.

Arguments
  • len: Number of integers to be stored.
  • width: Number of bits to represent an integer.

Creates a new CompactVector that capa integers are reserved.

Arguments
  • capa: Number of integers to be reserved.
  • width: Number of bits to represent an integer.

Creates a new CompactVector from a slice of integers.

Arguments
  • ints: Integers to be stored.
Examples
use sucds::CompactVector;

let cv = CompactVector::from_slice(&[5, 256, 0, 10]);
assert_eq!(cv.get(0), 5);
assert_eq!(cv.get(1), 256);
assert_eq!(cv.get(2), 0);
assert_eq!(cv.get(3), 10);

Serializes the data structure into the writer, returning the number of serialized bytes.

Arguments
  • writer: std::io::Write variable.

Deserializes the data structure from the reader.

Arguments
  • reader: std::io::Read variable.

Returns the number of bytes to serialize the data structure.

Gets the pos-th integer.

Arguments
  • pos: Position.
Examples
use sucds::CompactVector;

let cv = CompactVector::from_slice(&[5, 256, 0, 10]);
assert_eq!(cv.get(0), 5);
assert_eq!(cv.get(1), 256);
assert_eq!(cv.get(2), 0);
assert_eq!(cv.get(3), 10);

Sets the pos-th integer to value.

Arguments
  • pos: Position.
  • value: Integer to be set.
Examples
use sucds::CompactVector;

let mut cv = CompactVector::with_len(2, 8);
cv.set(0, 10);
cv.set(1, 255);
assert_eq!(cv.get(0), 10);
assert_eq!(cv.get(1), 255);

Pushes integer value at the end.

Arguments
  • value: Integer to be set.
Examples
use sucds::CompactVector;

let mut cv = CompactVector::new(8);
cv.push(10);
cv.push(255);
assert_eq!(cv.get(0), 10);
assert_eq!(cv.get(1), 255);

Gets the number of ints.

Checks if the vector is empty.

Gets the number of bits to represent an integer.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.