ORIGINAL
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
original::skipList< K_TYPE, V_TYPE, ALLOC, Compare > Class Template Reference

Skip List container implementation. More...

#include <skipList.h>

Collaboration diagram for original::skipList< K_TYPE, V_TYPE, ALLOC, Compare >:
Collaboration graph

Classes

class  Iterator
 Forward iterator for skipList. More...
 
class  skipListNode
 Internal node class for Skip List. More...
 

Public Types

using rebind_alloc_node = ALLOC::template rebind_alloc< skipListNode >
 Rebound allocator for nodes.
 
using rebind_alloc_pointer = ALLOC::template rebind_alloc< skipListNode * >
 Rebound allocator for pointers.
 

Public Member Functions

skipListNodecreateNode (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 () const
 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.
 
skipListNodelistCopy () const
 Creates a deep copy of the list.
 
skipListNodefindLastNode () const
 Finds last node in list.
 
 skipList (Compare compare=Compare{})
 Constructs skipList with given comparison function.
 
skipListNodefind (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.
 
virtual ~skipList ()
 Destructor.
 

Static Public Member Functions

static bool equal (const K_TYPE &key, skipListNode *next)
 Checks if key matches node's key.
 

Public Attributes

u_integer size_
 Number of elements.
 
skipListNodehead_
 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 dis_ {0.0, 1.0}
 Uniform distribution for level generation.
 
friend Iterator
 

Detailed Description

template<typename K_TYPE, typename V_TYPE, typename ALLOC = allocator<K_TYPE>, typename Compare = increaseComparator<K_TYPE>>
class original::skipList< K_TYPE, V_TYPE, ALLOC, Compare >

Skip List container implementation.

Template Parameters
K_TYPEKey type (must be comparable)
V_TYPEValue type
ALLOCAllocator type (default: allocator<K_TYPE>)
CompareComparison function type (default: increaseComparator<K_TYPE>)

This class provides a probabilistic alternative to balanced trees with:

Constructor & Destructor Documentation

◆ skipList()

template<typename K_TYPE , typename V_TYPE , typename ALLOC , typename Compare >
original::skipList< K_TYPE, V_TYPE, ALLOC, Compare >::skipList ( Compare  compare = Compare{})
explicit

Constructs skipList with given comparison function.

Parameters
compareComparison function to use

◆ ~skipList()

template<typename K_TYPE , typename V_TYPE , typename ALLOC , typename Compare >
original::skipList< K_TYPE, V_TYPE, ALLOC, Compare >::~skipList ( )
virtual

Destructor.

Cleans up all list nodes and allocated memory

Member Function Documentation

◆ createNode()

template<typename K_TYPE , typename V_TYPE , typename ALLOC , typename Compare >
original::skipList< K_TYPE, V_TYPE, ALLOC, Compare >::skipListNode * original::skipList< K_TYPE, V_TYPE, ALLOC, Compare >::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.

Parameters
keyKey for new node
valueValue for new node
levelsNumber of levels for new node
nextInitializer list of next pointers
Returns
Pointer to newly created node

Uses allocator to construct node in place

◆ destroyNode()

template<typename K_TYPE , typename V_TYPE , typename ALLOC , typename Compare >
void original::skipList< K_TYPE, V_TYPE, ALLOC, Compare >::destroyNode ( skipListNode node) const

Destroys a node and deallocates memory.

Parameters
nodeNode to destroy

Uses allocator to destroy and deallocate node

◆ equal()

template<typename K_TYPE , typename V_TYPE , typename ALLOC , typename Compare >
bool original::skipList< K_TYPE, V_TYPE, ALLOC, Compare >::equal ( const K_TYPE key,
skipListNode next 
)
static

Checks if key matches node's key.

Parameters
keyKey to compare
nextNode to compare
Returns
true if key matches node's key

◆ erase()

template<typename K_TYPE , typename V_TYPE , typename ALLOC , typename Compare >
bool original::skipList< K_TYPE, V_TYPE, ALLOC, Compare >::erase ( const K_TYPE key)

Erases node with given key.

Parameters
keyKey to erase
Returns
true if key was found and erased

Automatically adjusts list levels if needed

◆ expandCurLevels()

template<typename K_TYPE , typename V_TYPE , typename ALLOC , typename Compare >
void original::skipList< K_TYPE, V_TYPE, ALLOC, Compare >::expandCurLevels ( u_integer  new_levels)

Expands list to more levels.

Parameters
new_levelsNew total number of levels

◆ find()

template<typename K_TYPE , typename V_TYPE , typename ALLOC , typename Compare >
original::skipList< K_TYPE, V_TYPE, ALLOC, Compare >::skipListNode * original::skipList< K_TYPE, V_TYPE, ALLOC, Compare >::find ( const K_TYPE key) const

Finds node with given key.

Parameters
keyKey to search for
Returns
Pointer to found node, or nullptr if not found

Uses multi-level search for efficiency

◆ findLastNode()

template<typename K_TYPE , typename V_TYPE , typename ALLOC , typename Compare >
original::skipList< K_TYPE, V_TYPE, ALLOC, Compare >::skipListNode * original::skipList< K_TYPE, V_TYPE, ALLOC, Compare >::findLastNode ( ) const

Finds last node in list.

Returns
Pointer to last node

◆ getCurLevels()

template<typename K_TYPE , typename V_TYPE , typename ALLOC , typename Compare >
original::u_integer original::skipList< K_TYPE, V_TYPE, ALLOC, Compare >::getCurLevels ( ) const

Gets current number of levels in list.

Returns
Current maximum number of levels

◆ getRandomLevels()

template<typename K_TYPE , typename V_TYPE , typename ALLOC , typename Compare >
original::u_integer original::skipList< K_TYPE, V_TYPE, ALLOC, Compare >::getRandomLevels ( ) const

Generates random number of levels for new node.

Returns
Random number of levels (geometric distribution)

◆ highPriority() [1/2]

template<typename K_TYPE , typename V_TYPE , typename ALLOC , typename Compare >
bool original::skipList< K_TYPE, V_TYPE, ALLOC, Compare >::highPriority ( const K_TYPE key,
skipListNode next 
) const

Compares priority between a key and a node.

Parameters
keyKey to compare
nextNode to compare
Returns
true if key has higher priority than node's key

Uses the list's comparison function

◆ highPriority() [2/2]

template<typename K_TYPE , typename V_TYPE , typename ALLOC , typename Compare >
bool original::skipList< K_TYPE, V_TYPE, ALLOC, Compare >::highPriority ( skipListNode cur,
skipListNode next 
) const

Compares priority between two nodes.

Parameters
curFirst node to compare
nextSecond node to compare
Returns
true if cur has higher priority than next

Uses the list's comparison function

◆ insert()

template<typename K_TYPE , typename V_TYPE , typename ALLOC , typename Compare >
bool original::skipList< K_TYPE, V_TYPE, ALLOC, Compare >::insert ( const K_TYPE key,
const V_TYPE value 
)

Inserts new key-value pair.

Parameters
keyKey to insert
valueValue to insert
Returns
true if inserted, false if key already existed

Automatically adjusts node levels probabilistically

◆ listCopy()

template<typename K_TYPE , typename V_TYPE , typename ALLOC , typename Compare >
original::skipList< K_TYPE, V_TYPE, ALLOC, Compare >::skipListNode * original::skipList< K_TYPE, V_TYPE, ALLOC, Compare >::listCopy ( ) const

Creates a deep copy of the list.

Returns
Pointer to head of copied list

◆ listDestroy()

template<typename K_TYPE , typename V_TYPE , typename ALLOC , typename Compare >
void original::skipList< K_TYPE, V_TYPE, ALLOC, Compare >::listDestroy ( )
noexcept

Destroys entire list and deallocates all nodes.

Uses sequential traversal to destroy all nodes

◆ modify()

template<typename K_TYPE , typename V_TYPE , typename ALLOC , typename Compare >
bool original::skipList< K_TYPE, V_TYPE, ALLOC, Compare >::modify ( const K_TYPE key,
const V_TYPE value 
)

Modifies value for existing key.

Parameters
keyKey to modify
valueNew value to set
Returns
true if key was found and modified

◆ shrinkCurLevels()

template<typename K_TYPE , typename V_TYPE , typename ALLOC , typename Compare >
void original::skipList< K_TYPE, V_TYPE, ALLOC, Compare >::shrinkCurLevels ( u_integer  new_levels)

Shrinks list to fewer levels.

Parameters
new_levelsNew total number of levels

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