[][src]Struct immutable_chunkmap::set::Set

pub struct Set<K: Ord + Clone>(_);

This set uses a similar strategy to BTreeSet to ensure cache efficient performance on modern hardware while still providing log(N) get, insert, and remove operations.

Examples

use std::string::String;
use self::immutable_chunkmap::set::Set;

let m =
   Set::new()
   .insert(String::from("1")).0
   .insert(String::from("2")).0
   .insert(String::from("3")).0;

assert_eq!(m.contains("1"), true);
assert_eq!(m.contains("2"), true);
assert_eq!(m.contains("3"), true);
assert_eq!(m.contains("4"), false);

for k in &m { println!("{}", k) }

Methods

impl<K> Set<K> where
    K: Ord + Clone
[src]

Create a new empty set

This will insert many elements at once, and is potentially a lot faster than inserting one by one, especially if the data is sorted.

#Examples

 use self::immutable_chunkmap::set::Set;

 let mut v = vec![1, 10, -12, 44, 50];
 v.sort_unstable();

 let m = Set::new().insert_many(v.iter().map(|k| *k));

 for k in &v {
   assert_eq!(m.contains(k), true)
 }

Remove multiple elements in a single pass. Similar performance to insert_many.

This is just slightly wierd, however if you have a bunch of borrowed forms of members of the set, and you want to look at the real entries and possibly add/update/remove them, then this method is for you.

return a new set with k inserted into it. If k already exists in the old set return true, else false. If the element already exists in the set memory will not be allocated.

return true if the set contains k, else false. Runs in log(N) time and constant space. where N is the size of the set.

return a reference to an item in the set if any that is equal to the given value.

return a new set with k removed. Runs in log(N) time and log(N) space, where N is the size of the set

return the union of 2 sets. Runs in O(log(N) + M) time, where N is the largest of the two sets, and M is the number of chunks that intersect, which is roughly proportional to the size of the intersection.

Examples

use std::iter::FromIterator;
use self::immutable_chunkmap::set::Set;

let s0 = Set::from_iter(0..10);
let s1 = Set::from_iter(5..15);
let s2 = s0.union(&s1);
for i in 0..15 {
    assert!(s2.contains(&i));
}

get the number of elements in the map O(1) time and space

Important traits for SetIter<'a, Q, K>

return an iterator over the subset of elements in the set that are within the specified range.

The returned iterator runs in O(log(N) + M) time, and constant space. N is the number of elements in the tree, and M is the number of elements you examine.

if lbound >= ubound the returned iterator will be empty

Trait Implementations

impl<K: Clone + Ord + Clone> Clone for Set<K>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<K> Hash for Set<K> where
    K: Hash + Ord + Clone
[src]

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

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

impl<K> Default for Set<K> where
    K: Ord + Clone
[src]

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

impl<K> PartialEq for Set<K> where
    K: Ord + Clone
[src]

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

This method tests for !=.

impl<K> Eq for Set<K> where
    K: Eq + Ord + Clone
[src]

impl<K> PartialOrd for Set<K> where
    K: Ord + Clone
[src]

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

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

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

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

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

impl<K> Ord for Set<K> where
    K: Ord + Clone
[src]

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

impl<K> Debug for Set<K> where
    K: Debug + Ord + Clone
[src]

Formats the value using the given formatter. Read more

impl<K> FromIterator<K> for Set<K> where
    K: Ord + Clone
[src]

Creates a value from an iterator. Read more

impl<'a, K> IntoIterator for &'a Set<K> where
    K: 'a + Borrow<K> + Ord + Clone
[src]

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

Auto Trait Implementations

impl<K> Send for Set<K> where
    K: Send + Sync

impl<K> Sync for Set<K> where
    K: Send + Sync

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

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

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

recently added

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

impl<T> From for T
[src]

Performs the conversion.

impl<T, U> Into for T where
    U: From<T>, 
[src]

Performs the conversion.

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T> Borrow for T where
    T: ?Sized
[src]

Immutably borrows from an owned value. Read more

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T> BorrowMut for T where
    T: ?Sized
[src]

Mutably borrows from an owned value. Read more

impl<T> Any for T where
    T: 'static + ?Sized
[src]

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

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more