Advanced Chunk Processing Library 0.2.0
A comprehensive C++ library for advanced data chunking strategies and processing operations
Loading...
Searching...
No Matches
advanced_structures::ChunkTreap< T > Class Template Reference

A treap implementation for efficient chunk searching and manipulation. More...

#include <advanced_structures.hpp>

+ Collaboration diagram for advanced_structures::ChunkTreap< T >:

Classes

struct  Node
 

Public Member Functions

 ChunkTreap ()
 
void insert (T value)
 
bool search (T value) const
 

Private Member Functions

std::shared_ptr< Nodeinsert (std::shared_ptr< Node > node, T value, int priority)
 
std::shared_ptr< Noderotate_left (std::shared_ptr< Node > node)
 
std::shared_ptr< Noderotate_right (std::shared_ptr< Node > node)
 
bool search (const std::shared_ptr< Node > &node, T value) const
 

Private Attributes

std::mt19937 gen
 
std::shared_ptr< Noderoot
 

Detailed Description

template<typename T>
class advanced_structures::ChunkTreap< T >

A treap implementation for efficient chunk searching and manipulation.

Template Parameters
TThe type of elements stored in the treap

Definition at line 426 of file advanced_structures.hpp.

Constructor & Destructor Documentation

◆ ChunkTreap()

template<typename T >
advanced_structures::ChunkTreap< T >::ChunkTreap ( )
inline

Definition at line 488 of file advanced_structures.hpp.

488: root(nullptr), gen(std::random_device{}()) {}

Member Function Documentation

◆ insert() [1/2]

template<typename T >
std::shared_ptr< Node > advanced_structures::ChunkTreap< T >::insert ( std::shared_ptr< Node node,
value,
int  priority 
)
inlineprivate

Definition at line 454 of file advanced_structures.hpp.

454 {
455 if (!node) {
456 return std::make_shared<Node>(value, priority);
457 }
458
459 if (value < node->value) {
460 node->left = insert(node->left, value, priority);
461 if (node->left->priority > node->priority) {
462 node = rotate_right(node);
463 }
464 } else {
465 node->right = insert(node->right, value, priority);
466 if (node->right->priority > node->priority) {
467 node = rotate_left(node);
468 }
469 }
470 return node;
471 }
std::shared_ptr< Node > insert(std::shared_ptr< Node > node, T value, int priority)
std::shared_ptr< Node > rotate_right(std::shared_ptr< Node > node)
std::shared_ptr< Node > rotate_left(std::shared_ptr< Node > node)

References advanced_structures::ChunkTreap< T >::insert(), advanced_structures::ChunkTreap< T >::rotate_left(), and advanced_structures::ChunkTreap< T >::rotate_right().

Referenced by advanced_structures::ChunkTreap< T >::insert(), advanced_structures::ChunkTreap< T >::insert(), and TEST().

◆ insert() [2/2]

template<typename T >
void advanced_structures::ChunkTreap< T >::insert ( value)
inline

Definition at line 490 of file advanced_structures.hpp.

490 {
491 int priority = std::uniform_int_distribution<>(1, 100)(gen);
492 root = insert(root, value, priority);
493 }

References advanced_structures::ChunkTreap< T >::gen, advanced_structures::ChunkTreap< T >::insert(), and advanced_structures::ChunkTreap< T >::root.

◆ rotate_left()

template<typename T >
std::shared_ptr< Node > advanced_structures::ChunkTreap< T >::rotate_left ( std::shared_ptr< Node node)
inlineprivate

Definition at line 447 of file advanced_structures.hpp.

447 {
448 auto new_root = node->right;
449 node->right = new_root->left;
450 new_root->left = node;
451 return new_root;
452 }

Referenced by advanced_structures::ChunkTreap< T >::insert().

◆ rotate_right()

template<typename T >
std::shared_ptr< Node > advanced_structures::ChunkTreap< T >::rotate_right ( std::shared_ptr< Node node)
inlineprivate

Definition at line 440 of file advanced_structures.hpp.

440 {
441 auto new_root = node->left;
442 node->left = new_root->right;
443 new_root->right = node;
444 return new_root;
445 }

Referenced by advanced_structures::ChunkTreap< T >::insert().

◆ search() [1/2]

template<typename T >
bool advanced_structures::ChunkTreap< T >::search ( const std::shared_ptr< Node > &  node,
value 
) const
inlineprivate

Definition at line 473 of file advanced_structures.hpp.

473 {
474 if (!node) {
475 return false;
476 }
477 if (node->value == value) {
478 return true;
479 }
480 if (value < node->value) {
481 return search(node->left, value);
482 } else {
483 return search(node->right, value);
484 }
485 }
bool search(const std::shared_ptr< Node > &node, T value) const

References advanced_structures::ChunkTreap< T >::search().

Referenced by advanced_structures::ChunkTreap< T >::search(), advanced_structures::ChunkTreap< T >::search(), and TEST().

◆ search() [2/2]

template<typename T >
bool advanced_structures::ChunkTreap< T >::search ( value) const
inline

Definition at line 495 of file advanced_structures.hpp.

495 {
496 return search(root, value);
497 }

References advanced_structures::ChunkTreap< T >::root, and advanced_structures::ChunkTreap< T >::search().

Member Data Documentation

◆ gen

template<typename T >
std::mt19937 advanced_structures::ChunkTreap< T >::gen
private

◆ root

template<typename T >
std::shared_ptr<Node> advanced_structures::ChunkTreap< T >::root
private

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