57 lines
1.2 KiB
C
57 lines
1.2 KiB
C
#pragma once
|
|
|
|
// ::DataStructures::Types::Header::
|
|
|
|
typedef enum RBNodeColor_e
|
|
{
|
|
RB_RED,
|
|
RB_BLACK,
|
|
} RBNodeColor;
|
|
|
|
typedef enum RBNodeDir_e
|
|
{
|
|
RB_LEFT,
|
|
RB_RIGHT,
|
|
} RBNodeDir;
|
|
|
|
typedef struct RBNode RBNode;
|
|
|
|
typedef struct RBNode
|
|
{
|
|
RBNode *parent;
|
|
union
|
|
{
|
|
struct
|
|
{
|
|
RBNode *left;
|
|
RBNode *right;
|
|
};
|
|
RBNode *child[2];
|
|
};
|
|
i32 value;
|
|
rawptr data;
|
|
RBNodeColor color;
|
|
} RBNode;
|
|
|
|
typedef struct RBTree
|
|
{
|
|
RBNode *root;
|
|
RBNode *nil;
|
|
} RBTree;
|
|
|
|
// ::DataStructures::Macros::Header::
|
|
|
|
#define NodeDir(node) (node == node->parent->left ? RB_LEFT : RB_RIGHT)
|
|
|
|
// ::DataStructures::RedBlackTree::Functions::Header::
|
|
|
|
static void CreateRBTree(RBTree *tree);
|
|
static void RBTreeInsert(RBTree *tree, RBNode *node);
|
|
static b32 RBTreeSearch(RBTree *tree, i32 value, RBNode **node);
|
|
static void RBTreeDelete(RBTree *tree, i32 value);
|
|
static void RBTreeLeftRotate(RBTree *tree, RBNode *node);
|
|
static void RBTreeRightRotate(RBTree *tree, RBNode *node);
|
|
static void RBTreeRotate(RBTree *tree, RBNode *node, RBNodeDir dir);
|
|
static void RBTreeCorrect(RBTree *tree, RBNode *node);
|
|
static inline void RBTreeTransplant(RBTree *tree, RBNode *node, RBNode *placed_node);
|