ROSE 0.11.145.147
|
Doubly-linked list with constant-time indexing.
This container is a hybrid of a doubly-linked list and a vector, having these features:
Element ID numbers are consecutive unsigned integers between zero (inclusive) and the size of the list (exclusive), and are convenient for indexing into lookup tables that the user keeps separate from the list itself. However, in order to meet the requirement the erasure is a constant-time operation, when an element is erased from the list, the element that had the largest ID number is given the ID of the element that was erased. In other words, ID numbers are not stable across erasure. This is actually not much different than using array indices as ID numbers and erasing an item from the middle of the array, except that the approach taken by IndexedList is contant rather than linear time.
Also, the order of ID numbers is not required to be identical to the order of the elements in the list. One may iterate over the elements in list order by using iterators, or iterate over the elements in ID order by using a simple "for" loop.
This container, as with the rest of the library, uses CamelCase names for types and methods, where types begin with an upper-case letter and methods begin with a lower-case letter. This may be surprising for users accustomed to the STL naming scheme. For instance, iterators are named Iterator
, ConstIterator
, etc., rather than iterator
, const_iterator
, etc.
Definition at line 75 of file IndexedList.h.
#include <Sawyer/IndexedList.h>
Classes | |
class | ConstNodeIterator |
List const node bidirectional iterator. More... | |
class | ConstValueIterator |
List const value bidirectional iterator. More... | |
class | Node |
Combination user-defined value and ID number. More... | |
class | NodeIterator |
List node bidirectional iterator. More... | |
class | ValueIterator |
List value bidirectional iterator. More... | |
Public Types | |
typedef T | Value |
Type of values stored in this container. | |
typedef Alloc | Allocator |
Allocator for the storage nodes. | |
Public Member Functions | |
IndexedList (const Allocator &allocator=Allocator()) | |
Default constructor. | |
IndexedList (const IndexedList &other) | |
Copy constructor. | |
template<class T2 , class Alloc2 > | |
IndexedList (const IndexedList< T2, Alloc2 > &other, const Allocator &=Allocator()) | |
Copy constructor. | |
IndexedList (size_t nElmts, const Value &val=Value(), const Allocator &allocator=Allocator()) | |
Filling constructor. | |
IndexedList & | operator= (const IndexedList &other) |
Assignment from another list. | |
template<class T2 > | |
IndexedList & | operator= (const IndexedList< T2 > &other) |
Assignment from another list. | |
const Allocator & | allocator () const |
Allocator. | |
bool | isEmpty () const |
Determines if this list is empty. | |
size_t | size () const |
Number of elements in list. | |
IndexedList & | pushFront (const Value &value) |
Insert at the front of the list. | |
IndexedList & | pushBack (const Value &value) |
Insert at the back of the list. | |
NodeIterator | insert (const ValueIterator &position, const Value &value) |
Insert element at position. | |
IndexedList & | insert (const ValueIterator &position, size_t nElmts, const Value &value) |
Insert multiple copies at position. | |
template<class OtherValueIterator > | |
IndexedList & | insertMultiple (const ValueIterator &position, const boost::iterator_range< OtherValueIterator > &range) |
Insert elements at position. | |
void | clear () |
Empties the list. | |
NodeIterator | erase (size_t id) |
Erase one element. | |
NodeIterator | eraseAt (const ValueIterator &position) |
Remove one element. | |
NodeIterator | eraseAtMultiple (const boost::iterator_range< NodeIterator > &range) |
NodeIterator | eraseAtMultiple (const boost::iterator_range< ValueIterator > &range) |
void | dump (std::ostream &o) const |
boost::iterator_range< NodeIterator > | nodes () |
All elements. | |
boost::iterator_range< ConstNodeIterator > | nodes () const |
All elements. | |
boost::iterator_range< ValueIterator > | values () |
All elements. | |
boost::iterator_range< ConstValueIterator > | values () const |
All elements. | |
size_t | capacity () const |
Allocated capacity of the index. | |
void | capacity (size_t n) |
Allocated capacity of the index. | |
NodeIterator | find (size_t id) |
Lookup by ID. | |
ConstNodeIterator | find (size_t id) const |
Lookup by ID. | |
Node & | frontNode () |
First element of list. | |
const Node & | frontNode () const |
First element of list. | |
Value & | frontValue () |
First element of list. | |
const Value & | frontValue () const |
First element of list. | |
Node & | backNode () |
Last element of list. | |
const Node & | backNode () const |
Last element of list. | |
Value & | backValue () |
Last element of list. | |
const Value & | backValue () const |
Last element of list. | |
Node & | indexedNode (size_t id) |
Element reference by ID. | |
const Node & | indexedNode (size_t id) const |
Element reference by ID. | |
Value & | indexedValue (size_t id) |
Element reference by ID. | |
const Value & | indexedValue (size_t id) const |
Element reference by ID. | |
Value & | operator[] (size_t id) |
Element reference by ID. | |
const Value & | operator[] (size_t id) const |
Element reference by ID. | |
Optional< Value > | getOptional (size_t id) const |
Element reference by ID. | |
Value & | getOrElse (size_t id, Value &dflt) |
Element reference by ID. | |
const Value & | getOrElse (size_t id, const Value &dflt) const |
Element reference by ID. | |
const Value & | getOrDefault (size_t id) const |
Element reference by ID. | |
typedef T Sawyer::Container::IndexedList< T, Alloc >::Value |
Type of values stored in this container.
Definition at line 77 of file IndexedList.h.
typedef Alloc Sawyer::Container::IndexedList< T, Alloc >::Allocator |
Allocator for the storage nodes.
Definition at line 78 of file IndexedList.h.
|
inlineexplicit |
Default constructor.
Create a new list which is empty.
Definition at line 400 of file IndexedList.h.
|
inline |
Copy constructor.
The newly constructed list's allocator is copy-constructed from the source list's allocator. For allocators that contain state (like pool allocators), this copies the settings but not the pools of allocated data.
Definition at line 407 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::pushBack(), and Sawyer::Container::IndexedList< T, Alloc >::values().
|
inline |
Copy constructor.
Definition at line 414 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::pushBack(), and Sawyer::Container::IndexedList< T, Alloc >::values().
|
inlineexplicit |
Filling constructor.
Constructs the list by inserting nElmts
copies of val
.
Definition at line 424 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::pushBack().
|
inline |
Definition at line 452 of file IndexedList.h.
|
inline |
Assignment from another list.
Causes this list to look like the other
list in that this list has copies of the nodes of the other list. However, the ID numbers in this list may be different than the ID numbers of the other list.
Definition at line 435 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::clear(), Sawyer::Container::IndexedList< T, Alloc >::insertMultiple(), Sawyer::Container::IndexedList< T, Alloc >::nodes(), and Sawyer::Container::IndexedList< T, Alloc >::values().
|
inline |
Assignment from another list.
Causes this list to look like the other
list in that this list has copies of the nodes of the other list. However, the ID numbers in this list may be different than the ID numbers of the other list.
Definition at line 446 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::clear(), Sawyer::Container::IndexedList< T, Alloc >::insert(), Sawyer::Container::IndexedList< T, Alloc >::nodes(), and Sawyer::Container::IndexedList< T, Alloc >::values().
|
inline |
Allocator.
Returns a reference to the allocator that's being used for elements of this list.
Definition at line 460 of file IndexedList.h.
|
inline |
All elements.
Returns an iterator range that references all nodes in the container in their list order.
Definition at line 474 of file IndexedList.h.
Referenced by Sawyer::Container::IndexedList< T, Alloc >::operator=(), Sawyer::Container::IndexedList< T, Alloc >::operator=(), Sawyer::Container::IndexedList< T, Alloc >::pushBack(), and Sawyer::Container::IndexedList< T, Alloc >::pushFront().
|
inline |
All elements.
Returns an iterator range that references all nodes in the container in their list order.
Definition at line 477 of file IndexedList.h.
|
inline |
All elements.
Returns an iterator range that references all nodes in the container in their list order.
Definition at line 480 of file IndexedList.h.
Referenced by Sawyer::Container::IndexedList< T, Alloc >::IndexedList(), Sawyer::Container::IndexedList< T, Alloc >::IndexedList(), Sawyer::Container::IndexedList< T, Alloc >::operator=(), and Sawyer::Container::IndexedList< T, Alloc >::operator=().
|
inline |
All elements.
Returns an iterator range that references all nodes in the container in their list order.
Definition at line 483 of file IndexedList.h.
|
inline |
Determines if this list is empty.
Returns true only if this list contains no elements.
Definition at line 508 of file IndexedList.h.
Referenced by Sawyer::Container::IndexedList< T, Alloc >::backNode(), Sawyer::Container::IndexedList< T, Alloc >::backNode(), Sawyer::Container::IndexedList< T, Alloc >::frontNode(), Sawyer::Container::IndexedList< T, Alloc >::frontNode(), and Sawyer::Container::Stack< T >::isEmpty().
|
inline |
Number of elements in list.
Returns the number of elements stored in the list in constant time.
Definition at line 515 of file IndexedList.h.
Referenced by Sawyer::Container::IndexedList< T, Alloc >::erase(), Sawyer::Container::Stack< T >::get(), Sawyer::Container::Stack< T >::get(), Sawyer::Container::IndexedList< T, Alloc >::getOrDefault(), Sawyer::Container::IndexedList< T, Alloc >::getOrElse(), Sawyer::Container::IndexedList< T, Alloc >::getOrElse(), Sawyer::Container::IndexedList< T, Alloc >::indexedNode(), Sawyer::Container::IndexedList< T, Alloc >::indexedNode(), Sawyer::Container::Stack< T >::pop(), and Sawyer::Container::Stack< T >::size().
|
inline |
Allocated capacity of the index.
Each container maintains an index in order to achieve constant time lookup by node ID, and this method queries or changes the number of elements that the index is prepared to handle. If more elements are added to the index than it is prepared to handle, then a new index is created in linear time.
Definition at line 526 of file IndexedList.h.
|
inline |
Allocated capacity of the index.
Each container maintains an index in order to achieve constant time lookup by node ID, and this method queries or changes the number of elements that the index is prepared to handle. If more elements are added to the index than it is prepared to handle, then a new index is created in linear time.
Definition at line 529 of file IndexedList.h.
|
inline |
Lookup by ID.
Returns a list iterator for the node with the specified ID number. The ID number must exist; i.e., it must be less than the number of elements in the list. This method executes in constant time.
Definition at line 546 of file IndexedList.h.
Referenced by Sawyer::Container::IndexedList< T, Alloc >::erase().
|
inline |
Lookup by ID.
Returns a list iterator for the node with the specified ID number. The ID number must exist; i.e., it must be less than the number of elements in the list. This method executes in constant time.
Definition at line 551 of file IndexedList.h.
|
inline |
First element of list.
Returns a reference to the first element stored in this list. The list must not be empty.
Definition at line 569 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::isEmpty().
Referenced by Sawyer::Container::IndexedList< T, Alloc >::frontValue(), and Sawyer::Container::IndexedList< T, Alloc >::frontValue().
|
inline |
First element of list.
Returns a reference to the first element stored in this list. The list must not be empty.
Definition at line 573 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::isEmpty().
|
inline |
First element of list.
Returns a reference to the first element stored in this list. The list must not be empty.
Definition at line 577 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::frontNode(), and Sawyer::Container::IndexedList< T, Alloc >::Node::value().
|
inline |
First element of list.
Returns a reference to the first element stored in this list. The list must not be empty.
Definition at line 580 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::frontNode(), and Sawyer::Container::IndexedList< T, Alloc >::Node::value().
|
inline |
Last element of list.
Returns a reference to the last element stored in this list. The list must not be empty.
Definition at line 590 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::isEmpty().
Referenced by Sawyer::Container::IndexedList< T, Alloc >::backValue(), and Sawyer::Container::IndexedList< T, Alloc >::backValue().
|
inline |
Last element of list.
Returns a reference to the last element stored in this list. The list must not be empty.
Definition at line 594 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::isEmpty().
|
inline |
Last element of list.
Returns a reference to the last element stored in this list. The list must not be empty.
Definition at line 598 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::backNode(), and Sawyer::Container::IndexedList< T, Alloc >::Node::value().
Referenced by Sawyer::Container::Stack< T >::top(), and Sawyer::Container::Stack< T >::top().
|
inline |
Last element of list.
Returns a reference to the last element stored in this list. The list must not be empty.
Definition at line 601 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::backNode(), and Sawyer::Container::IndexedList< T, Alloc >::Node::value().
|
inline |
Element reference by ID.
Returns a reference to the element with the specified ID number. The ID number must exist in this list. ID numbers are consecutive, beginning at zero.
Definition at line 612 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::size().
Referenced by Sawyer::Container::IndexedList< T, Alloc >::indexedValue(), and Sawyer::Container::IndexedList< T, Alloc >::indexedValue().
|
inline |
Element reference by ID.
Returns a reference to the element with the specified ID number. The ID number must exist in this list. ID numbers are consecutive, beginning at zero.
Definition at line 617 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::size().
|
inline |
Element reference by ID.
Returns a reference to the element with the specified ID number. The ID number must exist in this list. ID numbers are consecutive, beginning at zero.
Definition at line 622 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::indexedNode(), and Sawyer::Container::IndexedList< T, Alloc >::Node::value().
Referenced by Sawyer::Container::IndexedList< T, Alloc >::getOptional(), Sawyer::Container::IndexedList< T, Alloc >::getOrDefault(), Sawyer::Container::IndexedList< T, Alloc >::getOrElse(), Sawyer::Container::IndexedList< T, Alloc >::getOrElse(), Sawyer::Container::IndexedList< T, Alloc >::operator[](), and Sawyer::Container::IndexedList< T, Alloc >::operator[]().
|
inline |
Element reference by ID.
Returns a reference to the element with the specified ID number. The ID number must exist in this list. ID numbers are consecutive, beginning at zero.
Definition at line 625 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::indexedNode(), and Sawyer::Container::IndexedList< T, Alloc >::Node::value().
|
inline |
Element reference by ID.
Returns a reference to the element with the specified ID number. The ID number must exist in this list. ID numbers are consecutive, beginning at zero.
Definition at line 628 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::indexedValue().
|
inline |
Element reference by ID.
Returns a reference to the element with the specified ID number. The ID number must exist in this list. ID numbers are consecutive, beginning at zero.
Definition at line 631 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::indexedValue().
|
inline |
Element reference by ID.
Returns a reference to the element with the specified ID number. The ID number must exist in this list. ID numbers are consecutive, beginning at zero.
Definition at line 635 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::indexedValue().
|
inline |
Element reference by ID.
Returns a reference to the element with the specified ID number. The ID number must exist in this list. ID numbers are consecutive, beginning at zero.
Definition at line 639 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::indexedValue(), and Sawyer::Container::IndexedList< T, Alloc >::size().
|
inline |
Element reference by ID.
Returns a reference to the element with the specified ID number. The ID number must exist in this list. ID numbers are consecutive, beginning at zero.
Definition at line 642 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::indexedValue(), and Sawyer::Container::IndexedList< T, Alloc >::size().
|
inline |
Element reference by ID.
Returns a reference to the element with the specified ID number. The ID number must exist in this list. ID numbers are consecutive, beginning at zero.
Definition at line 646 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::indexedValue(), and Sawyer::Container::IndexedList< T, Alloc >::size().
|
inline |
Insert at the front of the list.
Inserts a copy of the value
at the beginning of the list. The new copy is given an ID number which one larger than the previously largest ID number in this list. No other element ID numbers are changed by this operation.
Definition at line 661 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::insert(), and Sawyer::Container::IndexedList< T, Alloc >::nodes().
|
inline |
Insert at the back of the list.
Inserts a copy of the value
at the end of the list. The new copy is given an ID number which one larger than the previously largest ID number in this list. No other element ID numbers are changed by this operation.
Definition at line 670 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::insert(), and Sawyer::Container::IndexedList< T, Alloc >::nodes().
Referenced by Sawyer::Container::IndexedList< T, Alloc >::IndexedList(), Sawyer::Container::IndexedList< T, Alloc >::IndexedList(), Sawyer::Container::IndexedList< T, Alloc >::IndexedList(), Sawyer::Container::Stack< T >::Stack(), and Sawyer::Container::Stack< T >::push().
|
inline |
Insert element at position.
Inserts a copy of value
at the indicated position in the list. The new copy is given an ID number which one larger than the previously largest ID number in this list. No other element ID numbers are changed by this operation.
Definition at line 679 of file IndexedList.h.
Referenced by Sawyer::Container::IndexedList< T, Alloc >::insert(), Sawyer::Container::IndexedList< T, Alloc >::insertMultiple(), Sawyer::Container::IndexedList< T, Alloc >::operator=(), Sawyer::Container::IndexedList< T, Alloc >::pushBack(), and Sawyer::Container::IndexedList< T, Alloc >::pushFront().
|
inline |
Insert multiple copies at position.
Inserts nElmts
copies of value
at the indicated position. The new copies are given sequential ID numbers in the order they are inserted, with the first inserted element having an ID number which is one larger than the previously largest ID number in this list. No other element ID numbers are changed by this operation.
Definition at line 692 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::insert().
|
inline |
Insert elements at position.
Inserts, at the indicated position, copies of the elements specified by the iterator range. The new copies are given sequential ID numbers in the order they are inserted, with the first inserted element having an ID number which is one larger than the previously largest ID number in this list. No other element ID numbers are changed by this operation.
Definition at line 705 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::insert().
Referenced by Sawyer::Container::IndexedList< T, Alloc >::operator=().
|
inline |
Empties the list.
Clears the list by removing all elements from it. This operation is linear time.
Definition at line 715 of file IndexedList.h.
Referenced by Sawyer::Container::IndexedList< T, Alloc >::operator=(), and Sawyer::Container::IndexedList< T, Alloc >::operator=().
|
inline |
Erase one element.
Erases the element having the specified ID. The ID number must exist in the list.
Definition at line 727 of file IndexedList.h.
References Sawyer::Container::IndexedList< T, Alloc >::eraseAt(), Sawyer::Container::IndexedList< T, Alloc >::find(), and Sawyer::Container::IndexedList< T, Alloc >::size().
Referenced by Sawyer::Container::Stack< T >::pop().
|
inline |
Remove one element.
Removes the element at the indicated position. The ID number of one other element (the one with the now highest ID) will be changed to fill the gap left by the erasure.
Definition at line 736 of file IndexedList.h.
Referenced by Sawyer::Container::IndexedList< T, Alloc >::erase().
|
inline |
Definition at line 753 of file IndexedList.h.
|
inline |
Definition at line 757 of file IndexedList.h.
|
inline |
Definition at line 765 of file IndexedList.h.