Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb_skiplistlib::skip_list::Node< T, _Compare > Class Template Reference

Forward reference. More...

Collaboration diagram for duckdb_skiplistlib::skip_list::Node< T, _Compare >:

Classes

struct  _Pool

Public Member Functions

 Node (const T &value, _Compare _cmp, _Pool &pool)
const T & value () const
 Returns the node value.
bool has (const T &value) const
const Node< T, _Compare > * at (size_t idx) const
bool index (const T &value, size_t &idx, size_t level) const
size_t height () const
 Number of linked lists that this node engages in, minimum 1.
const Node< T, _Compare > * next () const
size_t width (size_t level) const
const Node< T, _Compare > * pNode (size_t level) const
SwappableNodeRefStack< T, _Compare > & nodeRefs ()
 Get a reference to the node references.
const SwappableNodeRefStack< T, _Compare > & nodeRefs () const
 Get a reference to the node references.
Node< T, _Compare > * insert (const T &value)
Node< T, _Compare > * remove (size_t call_level, const T &value)
size_t size_of () const
IntegrityCheck lacksIntegrity (size_t headnode_height) const
IntegrityCheck lacksIntegrityRefsInSet (const std::set< const Node< T, _Compare > * > &nodeSet) const

Protected Member Functions

Node< T, _Compare > * _adjRemoveRefs (size_t level, Node< T, _Compare > *pNode)
void Initialize (const T &value)

Protected Attributes

T _value
SwappableNodeRefStack< T, _Compare > _nodeRefs
_Compare _compare
_Pool & _pool

Private Member Functions

 Node (const Node &that)
Node & operator= (const Node &that) const

Detailed Description

template<typename T, typename _Compare>
class duckdb_skiplistlib::skip_list::Node< T, _Compare >

Forward reference.

A single node in a Skip List containing a value and references to other downstream Node objects.

Template Parameters
TThe type of the Skip List Node values.
_CompareA comparison function for type T.

Constructor & Destructor Documentation

◆ Node()

template<typename T, typename _Compare>
duckdb_skiplistlib::skip_list::Node< T, _Compare >::Node ( const T & value,
_Compare _cmp,
_Pool & pool )

Constructor. This also creates a SwappableNodeRefStack of random height by tossing a virtual coin.

