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>
impl<T: 'static> Seq<T>
Sourcepub fn push_front(&self, x: T) -> Seq<T>
pub fn push_front(&self, x: T) -> Seq<T>
A new sequence that is self with x added to the front. Time: O(1)
Sourcepub fn push_back(&self, x: T) -> Seq<T>
pub fn push_back(&self, x: T) -> Seq<T>
A new sequence that is self with x added to the back. Time: O(1)
Sourcepub fn append(&self, other: &Seq<T>) -> Seq<T>
pub fn append(&self, other: &Seq<T>) -> Seq<T>
The concatenation of self with other. Time: O(log(min(n1,n2)))
Sourcepub fn pop_front(&self) -> Seq<T>
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)
Sourcepub fn pop_back(&self) -> Seq<T>
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)
Sourcepub fn adjust<F>(&self, i: usize, func: F) -> Seq<T>
pub fn adjust<F>(&self, i: usize, func: F) -> Seq<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.
Sourcepub fn update(&self, i: usize, x: T) -> Seq<T>
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.
Sourcepub fn truncate(&self, count: usize) -> Seq<T>
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.
Sourcepub fn skip(&self, count: usize) -> Seq<T>
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.
Sourcepub fn split(&self, n: usize) -> (Seq<T>, Seq<T>)
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.
Sourcepub fn remove(&self, i: usize) -> Seq<T>
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.
Sourcepub fn insert(&self, i: usize, x: T) -> Seq<T>
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.