BAM
Abstract Machine for Bottom-Up Evaluation with the Push Method
Main Page
Related Pages
Classes
Files
File List
File Members
rel
rel.h
Go to the documentation of this file.
1
// ============================================================================
2
// Project: Deductive Database
3
// Filename: rel.h
4
// Purpose: Superclass of all data structures for relations
5
// Last Change: 04.08.2017
6
// Language: C++
7
// EMail: brass@informatik.uni-halle.de
8
// WWW: http://www.informatik.uni-halle.de/~brass/
9
// Address: Feldschloesschen 15, D-06120 Halle (Saale), GERMANY
10
// Copyright: (c) 2015-2017 by Stefan Brass
11
// License: See file "LICENSE" for copying conditions.
12
// Note: There is no warranty at all - this code may contain bugs.
13
// ============================================================================
14
15
28
//=============================================================================
29
// Include File Frame:
30
//=============================================================================
31
32
#ifndef REL_INCLUDED
33
#define REL_INCLUDED
34
35
//=============================================================================
36
// Used Types and Macros:
37
//=============================================================================
38
39
#ifndef VER_INCLUDED
40
#include "../base/ver.h"
41
#endif
42
43
#ifndef STR_INCLUDED
44
#include "../base/str.h"
45
#endif
46
47
#ifndef CHECK_INCLUDED
48
#include "../base/check.h"
49
#endif
50
51
#ifndef MPOOL_INCLUDED
52
#include "../mem/mpool.h"
53
#endif
54
55
56
//=============================================================================
57
// Private Constants:
58
//=============================================================================
59
60
61
//-----------------------------------------------------------------------------
62
// REL_MAGIC: Magic number (identifies objects of this class).
63
//-----------------------------------------------------------------------------
64
65
static
const
long
REL_MAGIC = 0x52454C0AL;
// 'REL\n'
66
67
68
//=============================================================================
69
// Superclass of all data structures for storing relations:
70
//=============================================================================
71
72
class
rel_c
{
73
protected
:
74
75
//-----------------------------------------------------------------------------
76
// Constructor, Destructor:
77
//-----------------------------------------------------------------------------
78
79
// Constructor:
80
rel_c
(
str_t
rel_name,
int
bound,
int
free,
str_t
impl);
81
82
// Destructor:
83
~
rel_c
();
84
85
//-----------------------------------------------------------------------------
86
// Copy-constructor and assignment operator are not supported for this class:
87
//-----------------------------------------------------------------------------
88
89
private
:
90
91
rel_c
(
const
rel_c
& obj);
// Not implemented
92
rel_c
& operator=(
const
rel_c
& obj);
// Not implemented
93
94
95
//=============================================================================
96
// (Object) Methods:
97
//=============================================================================
98
99
public
:
100
101
//-----------------------------------------------------------------------------
102
// name: Get name of this table/relation.
103
//-----------------------------------------------------------------------------
104
105
str_t
name()
const
{
106
CHECK_VALID
(
"set::name"
);
107
return
Name;
108
}
109
110
//-----------------------------------------------------------------------------
111
// mem_err: Did we get enough memory pages?
112
//-----------------------------------------------------------------------------
113
114
bool
mem_err()
const
{
115
CHECK_VALID
(
"rel_c::mem_err"
);
116
return
MemErr;
117
}
118
119
//-----------------------------------------------------------------------------
120
// num_rows: Get number of rows (tuples) in this table.
121
//-----------------------------------------------------------------------------
122
123
int
num_rows()
const
{
124
CHECK_VALID
(
"rel_c::num_rows"
);
125
return
NumRows;
126
}
127
128
//-----------------------------------------------------------------------------
129
// num_cols: Get number of columns (attributes) of this table.
130
//-----------------------------------------------------------------------------
131
132
int
num_cols()
const
{
133
CHECK_VALID
(
"rel_c::num_cols"
);
134
return
FreeArgs + BoundArgs;
135
}
136
137
138
//-----------------------------------------------------------------------------
139
// bound_args: Number of bound (input) arguments of the relation.
140
//-----------------------------------------------------------------------------
141
153
int
bound_args
() {
154
155
// Check this object:
156
CHECK_VALID
(
"rel_c::bound_args"
);
157
158
// Return number of bound arguments:
159
return
BoundArgs;
160
}
161
162
163
//-----------------------------------------------------------------------------
164
// free_args: Number of free (output) arguments of the relation.
165
//-----------------------------------------------------------------------------
166
167
179
int
free_args
() {
180
181
// Check this object:
182
CHECK_VALID
(
"rel_c::free_args"
);
183
184
// Return number of free arguments:
185
return
FreeArgs;
186
}
187
188
//-----------------------------------------------------------------------------
189
// impl_name: Implementation (data structure) used for this relation.
190
//-----------------------------------------------------------------------------
191
192
201
str_t
impl_name
() {
202
203
// Check this object:
204
CHECK_VALID
(
"rel_c::impl_name"
);
205
206
// Return the implementation name.
207
return
ImplName;
208
}
209
210
//-----------------------------------------------------------------------------
211
// num_pages: Get number of memory pages used for this relation.
212
//-----------------------------------------------------------------------------
213
214
int
num_pages()
const
{
215
CHECK_VALID
(
"rel_c::num_pages"
);
216
return
MemPool.num_alloc_pages();
217
}
218
219
220
//=============================================================================
221
// Debugging Support:
222
//=============================================================================
223
224
#if VER_DEBUG
225
public
:
226
// Integrity check:
227
str_t
check()
const
;
228
229
private
:
230
// Magic number (identifies objects of this class for debugging).
231
long
Magic;
// Must be "REL_MAGIC".
232
#endif
233
234
#if VER_DUMP
235
public
:
236
// Display data structure:
237
void
dump(
str_t
headline =
STR_NULL
)
const
;
238
#endif
239
240
241
//=============================================================================
242
// Protected Object Members:
243
//=============================================================================
244
245
protected
:
246
247
// Memory Pool for Allocating Storage Pages:
248
mpool_c
MemPool;
249
250
// Name of this set (table/relation):
251
str_t
Name;
252
253
// Did a memory page allocation error occur?
254
bool
MemErr;
255
256
// Current number of rows/tuples:
257
int
NumRows;
258
259
// Number of "bound" (input) arguments:
260
int
BoundArgs;
261
262
// Number of "free" (output) arguments:
263
int
FreeArgs;
264
265
// If there are no bound arguments, it is a list data structure.
266
// If there are no free arguments, it is a set data structure.
267
// Otherwise it is a multi-map,
268
// i.e. for given values for the input arguments,
269
// there is a set/list of rows for the output arguments.
270
271
// Implementation (data structure) name:
272
str_t
ImplName;
273
274
//=============================================================================
275
// End of Class:
276
//=============================================================================
277
278
};
279
280
//-----------------------------------------------------------------------------
281
// Define pointer type:
282
//-----------------------------------------------------------------------------
283
284
typedef
rel_c
*
rel_t
;
285
286
//-----------------------------------------------------------------------------
287
// Define null pointer:
288
//-----------------------------------------------------------------------------
289
290
#define REL_NULL (static_cast<rel_t>(0))
291
292
293
//=============================================================================
294
// End of Include File:
295
//=============================================================================
296
297
#endif
298
mpool_c
Definition:
mpool.h:103
rel_c
Definition:
rel.h:72
rel_c::bound_args
int bound_args()
Definition:
rel.h:153
CHECK_VALID
#define CHECK_VALID(EX)
Definition:
check.h:85
str_t
const char * str_t
Definition:
str.h:41
STR_NULL
#define STR_NULL
Definition:
str.h:52
rel_c::impl_name
str_t impl_name()
Definition:
rel.h:201
rel_c::free_args
int free_args()
Definition:
rel.h:179
Generated by
1.8.10