Coda Distributed File System
bstree.h
Go to the documentation of this file.
1/* BLURB gpl
2
3 Coda File System
4 Release 6
5
6 Copyright (c) 1987-2003 Carnegie Mellon University
7 Additional copyrights listed below
8
9This code is distributed "AS IS" without warranty of any kind under
10the terms of the GNU General Public Licence Version 2, as shown in the
11file LICENSE. The technical and financial contributors to Coda are
12listed in the file CREDITS.
13
14 Additional copyrights
15 none currently
16
17#*/
18
19/*
20 *
21 * Specification of binary search tree.
22 *
23 */
24
25#ifndef _UTIL_BSTREE_H_
26#define _UTIL_BSTREE_H_ 1
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#include <stdio.h>
33
34#ifdef __cplusplus
35}
36#endif
37
38class bstree;
39class bsnode;
40class bstree_iterator;
41typedef int (*BSTCFN)(bsnode *, bsnode *);
42
44{
47};
48
49class bstree {
50 bsnode *root;
51 BSTCFN CmpFn; /* function to order the nodes */
52 int cnt;
53
54 /* statistics */
55 int inserts;
56 int removes;
57 int gets;
58
59public:
61 bstree(bstree &); /* not supported! */
62 int operator=(bstree &); /* not supported! */
63 virtual ~bstree();
64
65 void insert(bsnode *); /* insert in sorted order */
66 bsnode *remove(bsnode *); /* remove specified entry */
67 bsnode *first(); /* return MINIMUM node */
68 bsnode *last(); /* return MAXMIMUM node */
69 bsnode *get(BstGetType = BstGetMin); /* return and remove MIN or MAX node */
70 void clear(); /* remove all entries */
71
72 int count();
73 int IsMember(bsnode *);
74 int IsOrdered(); /* sanity checker */
75 virtual void print();
76 virtual void print(FILE *);
77 virtual void print(int);
78};
79
80class bsnode {
81 friend class bstree;
82 friend class bstree_iterator;
83 bstree *mytree;
85 bsnode *leftchild;
86 bsnode *rightchild;
87
88public:
89 bsnode();
90 bsnode(bsnode &); /* not supported! */
91 int operator=(bsnode &); /* not supported! */
92 virtual ~bsnode();
93
94 bstree *tree();
95 void print();
96 void print(FILE *);
97 void print(int);
98};
99
101{
105
107 bstree *cbstree; /* tree being iterated over */
108 bsnode *cbsnode; /* current node in the iteration */
109 BstIterOrder order;
110
111public:
113 bsnode *operator()(); /* return next node or 0 */
114};
115
116#endif /* _UTIL_BSTREE_H_ */
BstIterOrder
Definition: bstree.h:101
@ BstDescending
Definition: bstree.h:103
@ BstAscending
Definition: bstree.h:102
int(* BSTCFN)(bsnode *, bsnode *)
Definition: bstree.h:41
BstGetType
Definition: bstree.h:44
@ BstGetMin
Definition: bstree.h:45
@ BstGetMax
Definition: bstree.h:46
Definition: bstree.h:80
bstree * tree()
Definition: bstree.cc:397
void print()
Definition: bstree.cc:407
int operator=(bsnode &)
Definition: bstree.cc:389
virtual ~bsnode()
Definition: bstree.cc:395
bsnode()
Definition: bstree.cc:376
Definition: bstree.h:106
bsnode * operator()()
Definition: bstree.cc:435
bstree_iterator(bstree &, BstIterOrder=BstAscending)
Definition: bstree.cc:428
Definition: bstree.h:49
bsnode * remove(bsnode *)
Definition: bstree.cc:171
int IsMember(bsnode *)
Definition: bstree.cc:274
int operator=(bstree &)
Definition: bstree.cc:103
void clear()
Definition: bstree.cc:258
virtual void print()
Definition: bstree.cc:347
void insert(bsnode *)
Definition: bstree.cc:117
bsnode * first()
Definition: bstree.cc:210
int count()
Definition: bstree.cc:268
bsnode * last()
Definition: bstree.cc:220
bsnode * get(BstGetType=BstGetMin)
Definition: bstree.cc:230
int IsOrdered()
Definition: bstree.cc:300
virtual ~bstree()
Definition: bstree.cc:109
bstree(BSTCFN)
Definition: bstree.cc:87
PROCESS parent
Definition: smon2.c:80