《操作系统》的实验代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.1 KiB

12 years ago
  1. #ifndef __KERN_LIBS_RB_TREE_H__
  2. #define __KERN_LIBS_RB_TREE_H__
  3. #include <defs.h>
  4. typedef struct rb_node {
  5. bool red; // if red = 0, it's a black node
  6. struct rb_node *parent;
  7. struct rb_node *left, *right;
  8. } rb_node;
  9. typedef struct rb_tree {
  10. // compare function should return -1 if *node1 < *node2, 1 if *node1 > *node2, and 0 otherwise
  11. int (*compare)(rb_node *node1, rb_node *node2);
  12. struct rb_node *nil, *root;
  13. } rb_tree;
  14. rb_tree *rb_tree_create(int (*compare)(rb_node *node1, rb_node *node2));
  15. void rb_tree_destroy(rb_tree *tree);
  16. void rb_insert(rb_tree *tree, rb_node *node);
  17. void rb_delete(rb_tree *tree, rb_node *node);
  18. rb_node *rb_search(rb_tree *tree, int (*compare)(rb_node *node, void *key), void *key);
  19. rb_node *rb_node_prev(rb_tree *tree, rb_node *node);
  20. rb_node *rb_node_next(rb_tree *tree, rb_node *node);
  21. rb_node *rb_node_root(rb_tree *tree);
  22. rb_node *rb_node_left(rb_tree *tree, rb_node *node);
  23. rb_node *rb_node_right(rb_tree *tree, rb_node *node);
  24. void check_rb_tree(void);
  25. #endif /* !__KERN_LIBS_RBTREE_H__ */