Struct immutable_chunkmap::set::Set [−][src]
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 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)
}pub fn remove_many<Q, E>(&self, elts: E) -> Self where
Q: Ord,
K: Borrow<Q>,
E: IntoIterator<Item = Q>,
pub fn remove_many<Q, E>(&self, elts: E) -> Self where
Q: Ord,
K: Borrow<Q>,
E: IntoIterator<Item = Q>,
Remove multiple elements in a single pass. Similar performance to insert_many.
pub fn update_many<Q, E, F>(&self, elts: E, f: F) -> Self where
Q: Ord,
K: Borrow<Q>,
E: IntoIterator<Item = Q>,
F: FnMut(Q, Option<&K>) -> Option<K>,
pub fn update_many<Q, E, F>(&self, elts: E, f: F) -> Self where
Q: Ord,
K: Borrow<Q>,
E: IntoIterator<Item = Q>,
F: FnMut(Q, Option<&K>) -> Option<K>,
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.
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));
}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
Creates a value from an iterator. Read more
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
Auto Trait Implementations
impl<K, const SIZE: usize> RefUnwindSafe for Set<K, SIZE> where
K: RefUnwindSafe,
impl<K, const SIZE: usize> UnwindSafe for Set<K, SIZE> where
K: RefUnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more