immutable_seq

Struct Seq

Source
pub struct Seq<T>(/* private fields */);
Expand description

A data-structure implementing an immutable sequence of values.

An amortized running time is given for each operation, with n referring to the length of the sequence and i being the integral index used by some operations. These bounds hold even in a persistent (shared) setting.

This implementation is based on Haskell’s Data.Sequence library (http://hackage.haskell.org/package/containers/docs/Data-Sequence.html), and the following paper:

  • Ralf Hinze and Ross Paterson, “Finger trees: a simple general-purpose data structure”, Journal of Functional Programming 16:2 (2006) pp 197-217. http://staff.city.ac.uk/~ross/papers/FingerTree.html

Implementations§

Source§

impl<T: 'static> Seq<T>

Source

pub fn empty() -> Seq<T>

The empty sequence. Time: O(1)

Source

pub fn singleton(x: T) -> Seq<T>

A sequence with a single value. Time O(1)

Source

pub fn push_front(&self, x: T) -> Seq<T>

A new sequence that is self with x added to the front. Time: O(1)

Source

pub fn push_back(&self, x: T) -> Seq<T>

A new sequence that is self with x added to the back. Time: O(1)

Source

pub fn append(&self, other: &Seq<T>) -> Seq<T>

The concatenation of self with other. Time: O(log(min(n1,n2)))

Source

pub fn is_empty(&self) -> bool

Is the sequence empty?. Time: O(1)

Source

pub fn len(&self) -> usize

The number of elements in the sequence. Time: O(1)

Source

pub fn front(&self) -> Option<&T>

The first element in the sequence, if it exists. Time: O(1)

Source

pub fn back(&self) -> Option<&T>

The back element, if it exsts. Time: O(1)

Source

pub fn pop_front(&self) -> Seq<T>

A new sequence that is self with the front element removed, together with the front element (if it exists). Time: O(1)

Source

pub fn pop_back(&self) -> Seq<T>

A new sequence that is self with the back element removed, together with the back element (if it exists). Time: O(1)

Source

pub fn adjust<F>(&self, i: usize, func: F) -> Seq<T>
where F: FnOnce(&T) -> T,

A new sequence with the element at index i replaced by f(self[i]). Time: O(log(min(i,n-i)))

If i is out of range, returns a clone of self.

Source

pub fn update(&self, i: usize, x: T) -> Seq<T>

A new sequence with the element at index i replaced by x. Time: O(log(min(i,n-i)))

If i is out of range, returns a clone of self.

Source

pub fn truncate(&self, count: usize) -> Seq<T>

A new sequence consisting of only the first count elements. Time: O(log(min(count, n - count)))

If count >= self.len(), then returns a clone of self.

Source

pub fn skip(&self, count: usize) -> Seq<T>

A new sequence consisting of only the last count elements. Time: O(log(min(count,n - count)))

If count >= self.len(), then returns a clone of self.

Source

pub fn split(&self, n: usize) -> (Seq<T>, Seq<T>)

Two new sequences, consisting of the first count elements, and the remaining elements, respectively. Time: O(log(min(count,n-count)))

If count >= self.len(), then the first sequence is a clone of self and the second is empty.

Source

pub fn remove(&self, i: usize) -> Seq<T>

A new sequence with the element at index i removed, together with the element at index i, if it exists. Time: O(log(min(i,n-i)))

If i is out of range, then the returned sequence is a clone of self, and the element is None.

Source

pub fn insert(&self, i: usize, x: T) -> Seq<T>

A new sequence with x inserted at index i. Time: O(log(min(i,n-i)))

If i < self.len(), then x will immediately precede self[i] in the new sequence.

if i >= self.len(), then x will be the last element in the new sequence.

Source

pub fn get(&self, i: usize) -> Option<&T>

Get the element at index i, if it exists. Time: O(log(min(i,n-i)))

Source

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

An iterator over the sequence. Time: O(1)

Trait Implementations§

Source§

impl<T: 'static> Clone for Seq<T>

Source§

fn clone(&self) -> Seq<T>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Seq<T>
where T: Debug + 'static,

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: 'static> From<Vec<T>> for Seq<T>

Source§

fn from(v: Vec<T>) -> Seq<T>

Converts to this type from the input type.
Source§

impl<T: 'static> FromIterator<T> for Seq<T>

Source§

fn from_iter<I>(iter: I) -> Self
where I: IntoIterator<Item = T>,

Creates a value from an iterator. Read more
Source§

impl<T: 'static> Index<usize> for Seq<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &T

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, T: 'static> IntoIterator for &'a Seq<T>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Iter<'a, T>

Creates an iterator from a value. Read more
Source§

impl<T> Ord for Seq<T>
where T: Ord + 'static,

Source§

fn cmp(&self, other: &Seq<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T> PartialEq for Seq<T>
where T: PartialEq + 'static,

Source§

fn eq(&self, other: &Seq<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialOrd for Seq<T>
where T: PartialOrd + 'static,

Source§

fn partial_cmp(&self, other: &Seq<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> Eq for Seq<T>
where T: Eq + 'static,

Auto Trait Implementations§

§

impl<T> !Freeze for Seq<T>

§

impl<T> !RefUnwindSafe for Seq<T>

§

impl<T> !Send for Seq<T>

§

impl<T> !Sync for Seq<T>

§

impl<T> Unpin for Seq<T>

§

impl<T> !UnwindSafe for Seq<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.