Skip to content

Commit

Permalink
rbtree: Define API
Browse files Browse the repository at this point in the history
  • Loading branch information
boki1 committed Aug 16, 2022
1 parent df989dc commit 0c0c404
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
26 changes: 25 additions & 1 deletion include/equilibrium/rbtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,43 @@ struct rbtree_node {
enum rbtree_color _color;
struct rbtree_node *_left;
struct rbtree_node *_right;
struct rbtree_node *_parent;
void *_data_ptr;
};

typedef int (*rbtree_node_compare)(struct rbtree_node *, struct rbtree_node *);

struct rbtree {
struct rbtree_node *_root;
struct rbtree_node *_smallest;
struct rbtree_node *_biggest;
size_t _size;
size_t _depth;
};

struct rbtree_iterator {
struct rbtree_node *_ptr;
struct rbtree *_tree;
};

// Tree operations
int rbtree_init(struct rbtree *);
int rbtree_destroy(struct rbtree *);
int rbtree_copy(struct rbtree *);

// Mutable data operations
int rbtree_insert(struct rbtree *);
int rbtree_remove(struct rbtree *);
int rbtree_find(struct rbtree *);

// Immutable data operations
int rbtree_find(struct rbtree *, rbtree_node_compare cb);
struct rbtree_iterator rbtree_find_it(struct rbtree *, rbtree_node_compare cb);
struct rbtree_iterator rbtree_begin(struct rbtree *);
struct rbtree_iterator rbtree_end(struct rbtree *);
int rbtree_next(struct rbtree_iterator *);
int rbtree_prev(struct rbtree_iterator *);

#define rbtree_for_each_node(tree, it) \
for (struct rbtree_iterator it = rbtree_begin(&(tree)), \
end = rbtree_end(&(tree)); \
it._ptr != end._ptr; rbtree_next(it._ptr))
46 changes: 46 additions & 0 deletions src/rbtree.c
Original file line number Diff line number Diff line change
@@ -1 +1,47 @@
#include <assert.h>
#include <stdlib.h>

#include <equilibrium/rbtree.h>

static void rotate_subtree_left(struct rbtree_node *root,
struct rbtree_node *pivot)
{
}
static void rotate_subtree_right(struct rbtree_node *root,
struct rbtree_node *pivot)
{
}

int rbtree_init(struct rbtree *rbtree)
{
}
int rbtree_destroy(struct rbtree *)
{
}
int rbtree_copy(struct rbtree *)
{
}
int rbtree_insert(struct rbtree *)
{
}
int rbtree_remove(struct rbtree *)
{
}
int rbtree_find(struct rbtree *, rbtree_node_compare)
{
}
struct rbtree_iterator rbtree_find_it(struct rbtree *, rbtree_node_compare)
{
}
struct rbtree_iterator rbtree_begin(struct rbtree *)
{
}
struct rbtree_iterator rbtree_end(struct rbtree *)
{
}
int rbtree_next(struct rbtree_iterator *)
{
}
int rbtree_prev(struct rbtree_iterator *)
{
}

0 comments on commit 0c0c404

Please sign in to comment.