Zip and Skip Tries
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Related Symbols | List of all members
GeometricRank Struct Reference

Represents a rank used in zip-zip trees, typically generated randomly for balancing. More...

#include <ZipTrie.hpp>

Public Member Functions

auto operator<=> (const GeometricRank &) const =default
 Default comparison operator.
 

Static Public Member Functions

static GeometricRank get_random ()
 Generates a random rank using static random number generators.
 

Public Attributes

uint8_t geometric_rank
 Rank component following a geometric distribution (primary rank). Higher values are less likely.
 
uint8_t uniform_rank
 Rank component following a uniform distribution (used for tie-breaking).
 

Related Symbols

(Note that these are not member symbols.)

std::ostream & operator<< (std::ostream &os, const GeometricRank &rank)
 Overloaded stream insertion operator (<<) for GeometricRank.
 

Detailed Description

Represents a rank used in zip-zip trees, typically generated randomly for balancing.

Combines a geometric and a uniform random component for tie-breaking. The geometric component helps achieve logarithmic expected depth in the zip tree/trie structure, while the uniform component ensures rank uniqueness with high probability, preventing arbitrary choices during 'zip' operations when geometric ranks are equal. This structure is crucial for maintaining the max-heap property based on ranks.

Definition at line 72 of file ZipTrie.hpp.

Member Function Documentation

◆ get_random()

GeometricRank GeometricRank::get_random ( )
inlinestatic

Generates a random rank using static random number generators.

The geometric component helps achieve logarithmic expected depth, while the uniform component ensures uniqueness with high probability.

Returns
GeometricRank A randomly generated rank.
Warning
Uses static generators internally. This means successive calls produce different random numbers, but it is not thread-safe if called from multiple threads concurrently without external locking.

Definition at line 1083 of file ZipTrie.hpp.

1084{
1085 // Static generators ensure the sequence is consistent across calls within a single thread,
1086 // but also mean it's not thread-safe without external locking.
1087 static std::random_device rd; // Obtain a random seed from the hardware device
1088 static std::default_random_engine generator(rd()); // Seed the default random engine
1089 // static std::default_random_engine generator(1); // Use for deterministic testing (fixed seed)
1090 static std::geometric_distribution<uint8_t> g_dist(0.5); // p=0.5: ~50% chance of 0, ~25% of 1, etc.
1091 static std::uniform_int_distribution<uint8_t> u_dist(0, std::numeric_limits<uint8_t>::max()); // Uniform distribution over all possible uint8_t values
1092
1093 // Generate and return a rank with both components
1094 return { g_dist(generator), u_dist(generator) };
1095}
T * alloc_to_device(size_t size)
Allocates memory on the CUDA device.

◆ operator<=>()

auto GeometricRank::operator<=> ( const GeometricRank ) const
default

Default comparison operator.

Compares geometric_rank first, then uniform_rank for tie-breaking.

Note
Higher ranks are considered "greater" in the context of the max-heap property used in zipping.

Friends And Related Symbol Documentation

◆ operator<<()

std::ostream & operator<< ( std::ostream &  os,
const GeometricRank rank 
)
related

Overloaded stream insertion operator (<<) for GeometricRank.

Allows printing GeometricRank objects directly to output streams (e.g., std::cout << rank;). Formats the output as "(geometric, uniform)".

Parameters
osThe output stream (e.g., std::cout, std::ofstream).
rankThe GeometricRank object to print.
Returns
std::ostream& Reference to the output stream after printing.

Definition at line 1107 of file ZipTrie.hpp.

1108{
1109 // Cast uint8_t to unsigned for correct stream output as numbers.
1110 return os << "(" << static_cast<unsigned>(rank.geometric_rank) << ", "
1111 << static_cast<unsigned>(rank.uniform_rank) << ")";
1112}
uint8_t geometric_rank
Rank component following a geometric distribution (primary rank). Higher values are less likely.
Definition ZipTrie.hpp:75
uint8_t uniform_rank
Rank component following a uniform distribution (used for tie-breaking).
Definition ZipTrie.hpp:77

Member Data Documentation

◆ geometric_rank

uint8_t GeometricRank::geometric_rank

Rank component following a geometric distribution (primary rank). Higher values are less likely.

Definition at line 75 of file ZipTrie.hpp.

◆ uniform_rank

uint8_t GeometricRank::uniform_rank

Rank component following a uniform distribution (used for tie-breaking).

Definition at line 77 of file ZipTrie.hpp.


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