File: btree.h

package info (click to toggle)
vile 9.2y-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 5,700 kB
  • ctags: 7,341
  • sloc: ansic: 78,427; lex: 4,726; perl: 2,922; cpp: 2,710; sh: 2,612; makefile: 715; awk: 212
file content (54 lines) | stat: -rw-r--r-- 1,237 bytes parent folder | download | duplicates (2)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
 * $Id: btree.h,v 1.4 2001/12/21 12:19:24 tom Exp $
 *
 * Interface for btree.c
 */
#ifndef BTREE_H
#define BTREE_H 1

#ifndef BI_DATA
#define BI_DATA struct _bi_data
 	BI_DATA {
	char	*bi_key;	/* the key */
	void	*data;		/* ...associated data */
	};
#endif

#define BI_NODE struct _bi_node
	BI_NODE	{
	BI_NODE	*links[2];
	int	 balance;	/* holds 0, -1, +1 */
	BI_DATA  value;
	};

#define BI_TREE struct _bi_tree
	BI_TREE	{
	BI_NODE*(*allocat) (BI_DATA *a);
	void	(*dealloc) (BI_NODE *a);
	void	(*display) (BI_NODE *a, int level);
	int	depth;
	int	count;
	BI_NODE	head;		/* root data, on end to ease initialization */
	};

#define	BI_KEY(p)	(p)->value.bi_key
#define	BI_LEFT(p)	(p)->links[0]
#define	BI_RIGHT(p)	(p)->links[1]

#ifdef __cplusplus
extern "C" {
#endif

extern	int	 btree_delete(BI_TREE *tree, const char *data);
extern	int	 btree_freeup(BI_TREE *tree);
extern	BI_DATA *btree_insert(BI_TREE *tree, BI_DATA *data);
extern	const char **btree_parray(BI_TREE *tree, char *name, unsigned len);
extern	BI_NODE *btree_pmatch(BI_NODE *n, const int mode, const char *name);
extern	void	 btree_printf(BI_TREE *tree);
extern	BI_DATA *btree_search(BI_TREE *tree, const char *data);

#ifdef __cplusplus
}
#endif

#endif /* BTREE_H */