Struct im::catlist::CatList [] [src]

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

A catenable list of values of type A.

A list data structure with O(1)* push and pop operations on both ends and O(1) concatenation of lists.

You usually want the Vector instead, which performs better on all operations except concatenation. If instant concatenation is what you need, the CatList is the cat for you.

Methods

impl<A> CatList<A>
[src]

[src]

Construct an empty list.

[src]

Construct a list with a single value.

[src]

Test whether a list is empty.

[src]

Get the length of a list.

Time: O(1)

Examples

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

[src]

Get the first element of a list.

If the list is empty, None is returned.

[src]

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

If the list is empty, None is returned.

Time: O(1)*

[src]

Get the last element of a list.

Time: O(1)*

If the list is empty, None is returned.

[src]

Get the list without the last element.

Time: O(1)*

If the list is empty, None is returned.

[src]

Get the tail of a list.

Time: O(1)

The tail means all elements in the list after the first item (the head). If the list only has one element, the result is an empty list. If the list is empty, the result is None.

[src]

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

Time: O(1)

Examples

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

[src]

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

Time: O(1)

[src]

Append the list other to the end of the current list, in place.

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

Time: O(1)

Examples

let mut l = catlist![1, 2, 3];
l.append_mut(catlist![7, 8, 9]);

assert_eq!(l, catlist![1, 2, 3, 7, 8, 9]);

[src]

Push a value onto the front of a list, updating in place.

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

Time: O(1)

[src]

Push a value onto the back of a list, updating in place.

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

Time: O(1)

[src]

Remove a value from the front of a list, updating in place. Returns the removed value.

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

Time: O(1)*

[src]

Remove a value from the back of a list, updating in place. Returns the removed value.

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

Time: O(1)*

[src]

Construct a list with a new value appended to the back of the current list.

snoc, for the curious, is cons spelled backwards, to denote that it works on the back of the list rather than the front. If you don't find that as clever as whoever coined the term no doubt did, this method is also available as push_back().

Time: O(1)

[src]

Construct a list with a new value appended to the back of the current list.

Time: O(1)

[src]

Get the head and the tail of a list.

This function performs both the head function and the tail function in one go, returning a tuple of the head and the tail, or None if the list is empty.

Time: O(1)*

Examples

This can be useful when pattern matching your way through a list:

fn walk_through_list<A>(list: &CatList<A>) where A: Debug {
    match list.pop_front() {
        None => (),
        Some((ref head, ref tail)) => {
            print!("{:?}", head);
            walk_through_list(tail)
        }
    }
}

[src]

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

This is an alias for push_front, for the Lispers in the house.

Time: O(1)

[src]

Get the head and the tail of a list.

If the list is empty, None is returned.

This is an alias for pop_front.

Time: O(1)*

[src]

[src]

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

If the list is empty, None is returned.

This is an alias for pop_back.

Time: O(1)*

Important traits for Iter<A>
[src]

Get an iterator over a list.

[src]

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

Please note that if all you want is to iterate over the list from back to front, it is much more efficient to use a reversed iterator rather than doing the work of reversing the list first.

Time: O(n)

Examples

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

[src]

Sort a list using a comparator function.

Time: O(n log n)

[src]

Sort a list of ordered elements.

Time: O(n log n)

Examples

assert_eq!(
  catlist![2, 8, 1, 6, 3, 7, 5, 4].sort(),
  CatList::from_iter(1..9)
);

[src]

Insert an item into a sorted list.

Constructs a new list with the new item inserted before the first item in the list 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!(
  catlist![2, 4, 5].insert(1).insert(3).insert(6),
  catlist![1, 2, 3, 4, 5, 6]
);

Trait Implementations

impl<A> Clone for CatList<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 CatList<A>
[src]

[src]

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

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

The resulting type after applying the + operator.

[src]

Performs the + operation.

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

The resulting type after applying the + operator.

[src]

Performs the + operation.

impl<A, R> Extend<R> for CatList<A> where
    A: Ord,
    R: Shared<A>, 
[src]

[src]

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

impl<A: PartialEq> PartialEq for CatList<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 CatList<A>
[src]

impl<A: PartialOrd> PartialOrd for CatList<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 CatList<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: Hash> Hash for CatList<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: Debug> Debug for CatList<A>
[src]

[src]

Formats the value using the given formatter. Read more

impl<A> IntoIterator for CatList<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 CatList<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> Sum for CatList<A>
[src]

[src]

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

impl<A, T> FromIterator<T> for CatList<A> where
    T: Shared<A>, 
[src]

[src]

Creates a value from an iterator. Read more

impl<'a, A, T> From<&'a [T]> for CatList<A> where
    &'a T: Shared<A>, 
[src]

[src]

Performs the conversion.

impl<'a, A, T> From<&'a Vec<T>> for CatList<A> where
    &'a T: Shared<A>, 
[src]

[src]

Performs the conversion.

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

[src]

Performs the conversion.

impl<A> From<Vec<Arc<A>>> for CatList<A>
[src]

[src]

Performs the conversion.

Auto Trait Implementations

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

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