pub struct RankedIndex<K, T>{ /* private fields */ }
Expand description
Keeps an index of items sorted by the given rank, highest rank first
Implementations§
Source§impl<K, T> RankedIndex<K, T>
impl<K, T> RankedIndex<K, T>
pub fn new_with(rank: K, value: T) -> Self
Sourcepub fn insert(&mut self, rank: K, value: T)
pub fn insert(&mut self, rank: K, value: T)
Insert the value T at the position of rank
Will add at first position if a value of the same rank is found
Sourcepub fn remove(&mut self, value: &T)
pub fn remove(&mut self, value: &T)
Remove all instances in the vector having the specific value
pub fn update_stream(&self) -> impl Stream<Item = VectorDiff<T>>
Methods from Deref<Target = ObservableVector<(K, T)>>§
Sourcepub fn subscribe(&self) -> VectorSubscriber<T>
pub fn subscribe(&self) -> VectorSubscriber<T>
Obtain a new subscriber.
If you put the ObservableVector
behind a lock, it is highly
recommended to make access of the elements and subscribing one
operation. Otherwise, the values could be altered in between the
reading of the values and subscribing to changes.
Methods from Deref<Target = Vector<T>>§
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Test whether a vector is empty.
Time: O(1)
§Examples
let vec = vector!["Joe", "Mike", "Robert"];
assert_eq!(false, vec.is_empty());
assert_eq!(true, Vector::<i32>::new().is_empty());
Sourcepub fn is_inline(&self) -> bool
pub fn is_inline(&self) -> bool
Test whether a vector is currently inlined.
Vectors small enough that their contents could be stored entirely inside
the space of std::mem::size_of::<Vector<A>>()
bytes are stored inline on
the stack instead of allocating any chunks. This method returns true
if
this vector is currently inlined, or false
if it currently has chunks allocated
on the heap.
This may be useful in conjunction with ptr_eq()
, which checks if
two vectors’ heap allocations are the same, and thus will never return true
for inlined vectors.
Time: O(1)
Sourcepub fn ptr_eq(&self, other: &Vector<A>) -> bool
pub fn ptr_eq(&self, other: &Vector<A>) -> bool
Test whether two vectors refer to the same content in memory.
This uses the following rules to determine equality:
- If the two sides are references to the same vector, return true.
- If the two sides are single chunk vectors pointing to the same chunk, return true.
- If the two sides are full trees pointing to the same chunks, return true.
This would return true if you’re comparing a vector to itself, or
if you’re comparing a vector to a fresh clone of itself. The exception to this is
if you’ve cloned an inline array (ie. an array with so few elements they can fit
inside the space a Vector
allocates for its pointers, so there are no heap allocations
to compare).
Time: O(1)
Sourcepub fn leaves(&self) -> Chunks<'_, A>
pub fn leaves(&self) -> Chunks<'_, A>
Get an iterator over the leaf nodes of a vector.
This returns an iterator over the Chunk
s at the leaves of the
RRB tree. These are useful for efficient parallelisation of work on
the vector, but should not be used for basic iteration.
Time: O(1)
Sourcepub fn get(&self, index: usize) -> Option<&A>
pub fn get(&self, index: usize) -> Option<&A>
Get a reference to the value at index index
in a vector.
Returns None
if the index is out of bounds.
Time: O(log n)
§Examples
let vec = vector!["Joe", "Mike", "Robert"];
assert_eq!(Some(&"Robert"), vec.get(2));
assert_eq!(None, vec.get(5));
Sourcepub fn front(&self) -> Option<&A>
pub fn front(&self) -> Option<&A>
Get the first element of a vector.
If the vector is empty, None
is returned.
Time: O(log n)
Sourcepub fn head(&self) -> Option<&A>
pub fn head(&self) -> Option<&A>
Get the first element of a vector.
If the vector is empty, None
is returned.
This is an alias for the front
method.
Time: O(log n)
Sourcepub fn back(&self) -> Option<&A>
pub fn back(&self) -> Option<&A>
Get the last element of a vector.
If the vector is empty, None
is returned.
Time: O(log n)
Sourcepub fn last(&self) -> Option<&A>
pub fn last(&self) -> Option<&A>
Get the last element of a vector.
If the vector is empty, None
is returned.
This is an alias for the back
method.
Time: O(log n)
Sourcepub fn index_of(&self, value: &A) -> Option<usize>where
A: PartialEq,
pub fn index_of(&self, value: &A) -> Option<usize>where
A: PartialEq,
Get the index of a given element in the vector.
Searches the vector for the first occurrence of a given value,
and returns the index of the value if it’s there. Otherwise,
it returns None
.
Time: O(n)
§Examples
let mut vec = vector![1, 2, 3, 4, 5];
assert_eq!(Some(2), vec.index_of(&3));
assert_eq!(None, vec.index_of(&31337));
Sourcepub fn contains(&self, value: &A) -> boolwhere
A: PartialEq,
pub fn contains(&self, value: &A) -> boolwhere
A: PartialEq,
Test if a given element is in the vector.
Searches the vector for the first occurrence of a given value,
and returns true
if it’s there. If it’s nowhere to be found
in the vector, it returns false
.
Time: O(n)
§Examples
let mut vec = vector![1, 2, 3, 4, 5];
assert_eq!(true, vec.contains(&3));
assert_eq!(false, vec.contains(&31337));
Sourcepub fn binary_search_by<F>(&self, f: F) -> Result<usize, usize>
pub fn binary_search_by<F>(&self, f: F) -> Result<usize, usize>
Binary search a sorted vector for a given element using a comparator function.
Assumes the vector has already been sorted using the same comparator
function, eg. by using sort_by
.
If the value is found, it returns Ok(index)
where index
is the index
of the element. If the value isn’t found, it returns Err(index)
where
index
is the index at which the element would need to be inserted to
maintain sorted order.
Time: O(log n)
Sourcepub fn binary_search(&self, value: &A) -> Result<usize, usize>where
A: Ord,
pub fn binary_search(&self, value: &A) -> Result<usize, usize>where
A: Ord,
Binary search a sorted vector for a given element.
If the value is found, it returns Ok(index)
where index
is the index
of the element. If the value isn’t found, it returns Err(index)
where
index
is the index at which the element would need to be inserted to
maintain sorted order.
Time: O(log n)
Sourcepub fn binary_search_by_key<B, F>(&self, b: &B, f: F) -> Result<usize, usize>
pub fn binary_search_by_key<B, F>(&self, b: &B, f: F) -> Result<usize, usize>
Binary search a sorted vector for a given element with a key extract function.
Assumes the vector has already been sorted using the same key extract
function, eg. by using sort_by_key
.
If the value is found, it returns Ok(index)
where index
is the index
of the element. If the value isn’t found, it returns Err(index)
where
index
is the index at which the element would need to be inserted to
maintain sorted order.
Time: O(log n)
Sourcepub fn update(&self, index: usize, value: A) -> Vector<A>
pub fn update(&self, index: usize, value: A) -> Vector<A>
Create a new vector with the value at index index
updated.
Panics if the index is out of bounds.
Time: O(log n)
§Examples
let mut vec = vector![1, 2, 3];
assert_eq!(vector![1, 5, 3], vec.update(1, 5));
Trait Implementations§
Source§impl<K, T> Default for RankedIndex<K, T>
impl<K, T> Default for RankedIndex<K, T>
Auto Trait Implementations§
impl<K, T> Freeze for RankedIndex<K, T>
impl<K, T> !RefUnwindSafe for RankedIndex<K, T>
impl<K, T> Send for RankedIndex<K, T>
impl<K, T> Sync for RankedIndex<K, T>
impl<K, T> Unpin for RankedIndex<K, T>
impl<K, T> !UnwindSafe for RankedIndex<K, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more