ORIGINAL
|
Skip List container implementation. More...
#include <skipList.h>
Classes | |
class | Iterator |
Forward iterator for skipList. More... | |
class | skipListNode |
Internal node class for Skip List. More... | |
Protected Types | |
using | rebind_alloc_node = typename ALLOC::template rebind_alloc<skipListNode> |
Rebound allocator for nodes. | |
using | rebind_alloc_pointer = typename ALLOC::template rebind_alloc<skipListNode*> |
Rebound allocator for pointers. | |
Protected Member Functions | |
skipListNode * | createNode (const K_TYPE &key=K_TYPE{}, const V_TYPE &value=V_TYPE{}, u_integer levels=1, std::initializer_list< skipListNode * > next={}) const |
Creates a new node with given parameters. | |
void | destroyNode (skipListNode *node) const |
Destroys a node and deallocates memory. | |
bool | highPriority (skipListNode *cur, skipListNode *next) const |
Compares priority between two nodes. | |
bool | highPriority (const K_TYPE &key, skipListNode *next) const |
Compares priority between a key and a node. | |
u_integer | getRandomLevels () |
Generates random number of levels for new node. | |
u_integer | getCurLevels () const |
Gets current number of levels in list. | |
void | expandCurLevels (u_integer new_levels) |
Expands list to more levels. | |
void | shrinkCurLevels (u_integer new_levels) |
Shrinks list to fewer levels. | |
skipListNode * | listCopy () const |
Creates a deep copy of the list. | |
skipListNode * | findLastNode () const |
Finds last node in list. | |
skipList (Compare compare=Compare{}) | |
Constructs skipList with given comparison function. | |
skipListNode * | find (const K_TYPE &key) const |
Finds node with given key. | |
bool | modify (const K_TYPE &key, const V_TYPE &value) |
Modifies value for existing key. | |
bool | insert (const K_TYPE &key, const V_TYPE &value) |
Inserts new key-value pair. | |
bool | erase (const K_TYPE &key) |
Erases node with given key. | |
void | listDestroy () noexcept |
Destroys entire list and deallocates all nodes. | |
~skipList () | |
Destructor. | |
Static Protected Member Functions | |
static bool | equal (const K_TYPE &key, skipListNode *next) |
Checks if key matches node's key. | |
Protected Attributes | |
u_integer | size_ |
Number of elements. | |
skipListNode * | head_ |
Head node pointer. | |
Compare | compare_ |
Comparison function. | |
rebind_alloc_node | rebind_alloc {} |
Node allocator. | |
std::mt19937 | gen_ {std::random_device{}()} |
Random number generator. | |
std::uniform_real_distribution< floating > | dis_ {0.0, 1.0} |
Uniform distribution for level generation. | |
friend | Iterator |
Skip List container implementation.
K_TYPE | Key type (must be comparable) |
V_TYPE | Value type |
ALLOC | Allocator type (default: allocator<K_TYPE>) |
Compare | Comparison function type (default: increaseComparator<K_TYPE>) |
This class provides a probabilistic alternative to balanced trees with:
|
explicitprotected |
Constructs skipList with given comparison function.
compare | Comparison function to use |
|
protected |
Destructor.
Cleans up all list nodes and allocated memory
|
protected |
Creates a new node with given parameters.
key | Key for new node |
value | Value for new node |
levels | Number of levels for new node |
next | Initializer list of next pointers |
Uses allocator to construct node in place
|
protected |
Destroys a node and deallocates memory.
node | Node to destroy |
Uses allocator to destroy and deallocate node
|
staticprotected |
Checks if key matches node's key.
key | Key to compare |
next | Node to compare |
|
protected |
Erases node with given key.
key | Key to erase |
Automatically adjusts list levels if needed
|
protected |
Expands list to more levels.
new_levels | New total number of levels |
|
protected |
Finds node with given key.
key | Key to search for |
Uses multi-level search for efficiency
|
protected |
Finds last node in list.
|
protected |
Gets current number of levels in list.
|
protected |
Generates random number of levels for new node.
|
protected |
Compares priority between a key and a node.
key | Key to compare |
next | Node to compare |
Uses the list's comparison function
|
protected |
Compares priority between two nodes.
cur | First node to compare |
next | Second node to compare |
Uses the list's comparison function
|
protected |
Inserts new key-value pair.
key | Key to insert |
value | Value to insert |
Automatically adjusts node levels probabilistically
|
protected |
Creates a deep copy of the list.
|
protectednoexcept |
Destroys entire list and deallocates all nodes.
Uses sequential traversal to destroy all nodes
|
protected |
Modifies value for existing key.
key | Key to modify |
value | New value to set |
|
protected |
Shrinks list to fewer levels.
new_levels | New total number of levels |