40 template<
class KEY,
class INFO,
class CMP>
43 template<
class KEY,
class INFO,
class CMP>
54 template<
class KEY,
class INFO,
class CMP = StdComparer<KEY> >
71 Element(
const KEY &key,
const INFO &info,
int height)
72 : m_key(key), m_info(info), m_height(height)
103 p =
static_cast<Element**
>(realloc(m_prev, newHeight *
sizeof(
Element*)));
124 SortedSequence(std::initializer_list < std::pair < KEY, INFO >> initList);
248 void del(
const KEY &key);
344 m_dummy =
new Element(m_realHeight);
350 void grow(
int newHeight);
362 template<
class KEY,
class INFO,
class CMP>
371 : m_pElement(pElement) { }
379 : m_pElement(it.m_pElement) { }
382 const KEY &
key()
const {
return m_pElement->
m_key; }
389 bool valid()
const {
return m_pElement !=
nullptr; }
393 m_pElement = succElement();
400 m_pElement = succElement();
406 m_pElement = predElement();
413 m_pElement = predElement();
419 return succElement();
424 return predElement();
455 template<
class KEY,
class INFO,
class CMP>
463 : m_pElement(pElement) { }
471 : m_pElement(it.m_pElement) { }
475 : m_pElement(it.m_pElement) { }
478 const KEY &
key()
const {
return m_pElement->
m_key; }
485 bool valid()
const {
return m_pElement != 0; }
489 m_pElement = succElement();
496 m_pElement = succElement();
502 m_pElement = predElement();
509 m_pElement = predElement();
515 return succElement();
520 return predElement();
550 template<
class KEY,
class INFO,
class CMP>
554 for (
const auto &p : initList)
555 insert(p.first, p.second);
559 template<
class KEY,
class INFO,
class CMP>
571 template<
class KEY,
class INFO,
class CMP>
583 template<
class KEY,
class INFO,
class CMP>
596 template<
class KEY,
class INFO,
class CMP>
622 template<
class KEY,
class INFO,
class CMP>
640 template<
class KEY,
class INFO,
class CMP>
648 pElement = pElement[h]->m_next;
657 template<
class KEY,
class INFO,
class CMP>
663 template<
class KEY,
class INFO,
class CMP>
670 template<
class KEY,
class INFO,
class CMP>
678 pElement = pElement[h]->m_next;
686 template<
class KEY,
class INFO,
class CMP>
692 template<
class KEY,
class INFO,
class CMP>
699 template<
class KEY,
class INFO,
class CMP>
707 for(
int i = newHeight; i-- >
m_height; ) {
711 m_height = newHeight;
714 template<
class KEY,
class INFO,
class CMP>
728 template<
class KEY,
class INFO,
class CMP>
736 pCurrent = pCurrent->
m_next[h];
762 template<
class KEY,
class INFO,
class CMP>
771 template<
class KEY,
class INFO,
class CMP>
785 template<
class KEY,
class INFO,
class CMP>
790 for(
int h = 0; h < p->
m_height; ++h) {
802 template<
class KEY,
class INFO,
class CMP>
814 template<
class KEY,
class INFO,
class CMP>
820 for(
int h = 0; h < p->
m_height; ++h) {
828 template<
class KEY,
class INFO,
class CMP>
839 template<
class KEY,
class INFO,
class CMP>
846 template<
class KEY,
class INFO,
class CMP>
854 template<
class KEY,
class INFO,
class CMP>
861 template<
class KEY,
class INFO,
class CMP>
869 template<
class KEY,
class INFO,
class CMP>
876 template<
class KEY,
class INFO,
class CMP>
884 template<
class KEY,
class INFO,
class CMP>
891 template<
class KEY,
class INFO,
class CMP>
void removeElement(Element *p)
SortedSequence< KEY, INFO, CMP >::Element * succElement() const
iterator end()
Returns an iterator pointing to one past the last element.
Maintains a sequence of (key,info) pairs sorted by key.
int empty() const
Returns true if the sequence is empty, false otherwise.
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.
SortedSequence(const CMP &comparer=CMP())
Constructs an initially empty sorted sequence.
iterator maxItem()
Returns an iterator to the element with maximal key if the sequence is not empty, an invalid iterator...
Declaration of memory manager for allocating small pieces of memory.
SortedSequenceIterator< KEY, INFO, CMP > & operator--()
Moves the iterator one item backward (prefix notation)
int m_size
number of elements stored in the sequence.
SortedSequenceConstIterator< KEY, INFO, CMP > & operator=(const SortedSequenceConstIterator< KEY, INFO, CMP > &it)
Assignment operator.
const_iterator cend() const
Returns a const-iterator pointing to one past the last element.
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.
bool operator==(const SortedSequenceConstIterator< KEY, INFO, CMP > &it) const
Equality operator.
Element * m_dummy
dummy element representing the head and tail of the skiplist.
SortedSequenceIterator()
Creates an invalid (null-) iterator.
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.
SortedSequenceConstIterator(const typename SortedSequence< KEY, INFO, CMP >::Element *pElement)
Creates an iterator pointing to pElement.
SortedSequenceIterator< KEY, INFO, CMP > succ() const
Returns an iterator pointing to the next element in the sequence.
const SortedSequence< KEY, INFO, CMP >::Element * m_pElement
const_iterator maxItem() const
Returns a const-iterator to the element with maximal key if the sequence is not empty, an invalid const-iterator otherwise.
const_iterator crend() const
Returns a const-iterator pointing to one before the first element.
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.
SortedSequenceConstIterator(const SortedSequenceIterator< KEY, INFO, CMP > &it)
Creates an iterator pointing to the same element as it.
void clear()
Removes all elements from the sorted sequence.
const_iterator crbegin() const
Returns a const-iterator pointing to the last element.
iterator minItem()
Returns an iterator to the element with minimal key if the sequence is not empty, an invalid iterator...
SortedSequenceIterator< KEY, INFO, CMP > & operator=(const SortedSequenceIterator< KEY, INFO, CMP > &it)
Assignment operator.
const Element * _lookup(const KEY &key) const
SortedSequenceIterator< KEY, INFO, CMP > & operator++()
Move the iterator one item forward (prefix notation)
SortedSequence< KEY, INFO, CMP >::Element * m_pElement
SortedSequenceIterator(const SortedSequenceIterator< KEY, INFO, CMP > &it)
Copy constructor.
bool operator==(const SortedSequenceIterator< KEY, INFO, CMP > &it) const
Equality operator.
SortedSequenceConstIterator< KEY, INFO, CMP > & operator++()
Moves the iterator one item forward (prefix notation).
SortedSequenceConstIterator< KEY, INFO, CMP > operator--(int)
Moves the iterator one item backward (postfix notation).
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.
const INFO & info() const
Returns the info of the sequence element pointed to.
SortedSequenceConstIterator(const SortedSequenceConstIterator< KEY, INFO, CMP > &it)
Copy constructor.
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...
SortedSequence< KEY, INFO, CMP >::Element * predElement() const
long unsigned int randomSeed()
Returns a random value suitable as initial seed for a random number engine.
bool operator!=(const SortedSequenceConstIterator< KEY, INFO, CMP > &it) const
Inequality operator.
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 iterators for sorted sequences.
Iterators for sorted sequences.
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.
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.
iterator rbegin()
Returns an iterator pointing to the last element.
Element ** m_next
array of successor elements.
void reverseElements(Element *p, Element *q)
void insertElementAfterElement(Element *p, Element *q)
SortedSequenceIterator< KEY, INFO, CMP > pred() const
Returns an iterator pointing to the previous element in the sequence.
void del(const KEY &key)
Removes the element with key key (if such an element exists).
bool valid() const
Returns true if the iterator points to an element.
int size() const
Returns the current size of the sequence, i.e., the number of stored elements.
SortedSequence< KEY, INFO, CMP >::Element * predElement() const
void grow(int newHeight)
Increases the element's height to newHeight.
SortedSequenceConstIterator< KEY, INFO, CMP > operator++(int)
Moves the iterator one item forward (postfix notation).
SortedSequenceConstIterator()
Creates an invalid (null-) iterator.
iterator rend()
Returns an iterator pointing to one before the first element.
SortedSequenceIterator< KEY, INFO, CMP > operator--(int)
Moves the iterator one item backward (postfix notation)
const KEY & key() const
Returns the key of the sequence element pointed to.
SortedSequenceConstIterator< KEY, INFO, CMP > pred() const
Returns an iterator pointing to the previous 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.
INFO & info() const
Returns the info of the sequence element pointed to.
const Element * _locate(const KEY &key) const
bool valid() const
Returns true if the iterator points to an element.
SortedSequenceIterator(typename SortedSequence< KEY, INFO, CMP >::Element *pElement)
Creates an iterator pointing to pElement.
The namespace for all OGDF objects.
SortedSequence< KEY, INFO, CMP > & operator=(const SortedSequence< KEY, INFO, CMP > &S)
Assignment operator.
SortedSequenceConstIterator< KEY, INFO, CMP > succ() const
Returns an iterator pointing to the next element in the sequence.
void reverseItems(iterator itBegin, iterator itEnd)
Reverses the items in the subsequence from itBegin to itEnd (inclusive).
SortedSequenceConstIterator< KEY, INFO, CMP > & operator--()
Moves the iterator one item backward (prefix notation).
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.
bool operator!=(const SortedSequenceIterator< KEY, INFO, CMP > &it) const
Inequality operator.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
SortedSequence< KEY, INFO, CMP >::Element * succElement() const
const KEY & key() const
Returns the key of the sequence element pointed to.
int randomHeightAndGrow()
SortedSequenceIterator< KEY, INFO, CMP > operator++(int)
Moves the iterator one item forward (postfix notation)