Struct ranged_set::RangedSet [] [src]

pub struct RangedSet<T: Step + Clone + Ord> { /* fields omitted */ }

A set that stores values in contiguous ranges

RangedSet stores numeric values (or values that implement the Step trait) in ranges to conserve space.

When is using RangedSet a good idea?

RangedSet should be used when you need to store a lot of values that are contiguous. The example given in the module stored values whose Collatz sequence converged. It iterated from 1 up to u64::MAX and stored values it that converged in a cache. Most of these numbers are contiguous. Definitely all the values below the current number do.

Example

use ranged_set::RangedSet;

let mut rs = RangedSet::new();

for i in 0..65_535 {
    rs.insert(i);
}

// There's no way to check here in the code, but the memory consumed
// here should be enough for a Vec<i32>, an enum discriminant, and
// two i32's.

Methods

impl<T: Step + Clone + Ord> RangedSet<T>
[src]

Returns a new empty set

Example

use ranged_set::RangedSet;
let mut set: RangedSet<i32> = RangedSet::new();

Returns true if the set contains a value.

Example

use ranged_set::RangedSet;

let mut set = RangedSet::new();
set.insert(0);
set.insert(1);
set.insert(2);

assert_eq!(set.contains(&0), true);
assert_eq!(set.contains(&3), false);

Adds a value to the set

If the set did not have this value present, true is returned. If the set did have this value present, false is returned.

Example

use ranged_set::RangedSet;

let mut set = RangedSet::new();
assert_eq!(set.insert(1), true);
assert_eq!(set.insert(1), false);

Removes and returns a value from the set

Example

use ranged_set::RangedSet;

let mut set = RangedSet::new();
set.insert(0);
set.insert(1);
set.insert(2);

assert_eq!(set.take(&0), Some(0));
assert_eq!(set.take(&5), None);

Removes a value from the set

Removes a value from the set. Returns true if the value was present in the set.

Example

use ranged_set::RangedSet;

let mut set = RangedSet::new();
set.insert(0);
set.insert(1);
set.insert(2);

assert_eq!(set.remove(&0), true);
assert_eq!(set.remove(&5), false);

Trait Implementations

impl<T: Debug + Step + Clone + Ord> Debug for RangedSet<T>
[src]

Formats the value using the given formatter.