stdx.collection

This module defines generic collections.

More...

Modules

array
module stdx.collection.array
Undocumented in source.
common
module stdx.collection.common

Utility and ancillary artifacts of stdx.collection.

dlist
module stdx.collection.dlist
Undocumented in source.
hashtable
module stdx.collection.hashtable
Undocumented in source.
slist
module stdx.collection.slist
Undocumented in source.

Detailed Description

Collection primitives

Collections do not form a class hierarchy, instead they implement a common set of primitives (see table below). These primitives each guarantee a specific worst case complexity and thus allow generic code to be written independently of the collection implementation.

The following table describes the common set of primitives that collections implement. A collection need not implement all primitives, but if a primitive is implemented, it must support the syntax described in the syntax column with the semantics described in the description column, and it must not have a worst-case complexity worse than denoted in big-O notation in the O(·) column. Below, C means a collection type, c is a value of collection type, n$(SUBSCRIPT x) represents the effective length of value x, which could be a single element (in which case n$(SUBSCRIPT x) is 1), a collection, or a range.

collection primitives
SyntaxO(·)Description
C(x)n$(SUBSCRIPT x)Creates a collection of type C from either another collection, a range or an element. The created collection must not be a null reference even if x is empty.
c.dupn$(SUBSCRIPT c)Returns a duplicate of the collection.
c ~ xn$(SUBSCRIPT c) + n$(SUBSCRIPT x)Returns the concatenation of c and x. x may be a single element or an input range.
x ~ cn$(SUBSCRIPT c) + n$(SUBSCRIPT x)Returns the concatenation of x and c. x may be a single element or an input range type.
Iteration
c.popFront()1Advances to the next element in the collection.
c.save1Return a shallow copy of the collection.
c[]n$(SUBSCRIPT c)Returns a range iterating over the entire collection, in a collection-defined order.
c[a .. b]n$(SUBSCRIPT c)Fetches a portion of the collection from key a to key b.
Capacity
c.empty1Returns true if the collection has no elements, false otherwise.
c.length1Returns the number of elements in the collection.
c.length = nmax(n$(SUBSCRIPT c), n)Forces the number of elements in the collection to n. If the collection ends up growing, the added elements are initialized in a collection-dependent manner (usually with T.init).
c.capacityn$(SUBSCRIPT c)Returns the maximum number of elements that can be stored in the collection without triggering a reallocation.
c.reserve(x)n$(SUBSCRIPT c)Forces capacity to at least x without reducing it.
Access
c.front1Returns the first element of the collection, in a collection-defined order.
c.front = v1Assigns v to the first element of the collection.
c.backlog n$(SUBSCRIPT c)Returns the last element of the collection, in a collection-defined order.
c.back = vn$(SUBSCRIPT c)Assigns v to the last element of the collection.
c[x]n$(SUBSCRIPT c)Provides indexed access into the collection. The index type is collection-defined. A collection may define several index types (and consequently overloaded indexing).
c[x] = vn$(SUBSCRIPT c)Sets element at specified index into the collection.
c[x] $(I op)= vn$(SUBSCRIPT c)Performs read-modify-write operation at specified index into the collection.
Operations
e in cn$(SUBSCRIPT c)Returns nonzero if e is found in c.
Modifiers
c ~= xn$(SUBSCRIPT c) + n$(SUBSCRIPT x)Appends x to c. x may be a single element or an input range type.
c.clear()n$(SUBSCRIPT c)Removes all elements in c.
c.insert(pos, x)n$(SUBSCRIPT x)Inserts x at pos in c. x may be a single element or an input range type.
c.insertBack(x)n$(SUBSCRIPT c) + n$(SUBSCRIPT x)Inserts x at the back of c. x may be a single element or an input range type.
c.remove()1Removes the front element of c.

Meta

License

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at ).

Authors

Eduard Staniloiu, Andrei Alexandrescu