Collections Cheat Sheet#
Common Collection Types#
Class |
Location |
Description |
---|---|---|
|
Multi-dimensional data, much like a matrix. |
|
|
A one-dimensional array. Vectors provide fast random access. |
|
|
A vector that can have elements directly added and removed without requiring a complete copy. |
|
|
A linked list. |
|
|
A double-ended queue. |
|
|
A set is for efficiently tracking membership. |
|
|
A set with bits for members. |
|
|
A vector optimized for storing bit values. |
|
|
A vector of bytes. |
|
|
A mapping between keys and values. |
|
|
A |
Note
Because of the default comparison function for <table>
, it is
important to use <string-table>
when the keys will be strings.
Mutable vs. Immutable#
Many operations don’t modify the collection passed in. The exception
is when you use an operation ending in !
on a stretchy collection.
For this reason, if you want to modify a collection frequently, be sure to pay attention to the type of collection that you’re working with.
In many cases, you will need to assign the result of an operation back to the source collection:
threads := add(threads, thread);
In cases where you are modifying a collection frequently, you may want
to consider using a <stretchy-vector>
rather than a <vector>
or some other type of collection.
Common Operations#
Class |
Operation |
Summary |
---|---|---|
Returns the first true value obtained by iterating over one or more collections. |
||
Iterates over one or more collections for side effect. |
||
Returns true if its argument is empty. |
||
Returns true if a predicate returns true when applied to all corresponding elements of a set of collections. |
||
Fills a collection with a specified value. |
||
Returns the key in a collection such that the corresponding collection element satisfies a predicate. |
||
Returns a sequence containing the keys of its
collection argument. This is commonly used with
|
||
Iterates over one or more collections and collects
the results in a freshly allocated collection.
See also |
||
Returns true if a collection contains a particular value. |
||
Combines the elements of a collection and a seed
value into a single value by repeatedly applying a
binary function. See also |
||
Replaces those collection elements that satisfy a predicate. |
||
Returns the size of its argument. |
||
Adds an element to a sequence. |
||
Adds a new element to a sequence. |
||
Returns those elements of a sequence that satisfy a
predicate. See also |
||
Returns the concatenation of one or more sequences
in a sequence of a type determined by the
|
||
Returns a freshly allocated copy of some subsequence of a sequence. |
||
Returns the intersection of two sequences. |
||
Removes an element from a sequence. |
||
Returns a sequence without duplicates. |
||
Replaces a portion of a sequence with the elements of another sequence. |
||
Returns a sequence with elements in the reverse order of its argument sequence. |
||
Returns a sequence containing the elements of its argument sequence, sorted. |
||
Returns the position where a pattern appears in a sequence. |
||
Returns the union of two sequences. |
||
Returns the head of a list. |
||
Returns the tail of a list. |
||
Adds an element to the front of a deque. |
||
Removes and returns the first element of a deque. |
||
Adds an element to the end of a deque. |
||
Removes and returns an element from the end of a deque. |
||
Modifies an explicit key collection so it no longer has a particular key. |