modules/up/src/gnug++/CacheKey.CacheValue.AVLMap.h
/* [<][>][^][v][top][bottom][index][help] */
FUNCTIONS
This source file includes following functions.
- CacheKeyCacheValueAVLNode
- CacheKeyCacheValueAVLNode
- CacheKeyCacheValueAVLMap
- CacheKeyCacheValueAVLMap
- CacheKeyCacheValueAVLMap
- first
- last
- next
- prev
- key
- contents
- clear
- contains
1 // This may look like C code, but it is really -*- C++ -*-
2 /*
3 Copyright (C) 1988 Free Software Foundation
4 written by Doug Lea (dl@rocky.oswego.edu)
5
6 This file is part of the GNU C++ Library. This library is free
7 software; you can redistribute it and/or modify it under the terms of
8 the GNU Library General Public License as published by the Free
9 Software Foundation; either version 2 of the License, or (at your
10 option) any later version. This library is distributed in the hope
11 that it will be useful, but WITHOUT ANY WARRANTY; without even the
12 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 PURPOSE. See the GNU Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19
20 #ifndef _CacheKeyCacheValueAVLMap_h
21 #ifdef __GNUG__
22 #pragma interface
23 #endif
24 #define _CacheKeyCacheValueAVLMap_h 1
25
26 #include "CacheKey.CacheValue.Map.h"
27
28 struct CacheKeyCacheValueAVLNode
29 {
30 CacheKeyCacheValueAVLNode* lt;
31 CacheKeyCacheValueAVLNode* rt;
32 CacheKey item;
33 CacheValue cont;
34 char stat;
35 CacheKeyCacheValueAVLNode(CacheKey h, CacheValue& c,
36 CacheKeyCacheValueAVLNode* l=0, CacheKeyCacheValueAVLNode* r=0);
37 ~CacheKeyCacheValueAVLNode();
38 };
39
40 inline CacheKeyCacheValueAVLNode::CacheKeyCacheValueAVLNode(CacheKey h, CacheValue& c,
/* [<][>][^][v][top][bottom][index][help] */
41 CacheKeyCacheValueAVLNode* l, CacheKeyCacheValueAVLNode* r)
42 :lt(l), rt(r), item(h), cont(c), stat(0) {}
43
44 inline CacheKeyCacheValueAVLNode::~CacheKeyCacheValueAVLNode() {}
/* [<][>][^][v][top][bottom][index][help] */
45
46 typedef CacheKeyCacheValueAVLNode* CacheKeyCacheValueAVLNodePtr;
47
48
49 class CacheKeyCacheValueAVLMap : public CacheKeyCacheValueMap
/* [<][>][^][v][top][bottom][index][help] */
50 {
51 protected:
52 CacheKeyCacheValueAVLNode* root;
53
54 CacheKeyCacheValueAVLNode* leftmost();
55 CacheKeyCacheValueAVLNode* rightmost();
56 CacheKeyCacheValueAVLNode* pred(CacheKeyCacheValueAVLNode* t);
57 CacheKeyCacheValueAVLNode* succ(CacheKeyCacheValueAVLNode* t);
58 void _kill(CacheKeyCacheValueAVLNode* t);
59 void _add(CacheKeyCacheValueAVLNode*& t);
60 void _del(CacheKeyCacheValueAVLNode* p, CacheKeyCacheValueAVLNode*& t);
61
62 public:
63 CacheKeyCacheValueAVLMap(CacheValue& dflt);
64 CacheKeyCacheValueAVLMap(CacheKeyCacheValueAVLMap& a);
65 inline ~CacheKeyCacheValueAVLMap();
66
67 CacheValue& operator [] (CacheKey key);
68
69 void del(CacheKey key);
70
71 inline Pix first();
72 inline void next(Pix& i);
73 inline CacheKey& key(Pix i);
74 inline CacheValue& contents(Pix i);
75
76 Pix seek(CacheKey key);
77 inline int contains(CacheKey key);
78
79 inline void clear();
80
81 Pix last();
82 void prev(Pix& i);
83
84 int OK();
85 };
86
87 inline CacheKeyCacheValueAVLMap::~CacheKeyCacheValueAVLMap()
/* [<][>][^][v][top][bottom][index][help] */
88 {
89 _kill(root);
90 }
91
92 inline CacheKeyCacheValueAVLMap::CacheKeyCacheValueAVLMap(CacheValue& dflt) :CacheKeyCacheValueMap(dflt)
/* [<][>][^][v][top][bottom][index][help] */
93 {
94 root = 0;
95 }
96
97 inline Pix CacheKeyCacheValueAVLMap::first()
/* [<][>][^][v][top][bottom][index][help] */
98 {
99 return Pix(leftmost());
100 }
101
102 inline Pix CacheKeyCacheValueAVLMap::last()
/* [<][>][^][v][top][bottom][index][help] */
103 {
104 return Pix(rightmost());
105 }
106
107 inline void CacheKeyCacheValueAVLMap::next(Pix& i)
/* [<][>][^][v][top][bottom][index][help] */
108 {
109 if (i != 0) i = Pix(succ((CacheKeyCacheValueAVLNode*)i));
110 }
111
112 inline void CacheKeyCacheValueAVLMap::prev(Pix& i)
/* [<][>][^][v][top][bottom][index][help] */
113 {
114 if (i != 0) i = Pix(pred((CacheKeyCacheValueAVLNode*)i));
115 }
116
117 inline CacheKey& CacheKeyCacheValueAVLMap::key(Pix i)
/* [<][>][^][v][top][bottom][index][help] */
118 {
119 if (i == 0) error("null Pix");
120 return ((CacheKeyCacheValueAVLNode*)i)->item;
121 }
122
123 inline CacheValue& CacheKeyCacheValueAVLMap::contents(Pix i)
/* [<][>][^][v][top][bottom][index][help] */
124 {
125 if (i == 0) error("null Pix");
126 return ((CacheKeyCacheValueAVLNode*)i)->cont;
127 }
128
129 inline void CacheKeyCacheValueAVLMap::clear()
/* [<][>][^][v][top][bottom][index][help] */
130 {
131 _kill(root);
132 count = 0;
133 root = 0;
134 }
135
136 inline int CacheKeyCacheValueAVLMap::contains(CacheKey key)
/* [<][>][^][v][top][bottom][index][help] */
137 {
138 return seek(key) != 0;
139 }
140
141 #endif