41 template<
class KEY,
class INFO,
class CMP,
bool isConst,
bool isReverse>
44 template<
class KEY,
class INFO,
class CMP>
47 template<
class KEY,
class INFO,
class CMP>
50 template<
class KEY,
class INFO,
class CMP>
53 template<
class KEY,
class INFO,
class CMP>
64 template<
class KEY,
class INFO,
class CMP = StdComparer<KEY> >
83 Element(
const KEY &key,
const INFO &info,
int height)
84 : m_key(key), m_info(info), m_height(height)
115 p =
static_cast<Element**
>(realloc(m_prev, newHeight *
sizeof(
Element*)));
140 SortedSequence(std::initializer_list < std::pair < KEY, INFO >> initList);
264 void del(
const KEY &key);
360 m_dummy =
new Element(m_realHeight);
366 void grow(
int newHeight);
378 template<
class KEY,
class INFO,
class CMP,
bool isConst,
bool isReverse>
385 using Element =
typename std::conditional<isConst,
387 typename SortedSequence<KEY,INFO,CMP>::Element>
::type;
400 : m_pElement(it.m_pElement) { }
405 : m_pElement(it.m_pElement) { }
410 return m_pElement->m_key;
416 return m_pElement->m_info;
420 bool valid()
const {
return m_pElement !=
nullptr; }
424 m_pElement = isReverse ? predElement() : succElement();
431 m_pElement = isReverse ? predElement() : succElement();
437 m_pElement = isReverse ? succElement() : predElement();
444 m_pElement = isReverse ? succElement() : predElement();
450 return isReverse ? predElement() : succElement();
455 return isReverse ? succElement() : predElement();
475 typename SortedSequence<KEY,INFO,CMP>::Element *
succElement()
const {
477 return (m_pElement->m_next[0]->m_height > 0) ? m_pElement->m_next[0] :
nullptr;
480 typename SortedSequence<KEY,INFO,CMP>::Element *
predElement()
const {
482 return (m_pElement->m_prev[0]->m_height > 0) ? m_pElement->m_prev[0] :
nullptr;
486 template<
class KEY,
class INFO,
class CMP>
490 for (
const auto &p : initList)
491 insert(p.first, p.second);
495 template<
class KEY,
class INFO,
class CMP>
507 template<
class KEY,
class INFO,
class CMP>
519 template<
class KEY,
class INFO,
class CMP>
532 template<
class KEY,
class INFO,
class CMP>
558 template<
class KEY,
class INFO,
class CMP>
576 template<
class KEY,
class INFO,
class CMP>
584 pElement = pElement[h]->m_next;
593 template<
class KEY,
class INFO,
class CMP>
599 template<
class KEY,
class INFO,
class CMP>
606 template<
class KEY,
class INFO,
class CMP>
614 pElement = pElement[h]->m_next;
622 template<
class KEY,
class INFO,
class CMP>
628 template<
class KEY,
class INFO,
class CMP>
635 template<
class KEY,
class INFO,
class CMP>
643 for(
int i = newHeight; i-- >
m_height; ) {
647 m_height = newHeight;
650 template<
class KEY,
class INFO,
class CMP>
664 template<
class KEY,
class INFO,
class CMP>
672 pCurrent = pCurrent->
m_next[h];
698 template<
class KEY,
class INFO,
class CMP>
707 template<
class KEY,
class INFO,
class CMP>
721 template<
class KEY,
class INFO,
class CMP>
726 for(
int h = 0; h < p->
m_height; ++h) {
738 template<
class KEY,
class INFO,
class CMP>
750 template<
class KEY,
class INFO,
class CMP>
756 for(
int h = 0; h < p->
m_height; ++h) {
764 template<
class KEY,
class INFO,
class CMP>
775 template<
class KEY,
class INFO,
class CMP>
782 template<
class KEY,
class INFO,
class CMP>
790 template<
class KEY,
class INFO,
class CMP>
797 template<
class KEY,
class INFO,
class CMP>
805 template<
class KEY,
class INFO,
class CMP>
812 template<
class KEY,
class INFO,
class CMP>
820 template<
class KEY,
class INFO,
class CMP>
827 template<
class KEY,
class INFO,
class CMP>
void removeElement(Element *p)
iterator end()
Returns an iterator pointing to one past the last element.
Maintains a sequence of (key,info) pairs sorted by key.
Declarations for Comparer objects.
iterator begin()
Returns an iterator pointing to the first element.
Element(int height)
Creates a dummy (stop) element with given height.
Iterators for sorted sequences.
SortedSequence(const CMP &comparer=CMP())
Constructs an initially empty sorted sequence.
Declaration of memory manager for allocating small pieces of memory.
int m_size
number of elements stored in the sequence.
const_iterator cend() const
Returns a const-iterator pointing to one past the last element.
bool empty() const
Returns true if the sequence is empty, false otherwise.
const_iterator minItem() const
Returns a const-iterator to the element with minimal key if the sequence is not empty, an invalid const-iterator otherwise.
std::minstd_rand m_rng
Random number generator.
SortedSequenceIteratorBase< KEY, INFO, CMP, isConst, isReverse > & operator--()
Moves the iterator one item backward (prefix notation)
typename std::conditional< isConst, const typename SortedSequence< KEY, INFO, CMP >::Element, typename SortedSequence< KEY, INFO, CMP >::Element >::type Element
Element * m_dummy
dummy element representing the head and tail of the skiplist.
SortedSequenceIteratorBase< KEY, INFO, CMP, isConst, isReverse > & operator++()
Move the iterator one item forward (prefix notation)
iterator insertAfter(iterator it, const KEY &key, const INFO &info)
Adds a new element <key, info> after element it.
#define OGDF_THROW(CLASS)
Replacement for throw.
const_reverse_iterator maxItem() const
Returns a const reverse iterator to the element with maximal key if the sequence is not empty...
SortedSequenceIteratorBase< KEY, INFO, CMP, isConst, isReverse > & operator=(const SortedSequenceIteratorBase< KEY, INFO, CMP, isConst, isReverse > &it)
Assignment operator.
iterator locate(const KEY &key)
Returns an iterator to the element < k1, i1 > such that k1 is minimal with k1 ≥ key, or a null iterator if no such element exists.
SortedSequence< KEY, INFO, CMP >::Element * succElement() const
bool valid() const
Returns true if the iterator points to an element.
void clear()
Removes all elements from the sorted sequence.
std::conditional< isConst, const INFO, INFO >::type & info() const
Returns the info of the sequence element pointed to.
iterator minItem()
Returns an iterator to the element with minimal key if the sequence is not empty, an invalid iterator...
const Element * _lookup(const KEY &key) const
SortedSequenceIteratorBase(const SortedSequenceIteratorBase< KEY, INFO, CMP, isConst, isReverse > &it)
Copy constructor.
SortedSequence< KEY, INFO, CMP >::Element * predElement() const
int m_realHeight
actual height of head/tail arrays.
Element(const KEY &key, const INFO &info, int height)
Creates a skiplist element for(key,info) and given height.
SortedSequenceIteratorBase< KEY, INFO, CMP, isConst, isReverse > operator++(int)
Moves the iterator one item forward (postfix notation)
const_reverse_iterator crend() const
Returns a const reverse iterator pointing to one before the first element.
SortedSequenceConstIterator< KEY, INFO, CMP > const_iterator
The const-iterator type for sorted sequences (bidirectional iterator).
iterator lookup(const KEY &key)
Returns an iterator to the element with key key, or a null iterator if no such element exists...
long unsigned int randomSeed()
Returns a random value suitable as initial seed for a random number engine.
SortedSequenceIteratorBase< KEY, INFO, CMP, isConst, isReverse > operator--(int)
Moves the iterator one item backward (postfix notation)
reverse_iterator rbegin()
Returns a reverse iterator pointing to the last element.
Implementation of the Reverse class for the reverse iteration of containers.
bool operator==(const SortedSequence< KEY, INFO, CMP > &S)
Returns true if the keys stored in this sequence equal the keys in S, false otherwise.
const KEY & key() const
Returns the key of the sequence element pointed to.
SortedSequenceIteratorBase()
Creates an invalid (null-) iterator.
iterator insert(const KEY &key, const INFO &info)
Updates information for key if contained in sequence, or adds a new element <key, info>...
int m_height
current height of head/tail.
SortedSequenceIteratorBase< KEY, INFO, CMP, isConst, isReverse > pred() const
Returns an iterator pointing to the previous element in the sequence.
bool operator!=(const SortedSequence< KEY, INFO, CMP > &S)
Returns false if the keys stored in this sequence equal the keys in S, true otherwise.
Exception thrown when not enough memory is available to execute an algorithm.
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
Element ** m_prev
array of predecessor elements.
Element ** m_next
array of successor elements.
void reverseElements(Element *p, Element *q)
const_reverse_iterator crbegin() const
Returns a const reverse iterator pointing to the last element.
void insertElementAfterElement(Element *p, Element *q)
bool operator==(const SortedSequenceIteratorBase< KEY, INFO, CMP, isConst, isReverse > &it) const
Equality operator.
void del(const KEY &key)
Removes the element with key key (if such an element exists).
bool operator!=(const SortedSequenceIteratorBase< KEY, INFO, CMP, isConst, isReverse > &it) const
Inequality operator.
int size() const
Returns the current size of the sequence, i.e., the number of stored elements.
SortedSequenceIteratorBase(const SortedSequenceIteratorBase< KEY, INFO, CMP, isArgConst, isArgReverse > &it)
Copy constructor.
void grow(int newHeight)
Increases the element's height to newHeight.
reverse_iterator rend()
Returns a reverse iterator pointing to one before the first element.
SortedSequenceIteratorBase< KEY, INFO, CMP, isConst, isReverse > succ() const
Returns an iterator pointing to the next element in the sequence.
SortedSequenceIterator< KEY, INFO, CMP > iterator
The iterator type for sorted sequences (bidirectional iterator).
INFO m_info
stores the associated information.
int m_height
the height of the skiplist element.
const Element * _locate(const KEY &key) const
reverse_iterator maxItem()
Returns a reverse iterator to the element with maximal key if the sequence is not empty...
The namespace for all OGDF objects.
SortedSequence< KEY, INFO, CMP > & operator=(const SortedSequence< KEY, INFO, CMP > &S)
Assignment operator.
SortedSequenceIteratorBase(Element *pElement)
Creates an iterator pointing to pElement.
void reverseItems(iterator itBegin, iterator itEnd)
Reverses the items in the subsequence from itBegin to itEnd (inclusive).
Internal structure to hold the items and internal forward/backward pointers of the skiplist...
std::uniform_int_distribution m_randomBits
void delItem(iterator it)
Removes the element to which it points from the sequence.
const_iterator cbegin() const
Returns a const-iterator pointing to the first element.
~SortedSequence()
Destructor.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
int randomHeightAndGrow()