-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtree.h
33 lines (26 loc) · 957 Bytes
/
tree.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#ifndef __TREE_H__
#define __TREE_H__
#include <kmem.h>
#include <string.h>
#include <linked_list.h>
struct tnode {
char *key;
void *value;
int nodes;
struct tnode *left;
struct tnode *right;
};
#define DO_SINGLE_XOR(i1, i2) ((unsigned int)i1)^=((unsigned int)i2)
#define SWAP(i1, i2) DO_SINGLE_XOR(i1, i2); DO_SINGLE_XOR(i2, i1); DO_SINGLE_XOR(i1, i2)
/* insert, swap, search value, search minimum and search maximum values */
struct tnode *tnode_insert(struct tnode *p, const char *key, void *value);
struct tnode *tnode_swap(struct tnode *p);
struct tnode *tnode_search(struct tnode *p, const char *key);
struct tnode *tnode_searchmin(struct tnode *p);
struct tnode *tnode_searchmax(struct tnode *p);
void tnode_startswith(struct tnode *p, struct linked_list **ll, const char *key);
void tnode_print(struct tnode *p, int num_spaces);
/* destroy, count tree nodes */
void tnode_destroy(struct tnode *);
int tnode_count(struct tnode *);
#endif