AGENT++
4.0.3
Main Page
Related Pages
Classes
Files
File List
File Members
include
agent_pp
avl_map.h
Go to the documentation of this file.
1
/*_############################################################################
2
_##
3
_## AGENT++ 4.0 - avl_map.h
4
_##
5
_## Copyright (C) 2000-2013 Frank Fock and Jochen Katz (agentpp.com)
6
_##
7
_## Licensed under the Apache License, Version 2.0 (the "License");
8
_## you may not use this file except in compliance with the License.
9
_## You may obtain a copy of the License at
10
_##
11
_## http://www.apache.org/licenses/LICENSE-2.0
12
_##
13
_## Unless required by applicable law or agreed to in writing, software
14
_## distributed under the License is distributed on an "AS IS" BASIS,
15
_## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
_## See the License for the specific language governing permissions and
17
_## limitations under the License.
18
_##
19
_##########################################################################*/
20
// This may look like C code, but it is really -*- C++ -*-
21
/*
22
Copyright (C) 1988 Free Software Foundation
23
written by Doug Lea (dl@rocky.oswego.edu)
24
25
This file is part of the GNU C++ Library. This library is free
26
software; you can redistribute it and/or modify it under the terms of
27
the GNU Library General Public License as published by the Free
28
Software Foundation; either version 2 of the License, or (at your
29
option) any later version. This library is distributed in the hope
30
that it will be useful, but WITHOUT ANY WARRANTY; without even the
31
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
32
PURPOSE. See the GNU Library General Public License for more details.
33
You should have received a copy of the GNU Library General Public
34
License along with this library; if not, write to the Free Software
35
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36
*/
37
38
39
#ifndef _OidxPtrEntryPtrAVLMap_h
40
#ifdef __GNUG__
41
#pragma interface
42
#endif
43
#define _OidxPtrEntryPtrAVLMap_h 1
44
45
#include <
agent_pp/map.h
>
46
47
#ifdef AGENTPP_NAMESPACE
48
namespace
Agentpp {
49
#endif
50
51
52
struct
OidxPtrEntryPtrAVLNode
53
{
54
OidxPtrEntryPtrAVLNode
*
lt
;
55
OidxPtrEntryPtrAVLNode
*
rt
;
56
OidxPtr
item
;
57
EntryPtr
cont
;
58
char
stat
;
59
OidxPtrEntryPtrAVLNode
(
OidxPtr
h,
EntryPtr
c,
60
OidxPtrEntryPtrAVLNode
* l=0,
61
OidxPtrEntryPtrAVLNode
* r=0);
62
~OidxPtrEntryPtrAVLNode
() {};
63
};
64
65
inline
OidxPtrEntryPtrAVLNode::OidxPtrEntryPtrAVLNode
(
OidxPtr
h,
EntryPtr
c,
66
OidxPtrEntryPtrAVLNode
* l,
67
OidxPtrEntryPtrAVLNode
* r)
68
:lt(l), rt(r), item(h), cont(c), stat(0) {}
69
70
typedef
OidxPtrEntryPtrAVLNode
*
OidxPtrEntryPtrAVLNodePtr
;
71
72
73
class
AGENTPP_DECL
OidxPtrEntryPtrAVLMap
:
public
OidxPtrEntryPtrMap
74
{
75
protected
:
76
OidxPtrEntryPtrAVLNode
*
root
;
77
78
OidxPtrEntryPtrAVLNode
* leftmost()
const
;
79
OidxPtrEntryPtrAVLNode
* rightmost()
const
;
80
OidxPtrEntryPtrAVLNode
* pred(
OidxPtrEntryPtrAVLNode
* t)
const
;
81
OidxPtrEntryPtrAVLNode
* succ(
OidxPtrEntryPtrAVLNode
* t)
const
;
82
void
_kill(
OidxPtrEntryPtrAVLNode
* t);
83
void
_add(
OidxPtrEntryPtrAVLNode
*& t);
84
void
_del(
OidxPtrEntryPtrAVLNode
* p,
OidxPtrEntryPtrAVLNode
*& t);
85
86
public
:
87
OidxPtrEntryPtrAVLMap
(
EntryPtr
deflt);
88
OidxPtrEntryPtrAVLMap
(
OidxPtrEntryPtrAVLMap
& a);
89
inline
~
OidxPtrEntryPtrAVLMap
();
90
91
EntryPtr
&
operator []
(
OidxPtr
key);
92
93
void
del
(
OidxPtr
key);
94
95
inline
Pix
first
()
const
;
96
inline
void
next
(
Pix
& i)
const
;
97
inline
OidxPtr
&
key
(
Pix
i)
const
;
98
inline
EntryPtr
&
contents
(
Pix
i);
99
100
Pix
seek
(
OidxPtr
key)
const
;
101
Pix
seek_inexact(
OidxPtr
key)
const
;
102
inline
int
contains
(
OidxPtr
key_)
const
;
103
104
inline
void
clear
();
105
106
Pix
last()
const
;
107
void
prev(
Pix
& i)
const
;
108
109
int
OK
();
110
};
111
112
inline
OidxPtrEntryPtrAVLMap::~OidxPtrEntryPtrAVLMap
()
113
{
114
_kill
(
root
);
115
}
116
117
inline
OidxPtrEntryPtrAVLMap::OidxPtrEntryPtrAVLMap
(
EntryPtr
deflt)
118
:
OidxPtrEntryPtrMap
(deflt)
119
{
120
root
= 0;
121
}
122
123
inline
Pix
OidxPtrEntryPtrAVLMap::first
()
const
124
{
125
return
Pix
(
leftmost
());
126
}
127
128
inline
Pix
OidxPtrEntryPtrAVLMap::last
()
const
129
{
130
return
Pix
(
rightmost
());
131
}
132
133
inline
void
OidxPtrEntryPtrAVLMap::next
(
Pix
& i)
const
134
{
135
if
(i != 0) i =
Pix
(
succ
((
OidxPtrEntryPtrAVLNode
*)i));
136
}
137
138
inline
void
OidxPtrEntryPtrAVLMap::prev
(
Pix
& i)
const
139
{
140
if
(i != 0) i =
Pix
(
pred
((
OidxPtrEntryPtrAVLNode
*)i));
141
}
142
143
inline
OidxPtr
&
OidxPtrEntryPtrAVLMap::key
(
Pix
i)
const
144
{
145
if
(i == 0)
error
(
"null Pix"
);
146
return
((
OidxPtrEntryPtrAVLNode
*)i)->item;
147
}
148
149
inline
EntryPtr
&
OidxPtrEntryPtrAVLMap::contents
(
Pix
i)
150
{
151
if
(i == 0)
error
(
"null Pix"
);
152
return
((
OidxPtrEntryPtrAVLNode
*)i)->cont;
153
}
154
155
inline
void
OidxPtrEntryPtrAVLMap::clear
()
156
{
157
_kill
(
root
);
158
count
= 0;
159
root
= 0;
160
}
161
162
inline
int
OidxPtrEntryPtrAVLMap::contains
(
OidxPtr
key_)
const
163
{
164
return
seek
(key_) != 0;
165
}
166
#ifdef AGENTPP_NAMESPACE
167
}
168
#endif
169
#endif
Generated by
1.8.2