Struct immutable_chunkmap::set::Set
source · [−]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
sourceimpl<K, const SIZE: usize> Set<K, SIZE> where
K: Ord + Clone,
impl<K, const SIZE: usize> Set<K, SIZE> where
K: Ord + Clone,
sourcepub fn downgrade(&self) -> WeakSetRef<K, SIZE>
pub fn downgrade(&self) -> WeakSetRef<K, SIZE>
Create a weak reference to this set
sourcepub fn strong_count(&self) -> usize
pub fn strong_count(&self) -> usize
Return the number of strong references to this set (see Arc)
sourcepub fn weak_count(&self) -> usize
pub fn weak_count(&self) -> usize
Return the number of weak references to this set (see Arc)
sourcepub fn insert_many<E: IntoIterator<Item = K>>(&self, elts: E) -> Self
pub fn insert_many<E: IntoIterator<Item = K>>(&self, elts: E) -> Self
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)
}sourcepub 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.
sourcepub 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.
sourcepub fn insert(&self, k: K) -> (Self, bool)
pub fn insert(&self, k: K) -> (Self, bool)
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.
sourcepub fn insert_cow(&mut self, k: K) -> bool
pub fn insert_cow(&mut self, k: K) -> bool
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.
sourcepub fn contains<'a, Q>(&'a self, k: &Q) -> bool where
Q: ?Sized + Ord,
K: Borrow<Q>,
pub fn contains<'a, Q>(&'a self, k: &Q) -> bool where
Q: ?Sized + Ord,
K: Borrow<Q>,
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.
sourcepub fn get<'a, Q>(&'a self, k: &Q) -> Option<&'_ K> where
Q: ?Sized + Ord,
K: Borrow<Q>,
pub fn get<'a, Q>(&'a self, k: &Q) -> Option<&'_ K> where
Q: ?Sized + Ord,
K: Borrow<Q>,
return a reference to the item in the set that is equal to the given value, or None if no such value exists.
sourcepub fn remove<Q: Sized + Ord>(&self, k: &Q) -> (Self, bool) where
K: Borrow<Q>,
pub fn remove<Q: Sized + Ord>(&self, k: &Q) -> (Self, bool) where
K: Borrow<Q>,
return a new set with k removed. Runs in log(N) time and log(N) space, where N is the size of the set
sourcepub fn remove_cow<Q: Sized + Ord>(&mut self, k: &Q) -> bool where
K: Borrow<Q>,
pub fn remove_cow<Q: Sized + Ord>(&mut self, k: &Q) -> bool where
K: Borrow<Q>,
remove k from the set in place with copy on write semantics
(see insert_cow). return true if k was in the set.
sourcepub fn union(&self, other: &Set<K, SIZE>) -> Self
pub fn union(&self, other: &Set<K, SIZE>) -> Self
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));
}sourcepub fn intersect(&self, other: &Set<K, SIZE>) -> Self
pub fn intersect(&self, other: &Set<K, SIZE>) -> Self
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)); } }
sourcepub fn diff(&self, other: &Set<K, SIZE>) -> Self where
K: Debug,
pub fn diff(&self, other: &Set<K, SIZE>) -> Self where
K: Debug,
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));
}sourcepub fn range<'a, Q>(
&'a self,
lbound: Bound<Q>,
ubound: Bound<Q>
) -> SetIter<'a, Q, K, SIZE>ⓘNotable traits for SetIter<'a, Q, K, SIZE>impl<'a, Q, K, const SIZE: usize> Iterator for SetIter<'a, Q, K, SIZE> where
Q: Ord,
K: 'a + Clone + Ord + Borrow<Q>, type Item = &'a K; where
Q: Ord,
K: 'a + Clone + Ord + Borrow<Q>,
pub fn range<'a, Q>(
&'a self,
lbound: Bound<Q>,
ubound: Bound<Q>
) -> SetIter<'a, Q, K, SIZE>ⓘNotable traits for SetIter<'a, Q, K, SIZE>impl<'a, Q, K, const SIZE: usize> Iterator for SetIter<'a, Q, K, SIZE> where
Q: Ord,
K: 'a + Clone + Ord + Borrow<Q>, type Item = &'a K; where
Q: Ord,
K: 'a + Clone + Ord + Borrow<Q>,
Q: Ord,
K: 'a + Clone + Ord + Borrow<Q>, type Item = &'a 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
sourceimpl<K, const SIZE: usize> FromIterator<K> for Set<K, SIZE> where
K: Ord + Clone,
impl<K, const SIZE: usize> FromIterator<K> for Set<K, SIZE> where
K: Ord + Clone,
sourcefn from_iter<T: IntoIterator<Item = K>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = K>>(iter: T) -> Self
Creates a value from an iterator. Read more
sourceimpl<'a, K, const SIZE: usize> IntoIterator for &'a Set<K, SIZE> where
K: 'a + Borrow<K> + Ord + Clone,
impl<'a, K, const SIZE: usize> IntoIterator for &'a Set<K, SIZE> where
K: 'a + Borrow<K> + Ord + Clone,
sourceimpl<K, const SIZE: usize> Ord for Set<K, SIZE> where
K: Ord + Clone,
impl<K, const SIZE: usize> Ord for Set<K, SIZE> where
K: Ord + Clone,
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl<K, const SIZE: usize> PartialEq<Set<K, SIZE>> for Set<K, SIZE> where
K: Ord + Clone,
impl<K, const SIZE: usize> PartialEq<Set<K, SIZE>> for Set<K, SIZE> where
K: Ord + Clone,
sourceimpl<K, const SIZE: usize> PartialOrd<Set<K, SIZE>> for Set<K, SIZE> where
K: Ord + Clone,
impl<K, const SIZE: usize> PartialOrd<Set<K, SIZE>> for Set<K, SIZE> where
K: Ord + Clone,
sourcefn partial_cmp(&self, other: &Set<K, SIZE>) -> Option<Ordering>
fn partial_cmp(&self, other: &Set<K, SIZE>) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
impl<K, const SIZE: usize> Eq for Set<K, SIZE> where
K: Eq + Ord + Clone,
Auto Trait Implementations
impl<K, const SIZE: usize> RefUnwindSafe for Set<K, SIZE> where
K: RefUnwindSafe,
impl<K, const SIZE: usize> Send for Set<K, SIZE> where
K: Send + Sync,
impl<K, const SIZE: usize> Sync for Set<K, SIZE> where
K: Send + Sync,
impl<K, const SIZE: usize> Unpin for Set<K, SIZE>
impl<K, const SIZE: usize> UnwindSafe for Set<K, SIZE> where
K: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> FmtForward for T
impl<T> FmtForward for T
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
Causes self to use its Binary implementation when Debug-formatted.
fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
Causes self to use its Display implementation when
Debug-formatted. Read more
fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
Causes self to use its LowerExp implementation when
Debug-formatted. Read more
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
Causes self to use its LowerHex implementation when
Debug-formatted. Read more
fn fmt_octal(self) -> FmtOctal<Self> where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self> where
Self: Octal,
Causes self to use its Octal implementation when Debug-formatted.
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
Causes self to use its Pointer implementation when
Debug-formatted. Read more
fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
Causes self to use its UpperExp implementation when
Debug-formatted. Read more
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
Causes self to use its UpperHex implementation when
Debug-formatted. Read more
impl<T> Pipe for T where
T: ?Sized,
impl<T> Pipe for T where
T: ?Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
Pipes by value. This is generally the method you want to use. Read more
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R where
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R where
R: 'a,
Borrows self and passes that borrow into the pipe function. Read more
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
Mutably borrows self and passes that borrow into the pipe function. Read more
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
Borrows self, then passes self.borrow() into the pipe function. Read more
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
Mutably borrows self, then passes self.borrow_mut() into the pipe
function. Read more
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
Borrows self, then passes self.as_ref() into the pipe function.
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R where
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R where
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
Mutably borrows self, then passes self.as_mut() into the pipe
function. Read more
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
Borrows self, then passes self.deref() into the pipe function.
impl<T> Tap for T
impl<T> Tap for T
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
Immutable access to the Borrow<B> of a value. Read more
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
Mutable access to the BorrowMut<B> of a value. Read more
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
Immutable access to the AsRef<R> view of a value. Read more
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
Mutable access to the AsMut<R> view of a value. Read more
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self where
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self where
Self: Deref<Target = T>,
T: ?Sized,
Immutable access to the Deref::Target of a value. Read more
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self where
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self where
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
Mutable access to the Deref::Target of a value. Read more
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
Calls .tap() only in debug builds, and is erased in release builds.
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls .tap_mut() only in debug builds, and is erased in release
builds. Read more
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
Calls .tap_borrow() only in debug builds, and is erased in release
builds. Read more
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
Calls .tap_borrow_mut() only in debug builds, and is erased in release
builds. Read more
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
Calls .tap_ref() only in debug builds, and is erased in release
builds. Read more
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
Calls .tap_ref_mut() only in debug builds, and is erased in release
builds. Read more