Commit e5973a9b authored by Chris Müller's avatar Chris Müller

lib: move red_black_tree implementation into its own module.

parent b1e27118
This diff is collapsed.
* Copyright (c) 2012 Christoph Mueller <>
* Crystal is free software: you can redistribute it and/or modify
* it under the terms of the Lesser GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Crystal is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* Lesser GNU General Public License for more details.
* You should have received a copy of the Lesser GNU General Public License
* along with this program. If not, see <>.
#include "structures.h"
enum RBNodeColor { RED, BLACK };
struct RBNode {
const_pointer key;
pointer data;
enum RBNodeColor color;
struct RBNode* parent;
struct RBNode* left;
struct RBNode* right;
struct RBTree {
struct RBNode* root;
cry_ordering_funptr compare;
size_t nodes;
#define RB_PARENT(node) node->parent
#define RB_GRAND_PARENT(node) node->parent->parent
struct RBTree* rb_tree_new(cry_ordering_funptr compare);
void rb_tree_clear(struct RBTree* tree, cry_free_funptr free_key, cry_free_funptr free_data);
struct RBNode* rb_tree_lookup(struct RBTree* tree, const_pointer key);
struct RBNode* rb_tree_insert(struct RBTree* tree, const_pointer key, pointer value);
struct RBNode* rb_tree_remove(struct RBTree* tree, const_pointer key);
struct RBNode* rb_node_new(enum RBNodeColor color, struct RBNode* parent, const_pointer key, pointer data);
void rb_node_free(struct RBNode* node, cry_free_funptr free_key, cry_free_funptr free_data);
......@@ -27,8 +27,6 @@
typedef int (*cry_ordering_funptr)(const_pointer a, const_pointer b);
typedef void (*cry_free_funptr)(pointer data);
typedef int (*cry_predicate_funptr)(pointer element, pointer context);
int cry_int_compare(const_pointer a, const_pointer b);
int cry_double_compare(const_pointer a, const_pointer b);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment