Coda Distributed File System
rec_bstree.h
Go to the documentation of this file.
1/* BLURB gpl
2
3 Coda File System
4 Release 8
5
6 Copyright (c) 1987-2025 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 recoverable binary search tree.
22 *
23 */
24
25#ifndef _UTIL_REC_BSTREE_H_
26#define _UTIL_REC_BSTREE_H_ 1
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#include <stdio.h>
33
34#ifdef __cplusplus
35}
36#endif
37
38#include "bstree.h"
39#include "rvmlib.h"
40
41class rec_bstree;
42class rec_bsnode;
44typedef int (*RBSTCFN)(rec_bsnode *, rec_bsnode *);
45
46/*enum BstGetType { BstGetMin, BstGetMax };*/
47
49 rec_bsnode *root;
50 RBSTCFN CmpFn; /* function to order the nodes */
51 int cnt;
52
53 /* statistics */
54 int inserts;
55 int removes;
56 int gets;
57
58public:
59 void *operator new(size_t) REQUIRES_TRANSACTION;
60 void operator delete(void *) REQUIRES_TRANSACTION;
61
63 rec_bstree(rec_bstree &); /* not supported! */
66 void SetCmpFn(RBSTCFN);
68 int operator=(rec_bstree &); /* not supported! */
69 void DeInit();
70
71 void insert(rec_bsnode *) REQUIRES_TRANSACTION; /* insert in sorted order */
73 remove(rec_bsnode *) REQUIRES_TRANSACTION; /* remove specified entry */
74 rec_bsnode *first(); /* return MINIMUM node */
75 rec_bsnode *last(); /* return MAXMIMUM node */
77 REQUIRES_TRANSACTION; /* return and remove MIN or MAX node */
78
79 int count();
80 int IsMember(rec_bsnode *);
81 int IsOrdered(); /* sanity checker */
82 /*virtual*/ void print();
83 /*virtual*/ void print(FILE *);
84 /*virtual*/ void print(int);
85};
86
88 friend class rec_bstree;
89 friend class rec_bstree_iterator;
90 rec_bstree *mytree;
92 rec_bsnode *leftchild;
93 rec_bsnode *rightchild;
94
95public:
96 rec_bsnode();
98 rec_bsnode(rec_bsnode &); /* not supported! */
99 int operator=(rec_bsnode &); /* not supported! */
100 /*
101 ~rec_bsnode();
102 void DeInit();
103*/
104
105 rec_bstree *tree();
106 /*virtual*/ void print();
107 /*virtual*/ void print(FILE *);
108 /*virtual*/ void print(int);
109};
110
111/*enum BstIterOrder { BstAscending, BstDescending };*/
112
114 rec_bstree *crec_bstree; /* tree being iterated over */
115 rec_bsnode *crec_bsnode; /* current node in the iteration */
116 BstIterOrder order;
117
118public:
120 rec_bsnode *operator()(); /* return next node or 0 */
121};
122
123#endif /* _UTIL_REC_BSTREE_H_ */
BstIterOrder
Definition: bstree.h:101
@ BstAscending
Definition: bstree.h:102
BstGetType
Definition: bstree.h:44
@ BstGetMin
Definition: bstree.h:45
Definition: rec_bstree.h:87
void print()
Definition: rec_bstree.cc:474
rec_bstree * tree()
Definition: rec_bstree.cc:464
friend class rec_bstree_iterator
Definition: rec_bstree.h:89
void Init() REQUIRES_TRANSACTION
Definition: rec_bstree.cc:434
rec_bsnode()
Definition: rec_bstree.cc:428
Definition: rec_bstree.h:113
rec_bsnode * operator()()
Definition: rec_bstree.cc:502
Definition: rec_bstree.h:48
void DeInit()
Definition: rec_bstree.cc:129
int count()
Definition: rec_bstree.cc:320
void Init(RBSTCFN) REQUIRES_TRANSACTION
Definition: rec_bstree.cc:116
void ClearStatistics() REQUIRES_TRANSACTION
Definition: rec_bstree.cc:144
int IsOrdered()
Definition: rec_bstree.cc:352
int operator=(rec_bstree &)
Definition: rec_bstree.cc:158
rec_bsnode * first()
Definition: rec_bstree.cc:271
void SetCmpFn(RBSTCFN)
Definition: rec_bstree.cc:136
int IsMember(rec_bsnode *)
Definition: rec_bstree.cc:326
void insert(rec_bsnode *) REQUIRES_TRANSACTION
Definition: rec_bstree.cc:165
void print()
Definition: rec_bstree.cc:399
rec_bsnode * get(BstGetType=BstGetMin) REQUIRES_TRANSACTION
Definition: rec_bstree.cc:291
rec_bsnode * remove(rec_bsnode *) REQUIRES_TRANSACTION
Definition: rec_bstree.cc:227
rec_bsnode * last()
Definition: rec_bstree.cc:281
rec_bstree(RBSTCFN)
Definition: rec_bstree.cc:106
~rec_bstree()
Definition: rec_bstree.cc:111
#define REQUIRES_TRANSACTION
Definition: coda_tsa.h:107
int(* RBSTCFN)(rec_bsnode *, rec_bsnode *)
Definition: rec_bstree.h:44
PROCESS parent
Definition: smon2.c:80