ROSE
0.11.96.11
|
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 78 of file IndexedList.h.
#include <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. More... | |
IndexedList (const IndexedList &other) | |
Copy constructor. More... | |
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. More... | |
IndexedList & | operator= (const IndexedList &other) |
Assignment from another list. More... | |
template<class T2 > | |
IndexedList & | operator= (const IndexedList< T2 > &other) |
Assignment from another list. More... | |
const Allocator & | allocator () const |
Allocator. More... | |
bool | isEmpty () const |
Determines if this list is empty. More... | |
size_t | size () const |
Number of elements in list. More... | |
IndexedList & | pushFront (const Value &value) |
Insert at the front of the list. More... | |
IndexedList & | pushBack (const Value &value) |
Insert at the back of the list. More... | |
NodeIterator | insert (const ValueIterator &position, const Value &value) |
Insert element at position. More... | |
IndexedList & | insert (const ValueIterator &position, size_t nElmts, const Value &value) |
Insert multiple copies at position. More... | |
template<class OtherValueIterator > | |
IndexedList & | insertMultiple (const ValueIterator &position, const boost::iterator_range< OtherValueIterator > &range) |
Insert elements at position. More... | |
void | clear () |
Empties the list. More... | |
NodeIterator | erase (size_t id) |
Erase one element. More... | |
NodeIterator | eraseAt (const ValueIterator &position) |
Remove one element. More... | |
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. More... | |
boost::iterator_range< ConstNodeIterator > | nodes () const |
All elements. More... | |
boost::iterator_range< ValueIterator > | values () |
All elements. More... | |
boost::iterator_range< ConstValueIterator > | values () const |
All elements. More... | |
size_t | capacity () const |
Allocated capacity of the index. More... | |
void | capacity (size_t n) |
Allocated capacity of the index. More... | |
NodeIterator | find (size_t id) |
Lookup by ID. More... | |
ConstNodeIterator | find (size_t id) const |
Lookup by ID. More... | |
Node & | frontNode () |
First element of list. More... | |
const Node & | frontNode () const |
First element of list. More... | |
Value & | frontValue () |
First element of list. More... | |
const Value & | frontValue () const |
First element of list. More... | |
Node & | backNode () |
Last element of list. More... | |
const Node & | backNode () const |
Last element of list. More... | |
Value & | backValue () |
Last element of list. More... | |
const Value & | backValue () const |
Last element of list. More... | |
Node & | indexedNode (size_t id) |
Element reference by ID. More... | |
const Node & | indexedNode (size_t id) const |
Element reference by ID. More... | |
Value & | indexedValue (size_t id) |
Element reference by ID. More... | |
const Value & | indexedValue (size_t id) const |
Element reference by ID. More... | |
Value & | operator[] (size_t id) |
Element reference by ID. More... | |
const Value & | operator[] (size_t id) const |
Element reference by ID. More... | |
Optional< Value > | getOptional (size_t id) const |
Element reference by ID. More... | |
Value & | getOrElse (size_t id, Value &dflt) |
Element reference by ID. More... | |
const Value & | getOrElse (size_t id, const Value &dflt) const |
Element reference by ID. More... | |
const Value & | getOrDefault (size_t id) const |
Element reference by ID. More... | |
|
inlineexplicit |
Default constructor.
Create a new list which is empty.
Definition at line 358 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 365 of file IndexedList.h.
|
inlineexplicit |
Filling constructor.
Constructs the list by inserting nElmts
copies of val
.
Definition at line 382 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 393 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 404 of file IndexedList.h.
|
inline |
Allocator.
Returns a reference to the allocator that's being used for elements of this list.
Definition at line 418 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 432 of file IndexedList.h.
Referenced by Sawyer::Container::IndexedList< Edge, Allocator >::operator=(), Sawyer::Container::IndexedList< Edge, Allocator >::pushBack(), and Sawyer::Container::IndexedList< Edge, Allocator >::pushFront().
|
inline |
All elements.
Returns an iterator range that references all nodes in the container in their list order.
Definition at line 435 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 438 of file IndexedList.h.
Referenced by Sawyer::Container::IndexedList< Edge, Allocator >::IndexedList(), and Sawyer::Container::IndexedList< Edge, Allocator >::operator=().
|
inline |
All elements.
Returns an iterator range that references all nodes in the container in their list order.
Definition at line 441 of file IndexedList.h.
|
inline |
Determines if this list is empty.
Returns true only if this list contains no elements.
Definition at line 466 of file IndexedList.h.
Referenced by Sawyer::Container::IndexedList< Edge, Allocator >::backNode(), Sawyer::Container::IndexedList< Edge, Allocator >::frontNode(), and Sawyer::Container::Stack< size_t >::isEmpty().
|
inline |
Number of elements in list.
Returns the number of elements stored in the list in constant time.
Definition at line 473 of file IndexedList.h.
Referenced by Sawyer::Container::IndexedList< Edge, Allocator >::erase(), Sawyer::Container::Stack< size_t >::get(), Sawyer::Container::IndexedList< Edge, Allocator >::getOrDefault(), Sawyer::Container::IndexedList< Edge, Allocator >::getOrElse(), Sawyer::Container::IndexedList< Edge, Allocator >::indexedNode(), Sawyer::Container::Stack< size_t >::pop(), and Sawyer::Container::Stack< size_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 484 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 487 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 504 of file IndexedList.h.
Referenced by Sawyer::Container::IndexedList< Edge, Allocator >::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 509 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 527 of file IndexedList.h.
Referenced by Sawyer::Container::IndexedList< Edge, Allocator >::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 531 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 535 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 538 of file IndexedList.h.
|
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 548 of file IndexedList.h.
Referenced by Sawyer::Container::IndexedList< Edge, Allocator >::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 552 of file IndexedList.h.
|
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 556 of file IndexedList.h.
Referenced by Sawyer::Container::Stack< size_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 559 of file IndexedList.h.
|
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 570 of file IndexedList.h.
Referenced by Sawyer::Container::IndexedList< Edge, Allocator >::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 575 of file IndexedList.h.
|
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 580 of file IndexedList.h.
Referenced by Sawyer::Container::IndexedList< Edge, Allocator >::getOptional(), Sawyer::Container::IndexedList< Edge, Allocator >::getOrDefault(), Sawyer::Container::IndexedList< Edge, Allocator >::getOrElse(), and Sawyer::Container::IndexedList< Edge, Allocator >::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 583 of file IndexedList.h.
|
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 586 of file IndexedList.h.
|
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 589 of file IndexedList.h.
|
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 593 of file IndexedList.h.
|
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 597 of file IndexedList.h.
|
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 600 of file IndexedList.h.
|
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 604 of file IndexedList.h.
|
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 619 of file IndexedList.h.
|
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 628 of file IndexedList.h.
Referenced by Sawyer::Container::IndexedList< Edge, Allocator >::IndexedList(), Sawyer::Container::Stack< size_t >::push(), and Sawyer::Container::Stack< size_t >::Stack().
|
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 637 of file IndexedList.h.
Referenced by Sawyer::Container::IndexedList< Edge, Allocator >::insert(), Sawyer::Container::IndexedList< Edge, Allocator >::insertMultiple(), Sawyer::Container::IndexedList< Edge, Allocator >::operator=(), Sawyer::Container::IndexedList< Edge, Allocator >::pushBack(), and Sawyer::Container::IndexedList< Edge, Allocator >::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 650 of file IndexedList.h.
|
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 663 of file IndexedList.h.
Referenced by Sawyer::Container::IndexedList< Edge, Allocator >::operator=().
|
inline |
Empties the list.
Clears the list by removing all elements from it. This operation is linear time.
Definition at line 673 of file IndexedList.h.
Referenced by Sawyer::Container::IndexedList< Edge, Allocator >::operator=().
|
inline |
Erase one element.
Erases the element having the specified ID. The ID number must exist in the list.
Definition at line 685 of file IndexedList.h.
Referenced by Sawyer::Container::Stack< size_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 694 of file IndexedList.h.
Referenced by Sawyer::Container::IndexedList< Edge, Allocator >::erase().