Struct veilid_core::ValueSubkeyRangeSet
source · pub struct ValueSubkeyRangeSet { /* private fields */ }
Implementations§
source§impl ValueSubkeyRangeSet
impl ValueSubkeyRangeSet
pub fn new() -> Self
pub fn full() -> Self
pub fn new_with_data(data: RangeSetBlaze<ValueSubkey>) -> Self
pub fn single(value: ValueSubkey) -> Self
pub fn single_range(low: ValueSubkey, high: ValueSubkey) -> Self
pub fn intersect(&self, other: &ValueSubkeyRangeSet) -> ValueSubkeyRangeSet
pub fn difference(&self, other: &ValueSubkeyRangeSet) -> ValueSubkeyRangeSet
pub fn union(&self, other: &ValueSubkeyRangeSet) -> ValueSubkeyRangeSet
pub fn data(&self) -> &RangeSetBlaze<ValueSubkey>
pub fn into_data(self) -> RangeSetBlaze<ValueSubkey>
pub fn nth_subkey(&self, idx: usize) -> Option<ValueSubkey>
pub fn idx_of_subkey(&self, subkey: ValueSubkey) -> Option<usize>
Methods from Deref<Target = RangeSetBlaze<ValueSubkey>>§
sourcepub fn iter(&self) -> Iter<T, RangesIter<'_, T>>
pub fn iter(&self) -> Iter<T, RangesIter<'_, T>>
Gets an (double-ended) iterator that visits the integer elements in the RangeSetBlaze
in
ascending and/or descending order.
Also see the RangeSetBlaze::ranges
method.
§Examples
use range_set_blaze::RangeSetBlaze;
let set = RangeSetBlaze::from_iter([1..=3]);
let mut set_iter = set.iter();
assert_eq!(set_iter.next(), Some(1));
assert_eq!(set_iter.next(), Some(2));
assert_eq!(set_iter.next(), Some(3));
assert_eq!(set_iter.next(), None);
Values returned by .next()
are in ascending order.
Values returned by .next_back()
are in descending order.
use range_set_blaze::RangeSetBlaze;
let set = RangeSetBlaze::from_iter([3, 1, 2]);
let mut set_iter = set.iter();
assert_eq!(set_iter.next(), Some(1));
assert_eq!(set_iter.next_back(), Some(3));
assert_eq!(set_iter.next(), Some(2));
assert_eq!(set_iter.next_back(), None);
sourcepub fn first(&self) -> Option<T>
pub fn first(&self) -> Option<T>
Returns the first element in the set, if any. This element is always the minimum of all integer elements in the set.
§Examples
Basic usage:
use range_set_blaze::RangeSetBlaze;
let mut set = RangeSetBlaze::new();
assert_eq!(set.first(), None);
set.insert(1);
assert_eq!(set.first(), Some(1));
set.insert(2);
assert_eq!(set.first(), Some(1));
sourcepub fn get(&self, value: T) -> Option<T>
pub fn get(&self, value: T) -> Option<T>
Returns the element in the set, if any, that is equal to the value.
§Examples
use range_set_blaze::RangeSetBlaze;
let set = RangeSetBlaze::from_iter([1, 2, 3]);
assert_eq!(set.get(2), Some(2));
assert_eq!(set.get(4), None);
sourcepub fn last(&self) -> Option<T>
pub fn last(&self) -> Option<T>
Returns the last element in the set, if any. This element is always the maximum of all elements in the set.
§Examples
Basic usage:
use range_set_blaze::RangeSetBlaze;
let mut set = RangeSetBlaze::new();
assert_eq!(set.last(), None);
set.insert(1);
assert_eq!(set.last(), Some(1));
set.insert(2);
assert_eq!(set.last(), Some(2));
sourcepub fn append(&mut self, other: &mut RangeSetBlaze<T>)
pub fn append(&mut self, other: &mut RangeSetBlaze<T>)
Moves all elements from other
into self
, leaving other
empty.
§Performance
It adds the integers in other
to self
in O(n log m) time, where n is the number of ranges in other
and m is the number of ranges in self
.
When n is large, consider using |
which is O(n+m) time.
§Examples
use range_set_blaze::RangeSetBlaze;
let mut a = RangeSetBlaze::from_iter([1..=3]);
let mut b = RangeSetBlaze::from_iter([3..=5]);
a.append(&mut b);
assert_eq!(a.len(), 5usize);
assert_eq!(b.len(), 0usize);
assert!(a.contains(1));
assert!(a.contains(2));
assert!(a.contains(3));
assert!(a.contains(4));
assert!(a.contains(5));
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the set, removing all integer elements.
§Examples
use range_set_blaze::RangeSetBlaze;
let mut v = RangeSetBlaze::new();
v.insert(1);
v.clear();
assert!(v.is_empty());
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the set contains no elements.
§Examples
use range_set_blaze::RangeSetBlaze;
let mut v = RangeSetBlaze::new();
assert!(v.is_empty());
v.insert(1);
assert!(!v.is_empty());
sourcepub fn is_subset(&self, other: &RangeSetBlaze<T>) -> bool
pub fn is_subset(&self, other: &RangeSetBlaze<T>) -> bool
Returns true
if the set is a subset of another,
i.e., other
contains at least all the elements in self
.
§Examples
use range_set_blaze::RangeSetBlaze;
let sup = RangeSetBlaze::from_iter([1..=3]);
let mut set = RangeSetBlaze::new();
assert_eq!(set.is_subset(&sup), true);
set.insert(2);
assert_eq!(set.is_subset(&sup), true);
set.insert(4);
assert_eq!(set.is_subset(&sup), false);
sourcepub fn is_superset(&self, other: &RangeSetBlaze<T>) -> bool
pub fn is_superset(&self, other: &RangeSetBlaze<T>) -> bool
Returns true
if the set is a superset of another,
i.e., self
contains at least all the elements in other
.
§Examples
use range_set_blaze::RangeSetBlaze;
let sub = RangeSetBlaze::from_iter([1, 2]);
let mut set = RangeSetBlaze::new();
assert_eq!(set.is_superset(&sub), false);
set.insert(0);
set.insert(1);
assert_eq!(set.is_superset(&sub), false);
set.insert(2);
assert_eq!(set.is_superset(&sub), true);
sourcepub fn contains(&self, value: T) -> bool
pub fn contains(&self, value: T) -> bool
Returns true
if the set contains an element equal to the value.
§Examples
use range_set_blaze::RangeSetBlaze;
let set = RangeSetBlaze::from_iter([1, 2, 3]);
assert_eq!(set.contains(1), true);
assert_eq!(set.contains(4), false);
sourcepub fn is_disjoint(&self, other: &RangeSetBlaze<T>) -> bool
pub fn is_disjoint(&self, other: &RangeSetBlaze<T>) -> bool
Returns true
if self
has no elements in common with other
.
This is equivalent to checking for an empty intersection.
§Examples
use range_set_blaze::RangeSetBlaze;
let a = RangeSetBlaze::from_iter([1..=3]);
let mut b = RangeSetBlaze::new();
assert_eq!(a.is_disjoint(&b), true);
b.insert(4);
assert_eq!(a.is_disjoint(&b), true);
b.insert(1);
assert_eq!(a.is_disjoint(&b), false);
sourcepub fn insert(&mut self, value: T) -> bool
pub fn insert(&mut self, value: T) -> bool
Adds a value to the set.
Returns whether the value was newly inserted. That is:
- If the set did not previously contain an equal value,
true
is returned. - If the set already contained an equal value,
false
is returned, and the entry is not updated.
§Performance
Inserting n items will take in O(n log m) time, where n is the number of inserted items and m is the number of ranges in self
.
When n is large, consider using |
which is O(n+m) time.
§Examples
use range_set_blaze::RangeSetBlaze;
let mut set = RangeSetBlaze::new();
assert_eq!(set.insert(2), true);
assert_eq!(set.insert(2), false);
assert_eq!(set.len(), 1usize);
sourcepub fn range<R>(&self, range: R) -> IntoIter<T>where
R: RangeBounds<T>,
pub fn range<R>(&self, range: R) -> IntoIter<T>where
R: RangeBounds<T>,
Constructs an iterator over a sub-range of elements in the set.
Not to be confused with RangeSetBlaze::ranges
, which returns an iterator over the ranges in the set.
The simplest way is to use the range syntax min..max
, thus range(min..max)
will
yield elements from min (inclusive) to max (exclusive).
The range may also be entered as (Bound<T>, Bound<T>)
, so for example
range((Excluded(4), Included(10)))
will yield a left-exclusive, right-inclusive
range from 4 to 10.
§Panics
Panics if range start > end
.
Panics if range start == end
and both bounds are Excluded
.
§Performance
Although this could be written to run in time O(ln(n)) in the number of ranges, it is currently O(n) in the number of ranges.
§Examples
use range_set_blaze::RangeSetBlaze;
use core::ops::Bound::Included;
let mut set = RangeSetBlaze::new();
set.insert(3);
set.insert(5);
set.insert(8);
for elem in set.range((Included(4), Included(8))) {
println!("{elem}");
}
assert_eq!(Some(5), set.range(4..).next());
sourcepub fn ranges_insert(&mut self, range: RangeInclusive<T>) -> bool
pub fn ranges_insert(&mut self, range: RangeInclusive<T>) -> bool
Adds a range to the set.
Returns whether any values where newly inserted. That is:
- If the set did not previously contain some value in the range,
true
is returned. - If the set already contained every value in the range,
false
is returned, and the entry is not updated.
§Performance
Inserting n items will take in O(n log m) time, where n is the number of inserted items and m is the number of ranges in self
.
When n is large, consider using |
which is O(n+m) time.
§Examples
use range_set_blaze::RangeSetBlaze;
let mut set = RangeSetBlaze::new();
assert_eq!(set.ranges_insert(2..=5), true);
assert_eq!(set.ranges_insert(5..=6), true);
assert_eq!(set.ranges_insert(3..=4), false);
assert_eq!(set.len(), 5usize);
sourcepub fn remove(&mut self, value: T) -> bool
pub fn remove(&mut self, value: T) -> bool
If the set contains an element equal to the value, removes it from the set and drops it. Returns whether such an element was present.
§Examples
use range_set_blaze::RangeSetBlaze;
let mut set = RangeSetBlaze::new();
set.insert(2);
assert!(set.remove(2));
assert!(!set.remove(2));
sourcepub fn split_off(&mut self, value: T) -> RangeSetBlaze<T>
pub fn split_off(&mut self, value: T) -> RangeSetBlaze<T>
Splits the collection into two at the value. Returns a new collection with all elements greater than or equal to the value.
§Examples
Basic usage:
use range_set_blaze::RangeSetBlaze;
let mut a = RangeSetBlaze::new();
a.insert(1);
a.insert(2);
a.insert(3);
a.insert(17);
a.insert(41);
let b = a.split_off(3);
assert_eq!(a, RangeSetBlaze::from_iter([1, 2]));
assert_eq!(b, RangeSetBlaze::from_iter([3, 17, 41]));
sourcepub fn take(&mut self, value: T) -> Option<T>
pub fn take(&mut self, value: T) -> Option<T>
Removes and returns the element in the set, if any, that is equal to the value.
§Examples
use range_set_blaze::RangeSetBlaze;
let mut set = RangeSetBlaze::from_iter([1, 2, 3]);
assert_eq!(set.take(2), Some(2));
assert_eq!(set.take(2), None);
sourcepub fn replace(&mut self, value: T) -> Option<T>
pub fn replace(&mut self, value: T) -> Option<T>
Adds a value to the set, replacing the existing element, if any, that is equal to the value. Returns the replaced element.
Note: This is very similar to insert
. It is included for consistency with BTreeSet
.
§Examples
use range_set_blaze::RangeSetBlaze;
let mut set = RangeSetBlaze::new();
assert!(set.replace(5).is_none());
assert!(set.replace(5).is_some());
sourcepub fn len(&self) -> <T as Integer>::SafeLen
pub fn len(&self) -> <T as Integer>::SafeLen
Returns the number of elements in the set.
The number is allowed to be very, very large.
§Examples
use range_set_blaze::RangeSetBlaze;
let mut v = RangeSetBlaze::new();
assert_eq!(v.len(), 0usize);
v.insert(1);
assert_eq!(v.len(), 1usize);
let v = RangeSetBlaze::from_iter([
-170_141_183_460_469_231_731_687_303_715_884_105_728i128..=10,
-10..=170_141_183_460_469_231_731_687_303_715_884_105_726,
]);
assert_eq!(
v.len(),
340_282_366_920_938_463_463_374_607_431_768_211_455u128
);
sourcepub fn pop_first(&mut self) -> Option<T>
pub fn pop_first(&mut self) -> Option<T>
Removes the first element from the set and returns it, if any. The first element is always the minimum element in the set.
§Examples
use range_set_blaze::RangeSetBlaze;
let mut set = RangeSetBlaze::new();
set.insert(1);
while let Some(n) = set.pop_first() {
assert_eq!(n, 1);
}
assert!(set.is_empty());
sourcepub fn pop_last(&mut self) -> Option<T>
pub fn pop_last(&mut self) -> Option<T>
Removes the last value from the set and returns it, if any. The last value is always the maximum value in the set.
§Examples
use range_set_blaze::RangeSetBlaze;
let mut set = RangeSetBlaze::new();
set.insert(1);
while let Some(n) = set.pop_last() {
assert_eq!(n, 1);
}
assert!(set.is_empty());
sourcepub fn ranges(&self) -> RangesIter<'_, T>
pub fn ranges(&self) -> RangesIter<'_, T>
An iterator that visits the ranges in the RangeSetBlaze
,
i.e., the integers as sorted & disjoint ranges.
Also see RangeSetBlaze::iter
and RangeSetBlaze::into_ranges
.
§Examples
use range_set_blaze::RangeSetBlaze;
let set = RangeSetBlaze::from_iter([10..=20, 15..=25, 30..=40]);
let mut ranges = set.ranges();
assert_eq!(ranges.next(), Some(10..=25));
assert_eq!(ranges.next(), Some(30..=40));
assert_eq!(ranges.next(), None);
Values returned by the iterator are returned in ascending order:
use range_set_blaze::RangeSetBlaze;
let set = RangeSetBlaze::from_iter([30..=40, 15..=25, 10..=20]);
let mut ranges = set.ranges();
assert_eq!(ranges.next(), Some(10..=25));
assert_eq!(ranges.next(), Some(30..=40));
assert_eq!(ranges.next(), None);
sourcepub fn ranges_len(&self) -> usize
pub fn ranges_len(&self) -> usize
Returns the number of sorted & disjoint ranges in the set.
§Example
use range_set_blaze::RangeSetBlaze;
// We put in three ranges, but they are not sorted & disjoint.
let set = RangeSetBlaze::from_iter([10..=20, 15..=25, 30..=40]);
// After RangeSetBlaze sorts & 'disjoint's them, we see two ranges.
assert_eq!(set.ranges_len(), 2);
assert_eq!(set.to_string(), "10..=25, 30..=40");
sourcepub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, f: F)
Retains only the elements specified by the predicate.
In other words, remove all integers e
for which f(&e)
returns false
.
The integer elements are visited in ascending order.
§Examples
use range_set_blaze::RangeSetBlaze;
let mut set = RangeSetBlaze::from_iter([1..=6]);
// Keep only the even numbers.
set.retain(|k| k % 2 == 0);
assert_eq!(set, RangeSetBlaze::from_iter([2, 4, 6]));
Trait Implementations§
source§impl Clone for ValueSubkeyRangeSet
impl Clone for ValueSubkeyRangeSet
source§fn clone(&self) -> ValueSubkeyRangeSet
fn clone(&self) -> ValueSubkeyRangeSet
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ValueSubkeyRangeSet
impl Debug for ValueSubkeyRangeSet
source§impl Default for ValueSubkeyRangeSet
impl Default for ValueSubkeyRangeSet
source§fn default() -> ValueSubkeyRangeSet
fn default() -> ValueSubkeyRangeSet
source§impl DerefMut for ValueSubkeyRangeSet
impl DerefMut for ValueSubkeyRangeSet
source§impl<'de> Deserialize<'de> for ValueSubkeyRangeSet
impl<'de> Deserialize<'de> for ValueSubkeyRangeSet
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Display for ValueSubkeyRangeSet
impl Display for ValueSubkeyRangeSet
source§impl FromStr for ValueSubkeyRangeSet
impl FromStr for ValueSubkeyRangeSet
source§impl Hash for ValueSubkeyRangeSet
impl Hash for ValueSubkeyRangeSet
source§impl JsonSchema for ValueSubkeyRangeSet
impl JsonSchema for ValueSubkeyRangeSet
source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref
keyword. Read moresource§fn schema_name() -> String
fn schema_name() -> String
source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
source§impl Ord for ValueSubkeyRangeSet
impl Ord for ValueSubkeyRangeSet
source§fn cmp(&self, other: &ValueSubkeyRangeSet) -> Ordering
fn cmp(&self, other: &ValueSubkeyRangeSet) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq for ValueSubkeyRangeSet
impl PartialEq for ValueSubkeyRangeSet
source§fn eq(&self, other: &ValueSubkeyRangeSet) -> bool
fn eq(&self, other: &ValueSubkeyRangeSet) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for ValueSubkeyRangeSet
impl PartialOrd for ValueSubkeyRangeSet
source§fn partial_cmp(&self, other: &ValueSubkeyRangeSet) -> Option<Ordering>
fn partial_cmp(&self, other: &ValueSubkeyRangeSet) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more