Template Parameters
TThe type of the Skip List Node values.
_CompareA comparison function for type T.
Parameters
valueThe value of the Node.
_cmpThe comparison function.
486657 : \
486658 _value(value), _compare(_cmp), _pool(pool) {
486659 Initialize(value);
Forward reference.
Definition duckdb.cpp:486549
const T & value() const
Returns the node value.
Definition duckdb.cpp:486584
Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ value()

template<typename T, typename _Compare>
const T & duckdb_skiplistlib::skip_list::Node< T, _Compare >::value ( ) const
inline

Returns the node value.

Here is the caller graph for this function:

◆ has()

template<typename T, typename _Compare>
bool duckdb_skiplistlib::skip_list::Node< T, _Compare >::has ( const T & value) const

Returns true if the value is present in the skip list from this node onwards.

Template Parameters
TThe type of the Skip List Node values.
_CompareA comparison function for type T.
Parameters
valueThe value to look for.
Returns
true if the value is present in the skip list from this node onwards.
486671 {
486672 assert(_nodeRefs.height());
486673 assert(value == value); // value can not be NaN for example
486674 // Effectively: if (value > _value) {
486675 if (_compare(_value, value)) {
486676 for (size_t l = _nodeRefs.height(); l-- > 0;) {
486677 if (_nodeRefs[l].pNode && _nodeRefs[l].pNode->has(value)) {
486678 return true;
486679 }
486680 }
486681 return false;
486682 }
486683 // Effectively: return value == _value; // false if value smaller
486684 return !_compare(value, _value) && !_compare(_value, value);
size_t height() const
Number of linked lists that this node engages in, minimum 1.
Definition duckdb.cpp:486593
const Node< T, _Compare > * pNode(size_t level) const
Definition duckdb.cpp:486792
#define assert(x)
Definition duckdb.cpp:486071
Here is the call graph for this function:

◆ at()

template<typename T, typename _Compare>
const Node< T, _Compare > * duckdb_skiplistlib::skip_list::Node< T, _Compare >::at ( size_t idx) const

Return a pointer to the n'th node. Start (or continue) from the highest level, drop down a level if not found. Return nullptr if not found at level 0.

Template Parameters
TThe type of the Skip List Node values.
_CompareA comparison function for type T.
Parameters
idxThe index from hereon. If zero return this.
Returns
Pointer to the Node or nullptr.
486698 {
486699 assert(_nodeRefs.height());
486700 if (idx == 0) {
486701 return this;
486702 }
486703 for (size_t l = _nodeRefs.height(); l-- > 0;) {
486704 if (_nodeRefs[l].pNode && _nodeRefs[l].width <= idx) {
486705 return _nodeRefs[l].pNode->at(idx - _nodeRefs[l].width);
486706 }
486707 }
486708 return nullptr;
size_t width(size_t level) const
Definition duckdb.cpp:486778
Here is the call graph for this function:

◆ index()

template<typename T, typename _Compare>
bool duckdb_skiplistlib::skip_list::Node< T, _Compare >::index ( const T & value,
size_t & idx,
size_t level ) const

Computes index of the first occurrence of a value.

Template Parameters
TThe type of the Skip List Node values.
_CompareA comparison function for type T.
Parameters
valueThe value to find.
idxThe current index, this will be updated.
levelThe current level to search from.
Returns
true if found, false otherwise.
486722 {
486723 assert(_nodeRefs.height());
486724 assert(value == value); // value can not be NaN for example
486725 assert(level < _nodeRefs.height());
486726 // Search has overshot, try again at a lower level.
486727 //if (_value > value) {
486728 if (_compare(value, _value)) {
486729 return false;
486730 }
486731 // First check if we match but we have been approached at a high level
486732 // as there may be an earlier node of the same value but with fewer
486733 // node references. In that case this search has to fail and try at a
486734 // lower level.
486735 // If however the level is 0 and we match then set the idx to 0 to mark us.
486736 // Effectively: if (_value == value) {
486737 if (!_compare(value, _value) && !_compare(_value, value)) {
486738 if (level > 0) {
486739 return false;
486740 }
486741 idx = 0;
486742 return true;
486743 }
486744 // Now work our way down
486745 // NOTE: We initialise l as level + 1 because l-- > 0 will decrement it to
486746 // the correct initial value
486747 for (size_t l = level + 1; l-- > 0;) {
486748 assert(l < _nodeRefs.height());
486749 if (_nodeRefs[l].pNode && _nodeRefs[l].pNode->index(value, idx, l)) {
486750 idx += _nodeRefs[l].width;
486751 return true;
486752 }
486753 }
486754 return false;
Here is the call graph for this function:

◆ height()

template<typename T, typename _Compare>
size_t duckdb_skiplistlib::skip_list::Node< T, _Compare >::height ( ) const
inline

Number of linked lists that this node engages in, minimum 1.

Here is the caller graph for this function:

◆ next()

template<typename T, typename _Compare>
const Node< T, _Compare > * duckdb_skiplistlib::skip_list::Node< T, _Compare >::next ( ) const

Return the pointer to the next node at level 0.

Template Parameters
TThe type of the Skip List Node values.
_CompareA comparison function for type T.
Returns
The next node at level 0.
486765 {
486766 assert(_nodeRefs.height());
486767 return _nodeRefs[0].pNode;
Here is the call graph for this function:
Here is the caller graph for this function:

◆ width()

template<typename T, typename _Compare>
size_t duckdb_skiplistlib::skip_list::Node< T, _Compare >::width ( size_t level) const

Return the width at given level.

Template Parameters
TThe type of the Skip List Node values.
_CompareA comparison function for type T.
Parameters
levelThe requested level.
Returns
The width.
486779 {
486780 assert(level < _nodeRefs.height());
486781 return _nodeRefs[level].width;
Here is the caller graph for this function:

◆ pNode()

template<typename T, typename _Compare>
const Node< T, _Compare > * duckdb_skiplistlib::skip_list::Node< T, _Compare >::pNode ( size_t level) const

Return the node pointer at given level, only used for HeadNode integrity checks.

Template Parameters
TThe type of the Skip List Node values.
_CompareA comparison function for type T.
Parameters
levelThe requested level.
Returns
The Node.
486793 {
486794 assert(level < _nodeRefs.height());
486795 return _nodeRefs[level].pNode;
Here is the call graph for this function:
Here is the caller graph for this function:

◆ nodeRefs() [1/2]

template<typename T, typename _Compare>
SwappableNodeRefStack< T, _Compare > & duckdb_skiplistlib::skip_list::Node< T, _Compare >::nodeRefs ( )
inline

Get a reference to the node references.

Here is the caller graph for this function:

◆ nodeRefs() [2/2]

template<typename T, typename _Compare>
const SwappableNodeRefStack< T, _Compare > & duckdb_skiplistlib::skip_list::Node< T, _Compare >::nodeRefs ( ) const
inline

Get a reference to the node references.

◆ insert()

template<typename T, typename _Compare>
Node< T, _Compare > * duckdb_skiplistlib::skip_list::Node< T, _Compare >::insert ( const T & value)

Insert a new node with a value.

Template Parameters
TThe type of the Skip List Node values.
_CompareA comparison function for type T.
Parameters
valueThe value of the Node to insert.
Returns
Pointer to the new Node or nullptr on failure.
486807 {
486808 assert(_nodeRefs.height());
486809 assert(_nodeRefs.noNodePointerMatches(this));
486810 assert(! _nodeRefs.canSwap());
486811 assert(value == value); // NaN check for double
486812
486813 // Effectively: if (value < _value) {
486814 if (_compare(value, _value)) {
486815 return nullptr;
486816 }
486817 // Recursive search for where to put the node
486818 Node<T, _Compare> *pNode = nullptr;
486819 size_t level = _nodeRefs.height();
486820 // Effectively: if (value >= _value) {
486821 if (! _compare(value, _value)) {
486822 for (level = _nodeRefs.height(); level-- > 0;) {
486823 if (_nodeRefs[level].pNode) {
486824 pNode = _nodeRefs[level].pNode->insert(value);
486825 if (pNode) {
486826 break;
486827 }
486828 }
486829 }
486830 }
486831 // Effectively: if (! pNode && value >= _value) {
486832 if (! pNode && !_compare(value, _value)) {
486833 // Insert new node here
486834 pNode = _pool.Allocate(value);
486835 level = 0;
486836 }
486837 assert(pNode); // Should never get here unless a NaN has slipped through
486838 // Adjust references by marching up and recursing back.
486840 if (! thatRefs.canSwap()) {
486841 // Have an existing node or new node that is all swapped.
486842 // All I need to do is adjust my overshooting nodes and return
486843 // this for the caller to do the same.
486844 level = thatRefs.height();
486845 while (level < _nodeRefs.height()) {
486846 _nodeRefs[level].width += 1;
486847 ++level;
486848 }
486849 // The caller just has to increment its references that overshoot this
486850 assert(! _nodeRefs.canSwap());
486851 return this;
486852 }
486853 // March upwards
486854 if (level < thatRefs.swapLevel()) {
486855 assert(level == thatRefs.swapLevel() - 1);
486856 // This will happen when say a 3 high node, A, finds a 2 high
486857 // node, B, that creates a new 2+ high node. A will be at
486858 // level 1 and the new node will have swapLevel == 2 after
486859 // B has swapped.
486860 // Add the level to the accumulator at the next level
486861 thatRefs[thatRefs.swapLevel()].width += _nodeRefs[level].width;
486862 ++level;
486863 }
486864 size_t min_height = std::min(_nodeRefs.height(), thatRefs.height());
486865 while (level < min_height) {
486866 assert(thatRefs.canSwap());
486867 assert(level == thatRefs.swapLevel());
486869 assert(_nodeRefs[level].width > 0);
486870 assert(thatRefs[level].width > 0);
486871 _nodeRefs[level].width -= thatRefs[level].width - 1;
486872 assert(_nodeRefs[level].width > 0);
486873 thatRefs.swap(_nodeRefs);
486874 if (thatRefs.canSwap()) {
486875 assert(thatRefs[thatRefs.swapLevel()].width == 0);
486876 thatRefs[thatRefs.swapLevel()].width = _nodeRefs[level].width;
486877 }
486878 ++level;
486879 }
486880 // Upwards march complete, now recurse back ('left').
486881 if (! thatRefs.canSwap()) {
486882 // All done with pNode locally.
486883 assert(level == thatRefs.height());
486884 assert(thatRefs.height() <= _nodeRefs.height());
486885 assert(level == thatRefs.swapLevel());
486886 // Adjust my overshooting nodes
486887 while (level < _nodeRefs.height()) {
486888 _nodeRefs[level].width += 1;
486889 ++level;
486890 }
486891 // The caller just has to increment its references that overshoot this
486892 assert(! _nodeRefs.canSwap());
486893 pNode = this;
486894 }
486895 return pNode;
Node(const T &value, _Compare _cmp, _Pool &pool)
Definition duckdb.cpp:486656
Here is the call graph for this function:

◆ remove()

template<typename T, typename _Compare>
Node< T, _Compare > * duckdb_skiplistlib::skip_list::Node< T, _Compare >::remove ( size_t call_level,
const T & value )

Remove a Node with the given value to be removed. The return value must be deleted, the other Nodes have been adjusted as required.

Template Parameters
TThe type of the Skip List Node values.
_CompareA comparison function for type T.
Parameters
call_levelLevel the caller Node is at.
valueValue of the detached Node to remove.
Returns
A pointer to the Node to be free'd or nullptr on failure.
486950 {
486951 assert(_nodeRefs.height());
486952 assert(_nodeRefs.noNodePointerMatches(this));
486953
486954 Node<T, _Compare> *pNode = nullptr;
486955 // Effectively: if (value >= _value) {
486956 if (!_compare(value, _value)) {
486957 for (size_t level = call_level + 1; level-- > 0;) {
486958 if (_nodeRefs[level].pNode) {
486959 // Make progress to the right
486960 pNode = _nodeRefs[level].pNode->remove(level, value);
486961 if (pNode) {
486962 return _adjRemoveRefs(level, pNode);
486963 }
486964 }
486965 // Make progress down
486966 }
486967 }
486968 if (! pNode) { // Base case
486969 // We only admit to being the node to remove if the caller is
486970 // approaching us from level 0. It is entirely likely that
486971 // the same (or an other) caller can see us at a higher level
486972 // but the recursion stack will not have been set up in the correct
486973 // step wise fashion so that the lower level references will
486974 // not be swapped.
486975 // Effectively: if (call_level == 0 && value == _value) {
486976 if (call_level == 0 && !_compare(value, _value) && !_compare(_value, value)) {
486977 _nodeRefs.resetSwapLevel();
486978 return this;
486979 }
486980 }
486981 assert(pNode == nullptr);
486982 return nullptr;
Node< T, _Compare > * _adjRemoveRefs(size_t level, Node< T, _Compare > *pNode)
Definition duckdb.cpp:486907
Here is the call graph for this function:

◆ size_of()

template<typename T, typename _Compare>
size_t duckdb_skiplistlib::skip_list::Node< T, _Compare >::size_of ( ) const

Returns an estimate of the memory usage of an instance.

Template Parameters
TThe type of the Skip List Node values.
_CompareA comparison function for type T.
Returns
The memory estimate of this Node.
487069 {
487070 // sizeof(*this) includes the size of _nodeRefs but _nodeRefs.size_of()
487071 // includes sizeof(_nodeRefs) so we need to subtract to avoid double counting
487072 return sizeof(*this) + _nodeRefs.size_of() - sizeof(_nodeRefs);
Here is the caller graph for this function:

◆ lacksIntegrity()

template<typename T, typename _Compare>
IntegrityCheck duckdb_skiplistlib::skip_list::Node< T, _Compare >::lacksIntegrity ( size_t headnode_height) const

This checks the internal consistency of a Node. It returns 0 if successful, non-zero on error. The tests are:

  • Height must be >= 1
  • Height must not exceed HeadNode height.
  • NULL pointer must not have a non-NULL above them.
  • Node pointers must not be self-referential.
Template Parameters
TThe type of the Skip List Node values.
_CompareA comparison function for type T.
Parameters
headnode_heightHeight of HeadNode.
Returns
An IntegrityCheck enum.
487009 {
487010 IntegrityCheck result = _nodeRefs.lacksIntegrity();
487011 if (result) {
487012 return result;
487013 }
487014 if (_nodeRefs.height() == 0) {
487015 return NODE_HEIGHT_ZERO;
487016 }
487017 if (_nodeRefs.height() > headnode_height) {
487019 }
487020 // Test: All nodes above a nullprt must be nullptr
487021 size_t level = 0;
487022 while (level < _nodeRefs.height()) {
487023 if (! _nodeRefs[level].pNode) {
487024 break;
487025 }
487026 ++level;
487027 }
487028 while (level < _nodeRefs.height()) {
487029 if (_nodeRefs[level].pNode) {
487031 }
487032 ++level;
487033 }
487034 // No reference should be to self.
487035 if (! _nodeRefs.noNodePointerMatches(this)) {
487036 return NODE_SELF_REFERENCE;
487037 }
487038 return INTEGRITY_SUCCESS;
IntegrityCheck lacksIntegrity(size_t headnode_height) const
Definition duckdb.cpp:487008
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lacksIntegrityRefsInSet()

template<typename T, typename _Compare>
IntegrityCheck duckdb_skiplistlib::skip_list::Node< T, _Compare >::lacksIntegrityRefsInSet ( const std::set< const Node< T, _Compare > * > & nodeSet) const

Checks that this Node is in the set held by the HeadNode.

Template Parameters
TThe type of the Skip List Node values.
_CompareA comparison function for type T.
Parameters
nodeSetSet of Nodes held by the HeadNode.
Returns
An IntegrityCheck enum.
487050 {
487051 size_t level = 0;
487052 while (level < _nodeRefs.height()) {
487053 if (nodeSet.count(_nodeRefs[level].pNode) == 0) {
487055 }
487056 ++level;
487057 }
487058 return INTEGRITY_SUCCESS;
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _adjRemoveRefs()

template<typename T, typename _Compare>
Node< T, _Compare > * duckdb_skiplistlib::skip_list::Node< T, _Compare >::_adjRemoveRefs ( size_t level,
Node< T, _Compare > * pNode )
protected

Adjust the Node references.

Template Parameters
TThe type of the Skip List Node values.
_CompareA comparison function for type T.
Parameters
levelThe level of the caller's node.
pNodeThe Node to swap references with.
Returns
The Node with swapped references.
486908 {
486909 assert(pNode);
486911
486912 assert(pNode != this);
486913 if (level < thatRefs.swapLevel()) {
486914 assert(level == thatRefs.swapLevel() - 1);
486915 ++level;
486916 }
486917 if (thatRefs.canSwap()) {
486918 assert(level == thatRefs.swapLevel());
486919 while (level < _nodeRefs.height() && thatRefs.canSwap()) {
486920 assert(level == thatRefs.swapLevel());
486921 // Compute the new width for the new node
486922 thatRefs[level].width += _nodeRefs[level].width - 1;
486923 thatRefs.swap(_nodeRefs);
486924 ++level;
486925 }
486926 assert(thatRefs.canSwap() || thatRefs.allNodePointerMatch(pNode));
486927 }
486928 // Decrement my widths as my refs are over the top of the missing pNode.
486929 while (level < _nodeRefs.height()) {
486930 _nodeRefs[level].width -= 1;
486931 ++level;
486932 thatRefs.incSwapLevel();
486933 }
486934 assert(! _nodeRefs.canSwap());
486935 return pNode;
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Initialize()

template<typename T, typename _Compare>
void duckdb_skiplistlib::skip_list::Node< T, _Compare >::Initialize ( const T & value)
inlineprotected
486627 {
486628 _value = value;
486629 _nodeRefs.clear();
486630 do {
486631 _nodeRefs.push_back(this, _nodeRefs.height() ? 0 : 1);
486632 } while (_pool.prng() < _pool.prng.max() / 2);

The documentation for this class was generated from the following file: