42template<
class KEY,
class INFO,
class CMP,
bool isConst,
bool isReverse>
43class SortedSequenceIteratorBase;
45template<
class KEY,
class INFO,
class CMP>
48template<
class KEY,
class INFO,
class CMP>
51template<
class KEY,
class INFO,
class CMP>
54template<
class KEY,
class INFO,
class CMP>
65template<
class KEY,
class INFO,
class CMP = StdComparer<KEY>>
378template<
class KEY,
class INFO,
class CMP,
bool isConst,
bool isReverse>
386 typename std::conditional<isConst, const typename SortedSequence<KEY, INFO, CMP>::Element,
416 typename std::conditional<isConst, const INFO, INFO>::type&
info()
const {
489template<
class KEY,
class INFO,
class CMP>
493 insert(p.first, p.second);
497template<
class KEY,
class INFO,
class CMP>
499 : m_comparer(
S.m_comparer), m_rng(
randomSeed()), m_randomBits(0, 1) {
508template<
class KEY,
class INFO,
class CMP>
510 : m_comparer(
S.m_comparer)
512 , m_height(
S.m_height)
513 , m_realHeight(
S.m_realHeight)
515 , m_randomBits(0, 1) {
523template<
class KEY,
class INFO,
class CMP>
530 it = insertAfter(it,
pS->m_key,
pS->m_info);
536template<
class KEY,
class INFO,
class CMP>
541 while (item != m_dummy) {
549 m_comparer =
S.m_comparer;
551 m_height =
S.m_height;
552 m_realHeight =
S.m_realHeight;
561template<
class KEY,
class INFO,
class CMP>
563 if (m_size !=
S.m_size) {
568 while (p != m_dummy) {
569 if (!m_comparer.equal(p->
m_key,
pS->m_key)) {
579template<
class KEY,
class INFO,
class CMP>
581 const KEY& key)
const {
582 int h = m_height - 1;
588 }
else if (--
h < 0) {
597template<
class KEY,
class INFO,
class CMP>
603template<
class KEY,
class INFO,
class CMP>
605 const KEY& key)
const {
609template<
class KEY,
class INFO,
class CMP>
611 const KEY& key)
const {
612 int h = m_height - 1;
618 }
else if (--
h < 0) {
625template<
class KEY,
class INFO,
class CMP>
631template<
class KEY,
class INFO,
class CMP>
633 const KEY& key)
const {
637template<
class KEY,
class INFO,
class CMP>
644 for (
int i =
newHeight; i-- > m_height;) {
645 m_dummy->m_next[i] = m_dummy;
646 m_dummy->m_prev[i] = m_dummy;
651template<
class KEY,
class INFO,
class CMP>
654 while (m_randomBits(m_rng) == 1) {
665template<
class KEY,
class INFO,
class CMP>
667 const KEY& key,
const INFO& info) {
668 int h = m_height - 1;
672 if (
pCurrent->m_next[
h] != m_dummy && m_comparer.less(
pCurrent->m_next[
h]->m_key, key)) {
679 && m_comparer.equal(
pCurrent->m_next[0]->m_key, key)) {
691 int nh = randomHeightAndGrow();
699template<
class KEY,
class INFO,
class CMP>
707template<
class KEY,
class INFO,
class CMP>
712 int nh = randomHeightAndGrow();
720template<
class KEY,
class INFO,
class CMP>
725 while (
q != m_dummy &&
q->m_height <=
h) {
726 q =
q->m_prev[
h - 1];
732 q->m_next[
h] =
r->m_prev[
h] = p;
736template<
class KEY,
class INFO,
class CMP>
742 insertElementAfterElement(
r,
q);
746template<
class KEY,
class INFO,
class CMP>
758template<
class KEY,
class INFO,
class CMP>
767template<
class KEY,
class INFO,
class CMP>
769 return (m_dummy->m_next[0] != m_dummy) ? m_dummy->m_next[0] :
nullptr;
772template<
class KEY,
class INFO,
class CMP>
775 return (m_dummy->m_next[0] != m_dummy) ? m_dummy->m_next[0] : 0;
778template<
class KEY,
class INFO,
class CMP>
783template<
class KEY,
class INFO,
class CMP>
789template<
class KEY,
class INFO,
class CMP>
792 return (m_dummy->m_prev[0] != m_dummy) ? m_dummy->m_prev[0] : 0;
795template<
class KEY,
class INFO,
class CMP>
798 return (m_dummy->m_prev[0] != m_dummy) ? m_dummy->m_prev[0] : 0;
801template<
class KEY,
class INFO,
class CMP>
806template<
class KEY,
class INFO,
class CMP>
Implementation of the Reverse class for the reverse iteration of containers.
Exception thrown when not enough memory is available to execute an algorithm.
Maintains a sequence of (key,info) pairs sorted by key.
reverse_iterator rend()
Returns a reverse iterator pointing to one before the first element.
SortedSequence(const CMP &comparer=CMP())
Constructs an initially empty sorted sequence.
iterator insertAfter(iterator it, const KEY &key, const INFO &info)
Adds a new element <key, info> after element it.
void delItem(iterator it)
Removes the element to which it points from the sequence.
std::minstd_rand m_rng
Random number generator.
const_iterator cend() const
Returns a const-iterator pointing to one past the last element.
bool operator==(const SortedSequence< KEY, INFO, CMP > &S)
Returns true if the keys stored in this sequence equal the keys in S, false otherwise.
int m_realHeight
actual height of head/tail arrays.
const_iterator minItem() const
Returns a const-iterator to the element with minimal key if the sequence is not empty,...
void reverseElements(Element *p, Element *q)
const_reverse_iterator crend() const
Returns a const reverse iterator pointing to one before the first element.
SortedSequence< KEY, INFO, CMP > & operator=(const SortedSequence< KEY, INFO, CMP > &S)
Assignment operator.
int m_size
number of elements stored in the sequence.
const_reverse_iterator maxItem() const
Returns a const reverse iterator to the element with maximal key if the sequence is not empty,...
void reverseItems(iterator itBegin, iterator itEnd)
Reverses the items in the subsequence from itBegin to itEnd (inclusive).
const Element * _lookup(const KEY &key) const
SortedSequenceIterator< KEY, INFO, CMP > iterator
The iterator type for sorted sequences (bidirectional iterator).
const Element * _locate(const KEY &key) const
iterator lookup(const KEY &key)
Returns an iterator to the element with key key, or a null iterator if no such element exists.
iterator begin()
Returns an iterator pointing to the first element.
int size() const
Returns the current size of the sequence, i.e., the number of stored elements.
bool operator!=(const SortedSequence< KEY, INFO, CMP > &S)
Returns false if the keys stored in this sequence equal the keys in S, true otherwise.
Element * m_dummy
dummy element representing the head and tail of the skiplist.
iterator insert(const KEY &key, const INFO &info)
Updates information for key if contained in sequence, or adds a new element <key, info>.
iterator locate(const KEY &key)
Returns an iterator to the element < k1, i1 > such that k1 is minimal with k1 ≥ key,...
reverse_iterator maxItem()
Returns a reverse iterator to the element with maximal key if the sequence is not empty,...
iterator minItem()
Returns an iterator to the element with minimal key if the sequence is not empty, an invalid iterator...
SortedSequenceReverseIterator< KEY, INFO, CMP > reverse_iterator
The reverse iterator type for sorted sequences (bidirectional iterator).
int randomHeightAndGrow()
SortedSequenceConstReverseIterator< KEY, INFO, CMP > const_reverse_iterator
The const reverse iterator type for sorted sequences (bidirectional iterator).
~SortedSequence()
Destructor.
std::uniform_int_distribution m_randomBits
void del(const KEY &key)
Removes the element with key key (if such an element exists).
void insertElementAfterElement(Element *p, Element *q)
SortedSequenceConstIterator< KEY, INFO, CMP > const_iterator
The const-iterator type for sorted sequences (bidirectional iterator).
bool empty() const
Returns true if the sequence is empty, false otherwise.
const_reverse_iterator crbegin() const
Returns a const reverse iterator pointing to the last element.
void clear()
Removes all elements from the sorted sequence.
iterator end()
Returns an iterator pointing to one past the last element.
int m_height
current height of head/tail.
reverse_iterator rbegin()
Returns a reverse iterator pointing to the last element.
void removeElement(Element *p)
const_iterator cbegin() const
Returns a const-iterator pointing to the first element.
Iterators for sorted sequences.
SortedSequenceIteratorBase(const SortedSequenceIteratorBase< KEY, INFO, CMP, isArgConst, isArgReverse > &it)
Copy constructor.
SortedSequenceIteratorBase< KEY, INFO, CMP, isConst, isReverse > operator++(int)
Moves the iterator one item forward (postfix notation)
SortedSequenceIteratorBase< KEY, INFO, CMP, isConst, isReverse > & operator++()
Move the iterator one item forward (prefix notation)
std::conditional< isConst, constINFO, INFO >::type & info() const
Returns the info of the sequence element pointed to.
bool operator==(const SortedSequenceIteratorBase< KEY, INFO, CMP, isConst, isReverse > &it) const
Equality operator.
const KEY & key() const
Returns the key of the sequence element pointed to.
SortedSequenceIteratorBase(Element *pElement)
Creates an iterator pointing to pElement.
SortedSequenceIteratorBase< KEY, INFO, CMP, isConst, isReverse > operator--(int)
Moves the iterator one item backward (postfix notation)
SortedSequenceIteratorBase< KEY, INFO, CMP, isConst, isReverse > & operator--()
Moves the iterator one item backward (prefix notation)
SortedSequenceIteratorBase()
Creates an invalid (null-) iterator.
SortedSequenceIteratorBase(const SortedSequenceIteratorBase< KEY, INFO, CMP, isConst, isReverse > &it)
Copy constructor.
SortedSequenceIteratorBase< KEY, INFO, CMP, isConst, isReverse > & operator=(const SortedSequenceIteratorBase< KEY, INFO, CMP, isConst, isReverse > &it)
Assignment operator.
bool valid() const
Returns true if the iterator points to an element.
SortedSequenceIteratorBase< KEY, INFO, CMP, isConst, isReverse > pred() const
Returns an iterator pointing to the previous element in the sequence.
typename std::conditional< isConst, const typename SortedSequence< KEY, INFO, CMP >::Element, typename SortedSequence< KEY, INFO, CMP >::Element >::type Element
bool operator!=(const SortedSequenceIteratorBase< KEY, INFO, CMP, isConst, isReverse > &it) const
Inequality operator.
SortedSequenceIteratorBase< KEY, INFO, CMP, isConst, isReverse > succ() const
Returns an iterator pointing to the next element in the sequence.
SortedSequence< KEY, INFO, CMP >::Element * succElement() const
SortedSequence< KEY, INFO, CMP >::Element * predElement() const
Declarations for Comparer objects.
#define OGDF_THROW(CLASS)
Replacement for throw.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
long unsigned int randomSeed()
Returns a random value suitable as initial seed for a random number engine.
Declaration of memory manager for allocating small pieces of memory.
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
Internal structure to hold the items and internal forward/backward pointers of the skiplist.
int m_height
the height of the skiplist element.
Element ** m_next
array of successor elements.
Element ** m_prev
array of predecessor elements.
void grow(int newHeight)
Increases the element's height to newHeight.
Element(int height)
Creates a dummy (stop) element with given height.
Element(const Element &)=delete
INFO m_info
stores the associated information.
Element(const KEY &key, const INFO &info, int height)
Creates a skiplist element for(key,info) and given height.