Struct mayda::monotone::Monotone [] [src]

pub struct Monotone<B> { /* fields omitted */ }

The type of a monotone encoded integer array. Designed for moderate compression and efficient decoding through the Encode trait, and efficient random access through the Access and AccessInto traits.

Support is provided for arrays with as many as (2^37 - 2^7) entries, or about 512 GiB of u32s. If your application requires more than that, you should probably be designing your own data structure anyway.

Examples

use mayda::{Access, Encode, Monotone};

let input: Vec<u32> = vec![1, 5, 7, 15, 20, 27];
let mut bits = Monotone::new();
bits.encode(&input).unwrap();

let length = bits.len();
assert_eq!(length, 6);

let output = bits.decode();
assert_eq!(input, output);

let value = bits.access(4);
assert_eq!(value, 20);

let range = bits.access(1..4);
assert_eq!(range, vec![5, 7, 15]);

Performance

Decoding does not allocate except for the return value, and decodes around 7.5 GiB/s of decoded integers on difficult inputs. Encoding allocates O(n) memory (n in the length of the array), and encodes around 4.5 GiB/s of decoded integers. Run cargo bench --bench monotone for performance numbers on your setup.

The performance (speed and compression) degrades gradually as the number of entries falls below 128.

Safety

As a general rule, you should not decode or access Monotone objects from untrusted sources.

A Monotone object performs unsafe pointer operations during encoding and decoding. Changing the header information with mut_storage can cause data to be written to or read from arbitrary addresses in memory.

That said, the situation is the same for any of the data structures in the standard library (consider the set_len method of a Vec).

Methods

impl<B: Bits> Monotone<B>
[src]

[src]

Creates an empty Monotone object.

Examples

use mayda::{Encode, Monotone};

let input: Vec<u32> = vec![1, 5, 7, 15, 20, 27];
let mut bits = Monotone::new();
bits.encode(&input).unwrap();

let bytes = std::mem::size_of_val(bits.storage());
assert_eq!(bytes, 16);

[src]

Creates a Monotone object that encodes the slice.

Examples

use mayda::{Encode, Monotone};

let input: Vec<u32> = vec![1, 5, 7, 15, 20, 27];
let bits = Monotone::from_slice(&input).unwrap();

let output = bits.decode();
assert_eq!(input, output);

[src]

Returns true when there are no encoded entries.

Examples

use mayda::Monotone;

let mut bits = Monotone::<u32>::new();
assert_eq!(bits.is_empty(), true);

[src]

Returns the number of encoded entries. Note that since the length has to be calculated, Monotone::len() is more expensive than Slice::len().

Examples

use mayda::{Encode, Monotone};

let input: Vec<u32> = vec![1, 5, 7, 15, 20, 27];
let mut bits = Monotone::new();
bits.encode(&input).unwrap();

assert_eq!(bits.len(), 6);

[src]

Exposes the word storage of the Monotone object.

Examples

use mayda::{Encode, Monotone};

let input: Vec<u32> = vec![1, 5, 7, 15, 20, 27];
let mut bits = Monotone::new();
bits.encode(&input).unwrap();

let storage = bits.storage();
assert_eq!(storage.len(), 4);

[src]

Exposes the mutable word storage of the Monotone object.

Safety

A Monotone object performs unsafe pointer operations during encoding and decoding. Changing the header information can cause data to be written to or read from arbitrary addresses in memory.

[src]

Returns the width of the encoded integer type.

Examples

use mayda::{Encode, Monotone};

let input: Vec<u32> = vec![1, 5, 7, 15, 20, 27];
let mut bits = Monotone::new();
bits.encode(&input).unwrap();

assert_eq!(bits.required_width(), 32);

Trait Implementations

impl<B: Clone> Clone for Monotone<B>
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<B: Debug> Debug for Monotone<B>
[src]

[src]

Formats the value using the given formatter. Read more

impl<B: Default> Default for Monotone<B>
[src]

[src]

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

impl<B: Hash> Hash for Monotone<B>
[src]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl<B: PartialEq> PartialEq for Monotone<B>
[src]

[src]

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

[src]

This method tests for !=.

impl<B: PartialOrd> PartialOrd for Monotone<B>
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

[src]

This method tests less than (for self and other) and is used by the < operator. Read more

[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<B: Bits> Encode<B> for Monotone<B>
[src]

[src]

Encodes the slice into the Encode object. Read more

[src]

Decodes the contents of the Encode object. Returns a vector because ownership of the returned value must be given to the caller. Read more

[src]

Decodes the contents of the Encode object and writes the result into the slice provided. More efficient than decode if the slice is already allocated. Returns the number of decoded entries. Read more

impl<B: Bits> Access<usize> for Monotone<B>
[src]

The type returned by the access operation.

[src]

The method for the access foo.access(bar) operation.

impl<B: Bits> Access<Range<usize>> for Monotone<B>
[src]

The type returned by the access operation.

[src]

The method for the access foo.access(bar) operation.

impl<B: Bits> Access<RangeFrom<usize>> for Monotone<B>
[src]

The type returned by the access operation.

[src]

The method for the access foo.access(bar) operation.

impl<B: Bits> Access<RangeTo<usize>> for Monotone<B>
[src]

The type returned by the access operation.

[src]

The method for the access foo.access(bar) operation.

impl<B: Bits> Access<RangeFull> for Monotone<B>
[src]

The type returned by the access operation.

[src]

The method for the access foo.access(bar) operation.

impl<B: Bits> Access<RangeInclusive<usize>> for Monotone<B>
[src]

The type returned by the access operation.

[src]

The method for the access foo.access(bar) operation.

impl<B: Bits> Access<RangeToInclusive<usize>> for Monotone<B>
[src]

The type returned by the access operation.

[src]

The method for the access foo.access(bar) operation.

impl<B: Bits> AccessInto<Range<usize>, B> for Monotone<B>
[src]

[src]

The method for the access foo.access_into(bar, slice) operation.

impl<B: Bits> AccessInto<RangeFrom<usize>, B> for Monotone<B>
[src]

[src]

The method for the access foo.access_into(bar, slice) operation.

impl<B: Bits> AccessInto<RangeTo<usize>, B> for Monotone<B>
[src]

[src]

The method for the access foo.access_into(bar, slice) operation.

impl<B: Bits> AccessInto<RangeFull, B> for Monotone<B>
[src]

[src]

The method for the access foo.access_into(bar, slice) operation.

impl<B: Bits> AccessInto<RangeInclusive<usize>, B> for Monotone<B>
[src]

[src]

The method for the access foo.access_into(bar, slice) operation.

impl<B: Bits> AccessInto<RangeToInclusive<usize>, B> for Monotone<B>
[src]

[src]

The method for the access foo.access_into(bar, slice) operation.

Auto Trait Implementations

impl<B> Send for Monotone<B> where
    B: Send

impl<B> Sync for Monotone<B> where
    B: Sync