acter_core::store

Struct LifoIndex

Source
pub struct LifoIndex<T>
where T: 'static + Clone + Eq,
{ /* private fields */ }
Expand description

Keeps an index of items sorted by when they were added latest first

Implementations§

Source§

impl<T> LifoIndex<T>
where T: 'static + Clone + Eq,

Source

pub fn new_with(value: T) -> Self

Source

pub fn insert(&mut self, value: T)

Insert the element at the front

Source

pub fn remove(&mut self, value: &T)

All instances of this element from the vector

Source

pub fn values(&self) -> Vec<&T>

Returns the current list of values in order of when they were added

Source

pub fn update_stream(&self) -> impl Stream<Item = VectorDiff<T>>

Methods from Deref<Target = ObservableVector<T>>§

Source

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>>§

Source

pub fn len(&self) -> usize

Get the length of a vector.

Time: O(1)

§Examples
assert_eq!(5, vector![1, 2, 3, 4, 5].len());
Source

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());
Source

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)

Source

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)

Source

pub fn iter(&self) -> Iter<'_, A>

Get an iterator over a vector.

Time: O(1)

Source

pub fn leaves(&self) -> Chunks<'_, A>

Get an iterator over the leaf nodes of a vector.

This returns an iterator over the Chunks 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)

Source

pub fn focus(&self) -> Focus<'_, A>

Construct a Focus for a vector.

Time: O(1)

Source

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));
Source

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)

Source

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)

Source

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)

Source

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)

Source

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));
Source

pub fn contains(&self, value: &A) -> bool
where 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));
Source

pub fn binary_search_by<F>(&self, f: F) -> Result<usize, usize>
where F: FnMut(&A) -> Ordering,

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)

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)

Source

pub fn binary_search_by_key<B, F>(&self, b: &B, f: F) -> Result<usize, usize>
where F: FnMut(&A) -> B, B: Ord,

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)

Source

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));
Source

pub fn skip(&self, count: usize) -> Vector<A>

Construct a vector with count elements removed from the start of the current vector.

Time: O(log n)

Source

pub fn take(&self, count: usize) -> Vector<A>

Construct a vector of the first count elements from the current vector.

Time: O(log n)

Trait Implementations§

Source§

impl<T> Default for LifoIndex<T>
where T: 'static + Clone + Eq,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T> Deref for LifoIndex<T>
where T: 'static + Clone + Eq,

Source§

type Target = ObservableVector<T>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<T> Freeze for LifoIndex<T>

§

impl<T> !RefUnwindSafe for LifoIndex<T>

§

impl<T> Send for LifoIndex<T>
where T: Send + Sync,

§

impl<T> Sync for LifoIndex<T>
where T: Sync + Send,

§

impl<T> Unpin for LifoIndex<T>
where T: Unpin,

§

impl<T> !UnwindSafe for LifoIndex<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Any for T
where T: Any,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T

Source§

impl<T> SendOutsideWasm for T
where T: Send,

Source§

impl<T> SyncOutsideWasm for T
where T: Sync,