Struct immutable_chunkmap::set::Set

source ·
pub struct Set<K: Ord + Clone, const SIZE: usize>(_);
Expand description

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::SetM;

let m =
   SetM::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) }

Implementations§

Create a new empty set

Examples found in repository?
src/set.rs (line 92)
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
    fn default() -> Set<K, SIZE> {
        Set::new()
    }
}

impl<K, const SIZE: usize> PartialEq for Set<K, SIZE>
where
    K: Ord + Clone,
{
    fn eq(&self, other: &Set<K, SIZE>) -> bool {
        self.0 == other.0
    }
}

impl<K, const SIZE: usize> Eq for Set<K, SIZE> where K: Eq + Ord + Clone {}

impl<K, const SIZE: usize> PartialOrd for Set<K, SIZE>
where
    K: Ord + Clone,
{
    fn partial_cmp(&self, other: &Set<K, SIZE>) -> Option<Ordering> {
        self.0.partial_cmp(&other.0)
    }
}

impl<K, const SIZE: usize> Ord for Set<K, SIZE>
where
    K: Ord + Clone,
{
    fn cmp(&self, other: &Set<K, SIZE>) -> Ordering {
        self.0.cmp(&other.0)
    }
}

impl<K, const SIZE: usize> Debug for Set<K, SIZE>
where
    K: Debug + Ord + Clone,
{
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
        f.debug_set().entries(self.into_iter()).finish()
    }
}

impl<K, const SIZE: usize> FromIterator<K> for Set<K, SIZE>
where
    K: Ord + Clone,
{
    fn from_iter<T: IntoIterator<Item = K>>(iter: T) -> Self {
        Set::new().insert_many(iter)
    }

Create a weak reference to this set

Return the number of strong references to this set (see Arc)

Return the number of weak references to this set (see Arc)

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::SetM;

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

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

 for k in &v {
   assert_eq!(m.contains(k), true)
 }
Examples found in repository?
src/set.rs (line 139)
138
139
140
    fn from_iter<T: IntoIterator<Item = K>>(iter: T) -> Self {
        Set::new().insert_many(iter)
    }

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.

insert k with copy on write semantics. if self is a unique reference to the set, then k will be inserted in place. Otherwise, only the parts of the set necessary to insert k will be copied, and then the copies will be mutated. self will share all the parts that weren’t modfied with any previous clones.

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.

Examples found in repository?
src/set.rs (line 356)
355
356
357
358
359
360
361
    pub fn insert(&self, k: K) -> (Self, bool) {
        if self.contains(&k) {
            (self.clone(), true)
        } else {
            (Set(self.0.insert(k, ()).0), false)
        }
    }

return a reference to the item in the set that is equal to the given value, or None if no such value exists.

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

remove k from the set in place with copy on write semantics (see insert_cow). return true if k was in the set.

return the union of 2 sets. Runs in O(log(N) + M) time and space, 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::SetM;

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

return the intersection of 2 sets. Runs in O(log(N) + M) time and space, where N is the smallest of the two sets, and M is the number of intersecting chunks.

Examples

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

let s0 = SetM::from_iter(0..100); let s1 = SetM::from_iter(20..50); let s2 = s0.intersect(&s1);

assert!(s2.len() == 30); for i in 0..100 { if i < 20 || i >= 50 { assert!(!s2.contains(&i)); } else { assert!(s2.contains(&i)); } }

Return the difference of two sets. Runs in O(log(N) + M) time and space, where N is the smallest of the two sets, and M is the number of intersecting chunks.

Examples
use std::iter::FromIterator;
use self::immutable_chunkmap::set::SetM;

let s0 = SetM::from_iter(0..100);
let s1 = SetM::from_iter(0..50);
let s2 = s0.diff(&s1);

assert!(s2.len() == 50);
for i in 0..50 {
    assert!(!s2.contains(&i));
}
for i in 50..100 {
    assert!(s2.contains(&i));
}

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

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§

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
Creates a value from an iterator. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
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 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
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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

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
Converts self into T using Into<T>. Read more
Causes self to use its Binary implementation when Debug-formatted.
Causes self to use its Display implementation when Debug-formatted.
Causes self to use its LowerExp implementation when Debug-formatted.
Causes self to use its LowerHex implementation when Debug-formatted.
Causes self to use its Octal implementation when Debug-formatted.
Causes self to use its Pointer implementation when Debug-formatted.
Causes self to use its UpperExp implementation when Debug-formatted.
Causes self to use its UpperHex implementation when Debug-formatted.
Formats each item in a sequence. 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.

Pipes by value. This is generally the method you want to use. Read more
Borrows self and passes that borrow into the pipe function. Read more
Mutably borrows self and passes that borrow into the pipe function. Read more
Borrows self, then passes self.borrow() into the pipe function. Read more
Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Borrows self, then passes self.as_ref() into the pipe function.
Mutably borrows self, then passes self.as_mut() into the pipe function.
Borrows self, then passes self.deref() into the pipe function.
Mutably borrows self, then passes self.deref_mut() into the pipe function.
Immutable access to a value. Read more
Mutable access to a value. Read more
Immutable access to the Borrow<B> of a value. Read more
Mutable access to the BorrowMut<B> of a value. Read more
Immutable access to the AsRef<R> view of a value. Read more
Mutable access to the AsMut<R> view of a value. Read more
Immutable access to the Deref::Target of a value. Read more
Mutable access to the Deref::Target of a value. Read more
Calls .tap() only in debug builds, and is erased in release builds.
Calls .tap_mut() only in debug builds, and is erased in release builds.
Calls .tap_borrow() only in debug builds, and is erased in release builds.
Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Calls .tap_ref() only in debug builds, and is erased in release builds.
Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Calls .tap_deref() only in debug builds, and is erased in release builds.
Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
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
Attempts to convert self into T using TryInto<T>. 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.