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

An ID List of u64 values, that uses a compressed representation of u64 to speed up set operations, improve cpu cache behaviour and consume less memory.

This is essentially a Vec<u64>, but requires less storage with large values and natively supports logical operations for set manipulation. Today this supports And, Or, AndNot. Future types may be added such as xor.

Examples

use idlset::v2::IDLBitRange;
use std::iter::FromIterator;

let idl_a = IDLBitRange::from_iter(vec![1, 2, 3]);
let idl_b = IDLBitRange::from_iter(vec![2]);

// Conduct an and (intersection) of the two lists to find commont members.
let idl_result = idl_a & idl_b;

let idl_expect = IDLBitRange::from_iter(vec![2]);
assert_eq!(idl_result, idl_expect);

Implementations

Construct a new, empty set.

Construct a set containing a single initial value. This is a special use case for database indexing where single value equality indexes are store uncompressed on disk.

Show if this IDL set contains no elements

Show if this data set is sparsely packed.

Show if this data set is compressed.

Returns the number of ids in the set. This operation iterates over the set, decompressing it to count the ids, which MAY be slow. If you want to see if the set is empty, us is_empty()

Returns if the number of ids in this set exceed this threshold. While this must iterate to determine if this is true, since we shortcut return in the check, on long sets we will not iterate over the complete content making it faster than len() < thresh.

Returns true if the set is smaller than threshold.

Sum all the values contained into this set to yield a single result.

Returns true if the id u64 value exists within the set.

Push an id into the set. The value is appended onto the tail of the set. You probably want insert_id instead.

Safety

Failure to insert sorted data will corrupt the set, and cause subsequent set operations to yield incorrect and inconsistent results.

Insert an id into the set, correctly sorted.

Remove an id from the set, leaving it correctly sorted.

If the value is not present, no action is taken.

Compress this IDL set. This may be needed if you wish to force a set to be compressed, even if the adaptive behaviour has not compressed it for you.

If it is viable, attempt to compress this IDL. This operation will scan the full IDL, so it’s not recommended to call this frequently. Generally the use of from_iter will already make the correct decision for you.

Trait Implementations

Perform an AndNot (exclude) operation between two sets. This returns a new set containing the results. The set on the right is the candidate set to exclude from the set of the left.

Examples
// Note the change to import the AndNot trait.
use idlset::{v2::IDLBitRange, AndNot};

let idl_a = IDLBitRange::from_iter(vec![1, 2, 3]);
let idl_b = IDLBitRange::from_iter(vec![2]);

let idl_result = idl_a.andnot(idl_b);

let idl_expect = IDLBitRange::from_iter(vec![1, 3]);
assert_eq!(idl_result, idl_expect);
// Note the change to import the AndNot trait.
use idlset::{v2::IDLBitRange, AndNot};

let idl_a = IDLBitRange::from_iter(vec![1, 2, 3]);
let idl_b = IDLBitRange::from_iter(vec![2]);

// Note how reversing a and b here will return an empty set.
let idl_result = idl_b.andnot(idl_a);

let idl_expect = IDLBitRange::new();
assert_eq!(idl_result, idl_expect);

The type of set implementation to return.

Perform an AndNot (exclude) operation between two sets. This returns a new set containing the results. The set on the right is the candidate set to exclude from the set of the left.

Examples
// Note the change to import the AndNot trait.
use idlset::{v2::IDLBitRange, AndNot};

let idl_a = IDLBitRange::from_iter(vec![1, 2, 3]);
let idl_b = IDLBitRange::from_iter(vec![2]);

let idl_result = idl_a.andnot(idl_b);

let idl_expect = IDLBitRange::from_iter(vec![1, 3]);
assert_eq!(idl_result, idl_expect);
// Note the change to import the AndNot trait.
use idlset::{v2::IDLBitRange, AndNot};

let idl_a = IDLBitRange::from_iter(vec![1, 2, 3]);
let idl_b = IDLBitRange::from_iter(vec![2]);

// Note how reversing a and b here will return an empty set.
let idl_result = idl_b.andnot(idl_a);

let idl_expect = IDLBitRange::new();
assert_eq!(idl_result, idl_expect);

The type of set implementation to return.

Perform an And (intersection) operation between two sets. This returns a new set containing the results.

Examples
let idl_a = IDLBitRange::from_iter(vec![1, 2, 3]);
let idl_b = IDLBitRange::from_iter(vec![2]);

let idl_result = idl_a & idl_b;

let idl_expect = IDLBitRange::from_iter(vec![2]);
assert_eq!(idl_result, idl_expect);

The resulting type after applying the & operator.

Perform an And (intersection) operation between two sets. This returns a new set containing the results.

Examples
let idl_a = IDLBitRange::from_iter(vec![1, 2, 3]);
let idl_b = IDLBitRange::from_iter(vec![2]);

let idl_result = idl_a & idl_b;

let idl_expect = IDLBitRange::from_iter(vec![2]);
assert_eq!(idl_result, idl_expect);

The resulting type after applying the & operator.

Perform an Or (union) operation between two sets. This returns a new set containing the results.

Examples
let idl_a = IDLBitRange::from_iter(vec![1, 2, 3]);
let idl_b = IDLBitRange::from_iter(vec![2]);

let idl_result = idl_a | idl_b;

let idl_expect = IDLBitRange::from_iter(vec![1, 2, 3]);
assert_eq!(idl_result, idl_expect);

The resulting type after applying the | operator.

Perform an Or (union) operation between two sets. This returns a new set containing the results.

Examples
let idl_a = IDLBitRange::from_iter(vec![1, 2, 3]);
let idl_b = IDLBitRange::from_iter(vec![2]);

let idl_result = idl_a | idl_b;

let idl_expect = IDLBitRange::from_iter(vec![1, 2, 3]);
assert_eq!(idl_result, idl_expect);

The resulting type after applying the | operator.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Construct a new, empty set.

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

Build an IDLBitRange from at iterator. If you provide a sorted input, a fast append mode is used. Unsorted inputs use a slower insertion sort method instead. Based on the provided input, this will adaptively choose sparse or compressed storage of the dataset.

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

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

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

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

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

Converts the given value to a String. 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.