Gator Library
An implementation of the Red-Black Tree and Priority queue data structure in C++.
|
Header file for the RBTree class and RbtNode class. More...
#include <redblack_tree.hpp>
Public Member Functions | |
RBTree () | |
Constructs a new RBTree object. | |
int | ColorFlipCount () |
Returns the number of color flips performed during tree operations. | |
rbtnode * | begin () |
Returns a pointer to the first node in the red-black tree. | |
rbtnode * | end () |
Returns a pointer to the end of the red-black tree. | |
void | add (book book_info) |
Adds a new book to the red-black tree. | |
void | remove (int key) |
Removes a book from the red-black tree based on the given key. | |
rbtnode * | find (int key) const |
Finds a book in the red-black tree based on the given key. | |
std::vector< int > | findclosest (int targetId) const |
Finds the closest book IDs to the given target ID in the red-black tree. | |
rbtnode * | operator[] (int key) const |
Overloads the subscript operator to find a book in the red-black tree based on the given key. | |
bool | empty () const |
Checks if the red-black tree is empty. | |
Private Member Functions | |
void | rotate_left (rbtnode *&, rbtnode *&) |
void | rotate_right (rbtnode *&, rbtnode *&) |
void | fix_colorviolation (rbtnode *&, rbtnode *&) |
rbtnode * | insert_node (rbtnode *root_node, rbtnode *node) |
void | remove (rbtnode *node) |
rbtnode * | BSTreplace (rbtnode *x) |
rbtnode * | successor (rbtnode *x) |
void | fix_double_black (rbtnode *node) |
Private Attributes | |
rbtnode * | root |
int | color_flip_count |
Header file for the RBTree class and RbtNode class.
Represents a red-black tree data structure.
This file defines the RBTree class and RbtNode class, which implement a red-black tree data structure. The RBTree class provides methods for adding, removing, and finding nodes in the red-black tree. The RbtNode class represents a node in the red-black tree and stores a key-value pair.
The RBTree class represents a red-black tree data structure. It provides methods for adding, removing, and finding nodes in the red-black tree.
RBTree::RBTree | ( | ) |
Constructs a new RBTree object.
void RBTree::add | ( | book | book_info | ) |
Adds a new book to the red-black tree.
book_info | The book to add. |
rbtnode * RBTree::begin | ( | ) |
Returns a pointer to the first node in the red-black tree.
Finds the node that can replace the given node in the red-black tree.
int RBTree::ColorFlipCount | ( | ) |
Returns the number of color flips performed during tree operations.
bool RBTree::empty | ( | ) | const |
Checks if the red-black tree is empty.
rbtnode * RBTree::end | ( | ) |
Returns a pointer to the end of the red-black tree.
rbtnode * RBTree::find | ( | int | key | ) | const |
Finds a book in the red-black tree based on the given key.
key | The key of the book to find. |
std::vector< int > RBTree::findclosest | ( | int | targetId | ) | const |
Finds the closest book IDs to the given target ID in the red-black tree.
targetId | The target book ID. |
Fixes the color violation after inserting a node.
|
private |
Fixes the double black violation after removing a node.
Inserts a node into the red-black tree.
rbtnode * RBTree::operator[] | ( | int | key | ) | const |
Overloads the subscript operator to find a book in the red-black tree based on the given key.
key | The key of the book to find. |
void RBTree::remove | ( | int | key | ) |
Removes a book from the red-black tree based on the given key.
key | The key of the book to remove. |
|
private |
Removes a node from the red-black tree.
Performs a left rotation on the given nodes.
Performs a right rotation on the given nodes.
Finds the successor of the given node in the red-black tree.
|
private |
The number of color flips performed during tree operations.
|
private |
Pointer to the root node of the red-black tree.