Struct im::vector::Vector [] [src]

pub struct Vector<A> { /* fields omitted */ }

A persistent vector of elements of type A.

This is an implementation of bitmapped vector tries, which offers highly efficient (amortised linear time) index lookups as well as appending elements to, or popping elements off, either side of the vector.

This is generally the best data structure if you're looking for something list like. If you don't need lookups or updates by index, but do need fast concatenation of whole lists, you should use the CatList instead.

If you're familiar with the Clojure variant, this improves on it by being efficiently extensible at the front as well as the back. If you're familiar with Immutable.js, this is essentially the same, but with easier mutability because Rust has the advantage of direct access to the garbage collector (which in our case is just Arc).

Methods

impl<A> Vector<A>
[src]

[src]

Construct an empty vector.

[src]

Construct a vector with a single value.

[src]

Get the length of a vector.

Time: O(1)

Examples

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

[src]

Test whether a list is empty.

Time: O(1)

Important traits for Iter<A>
[src]

Get an iterator over a vector.

Time: O(log n) per next() call

[src]

Get the first element of a vector.

If the vector is empty, None is returned.

Time: O(log n)

[src]

Get the vector without the first element.

If the vector is empty, None is returned.

Time: O(log n)

[src]

Get the last element of a vector.

If the vector is empty, None is returned.

Time: O(log n)

[src]

Get the vector without the last element.

If the vector is empty, None is returned.

Time: O(log n)

[src]

Get the value at index index in a vector.

Returns None if the index is out of bounds.

Time: O(log n)

[src]

Get the value at index index in a vector, directly.

Panics if the index is out of bounds.

Time: O(log n)

[src]

Create a new vector with the value at index index updated.

Panics if the index is out of bounds.

Time: O(log n)

[src]

Update the value at index index in a vector.

Panics if the index is out of bounds.

This is a copy-on-write operation, so that the parts of the vector's structure which are shared with other vectors will be safely copied before mutating.

Time: O(log n)

[src]

Construct a vector with a new value prepended to the end of the current vector.

Time: O(log n)

[src]

Update a vector in place with a new value prepended to the end of it.

This is a copy-on-write operation, so that the parts of the vector's structure which are shared with other vectors will be safely copied before mutating.

Time: O(log n)

[src]

Construct a vector with a new value prepended to the front of the current vector.

Time: O(log n)

[src]

Update a vector in place with a new value prepended to the front of it.

This is a copy-on-write operation, so that the parts of the vector's structure which are shared with other vectors will be safely copied before mutating.

Time: O(log n)

[src]

Get the last element of a vector, as well as the vector with the last element removed.

If the vector is empty, None is returned.

Time: O(log n)

[src]

Remove the last element of a vector in place and return it.

This is a copy-on-write operation, so that the parts of the vector's structure which are shared with other vectors will be safely copied before mutating.

Time: O(log n)

[src]

Get the first element of a vector, as well as the vector with the first element removed.

If the vector is empty, None is returned.

Time: O(log n)

[src]

Remove the first element of a vector in place and return it.

This is a copy-on-write operation, so that the parts of the vector's structure which are shared with other vectors will be safely copied before mutating.

Time: O(log n)

[src]

Split a vector at a given index, returning a vector containing every element before of the index and a vector containing every element from the index onward.

Time: O(log n)

[src]

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

Time: O(log n)

[src]

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

Time: O(log n)

[src]

Construct a vector with the elements from start_index until end_index in the current vector.

Time: O(log n)

[src]

Append the vector other to the end of the current vector.

Time: O(n) where n = the length of other

Examples

assert_eq!(
  vector![1, 2, 3].append(vector![7, 8, 9]),
  vector![1, 2, 3, 7, 8, 9]
);

[src]

Write from an iterator into a vector, starting at the given index.

This will overwrite elements in the vector until the iterator ends or the end of the vector is reached.

Time: O(n) where n = the length of the iterator

[src]

Construct a vector which is the reverse of the current vector.

Time: O(1)

Examples

assert_eq!(
  vector![1, 2, 3, 4, 5].reverse(),
  vector![5, 4, 3, 2, 1]
);

[src]

Reverse a vector in place.

Time: O(1)

Examples

let mut v = vector![1, 2, 3, 4, 5];
v.reverse_mut();

assert_eq!(
  v,
  vector![5, 4, 3, 2, 1]
);

[src]

Sort a vector of ordered elements.

Time: O(n log n) worst case

Examples

assert_eq!(
  vector![2, 8, 1, 6, 3, 7, 5, 4].sort(),
  vector![1, 2, 3, 4, 5, 6, 7, 8]
);

[src]

Sort a vector using a comparator function.

Time: O(n log n) roughly

[src]

Insert an item into a sorted vector.

Constructs a new vector with the new item inserted before the first item in the vector which is larger than the new item, as determined by the Ord trait.

Please note that this is a very inefficient operation; if you want a sorted list, consider if OrdSet might be a better choice for you.

Time: O(n)

Examples

assert_eq!(
  vector![2, 4, 5].insert(1).insert(3).insert(6),
  vector![1, 2, 3, 4, 5, 6]
);

Trait Implementations

impl<A> Clone for Vector<A>
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<A> Default for Vector<A>
[src]

[src]

Returns the "default value" for a type. Read more

impl<A: Debug> Debug for Vector<A>
[src]

[src]

Formats the value using the given formatter. Read more

impl<A: PartialEq> PartialEq for Vector<A>
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl<A: Eq> Eq for Vector<A>
[src]

impl<A: PartialOrd> PartialOrd for Vector<A>
[src]

[src]

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

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<A: Ord> Ord for Vector<A>
[src]

[src]

This method returns an Ordering between self and other. Read more

1.21.0
[src]

Compares and returns the maximum of two values. Read more

1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl<A> Add for Vector<A>
[src]

The resulting type after applying the + operator.

[src]

Performs the + operation.

impl<'a, A> Add for &'a Vector<A>
[src]

The resulting type after applying the + operator.

[src]

Performs the + operation.

impl<A: Hash> Hash for Vector<A>
[src]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl<A> Sum for Vector<A>
[src]

[src]

Method which takes an iterator and generates Self from the elements by "summing up" the items. Read more

impl<A, R: Shared<A>> Extend<R> for Vector<A>
[src]

[src]

Extends a collection with the contents of an iterator. Read more

impl<A, RA: Shared<A>> FromIterator<RA> for Vector<A>
[src]

[src]

Creates a value from an iterator. Read more

impl<A> IntoIterator for Vector<A>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

[src]

Creates an iterator from a value. Read more

impl<'a, A> IntoIterator for &'a Vector<A>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

[src]

Creates an iterator from a value. Read more

impl<A> From<Vec<A>> for Vector<A>
[src]

[src]

Performs the conversion.

Auto Trait Implementations

impl<A> Send for Vector<A> where
    A: Send + Sync

impl<A> Sync for Vector<A> where
    A: Send + Sync