BAM
Abstract Machine for Bottom-Up Evaluation with the Push Method
bench_tcff_2.h
Go to the documentation of this file.
1 // ============================================================================
2 // Project: Deductive Database
3 // Filename: bench_tcff_2.h
4 // Purpose: Bottom-Up Evaluation for tc(X,Y), Ver 2: Cursor interface
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 
24 //=============================================================================
25 // Include File Frame:
26 //=============================================================================
27 
28 #ifndef BENCH_TCFF_2_INCLUDED
29 #define BENCH_TCFF_2_INCLUDED
30 
31 
32 //=============================================================================
33 // This Benchmark is optional:
34 //=============================================================================
35 
36 #ifndef VER_INCLUDED
37 #include "../base/ver.h"
38 #endif
39 
40 #if VER_BENCH_TCFF_2
41 
42 
43 //=============================================================================
44 // Used Types and Macros:
45 //=============================================================================
46 
47 #ifndef STR_INCLUDED
48 #include "../base/str.h"
49 #endif
50 
51 #ifndef CHECK_INCLUDED
52 #include "../base/check.h"
53 #endif
54 
55 #ifndef STACK_INCLUDED
56 #include "../bds/stack.h"
57 #endif
58 
59 #ifndef LIST_2_INCLUDED
60 #include "../rel/list_2.h"
61 #endif
62 
63 #ifndef CUR_2_INCLUDED
64 #include "../rel/cur_2.h"
65 #endif
66 
67 #ifndef SET_2_INCLUDED
68 #include "../rel/set_2.h"
69 #endif
70 
71 #ifndef REL_N_N_INCLUDED
72 #include "../rel/rel_n_n.h"
73 #endif
74 
75 #ifndef CUR_N_N_INCLUDED
76 #include "../rel/cur_n_n.h"
77 #endif
78 
79 #ifndef BENCH_INCLUDED
80 #include "bench.h"
81 #endif
82 
83 //=============================================================================
84 // Private Constants:
85 //=============================================================================
86 
87 //-----------------------------------------------------------------------------
88 // BENCH_TCFF_2_MAGIC: Magic number (identifies objects of this class).
89 //-----------------------------------------------------------------------------
90 
91 static const long BENCH_TCFF_2_MAGIC = 0x5443460AL; // 'TCF\n'
92 
93 
94 //=============================================================================
95 // Bottom-Up Evalutation (DBLP Benchmark) - Ver. 2: Attrib., Cursor Interface.
96 //=============================================================================
97 
98 class bench_tcff_2_c : public bench_c {
99  public:
100 
101 //-----------------------------------------------------------------------------
102 // Constructor, Destructor:
103 //-----------------------------------------------------------------------------
104 
105  public:
106 
107  // Constructor:
108  bench_tcff_2_c();
109 
110  // Destructor:
111  ~bench_tcff_2_c();
112 
113 //-----------------------------------------------------------------------------
114 // (Object) Methods:
115 //-----------------------------------------------------------------------------
116 
117  // load: Load data file with EDB facts.
118  bool load(str_t filename);
119 
120  // eval: Do bottom-up evaluation.
121  long eval();
122 
123  // name: Name of this benchmark.
124  str_t name() const {
125  return
126  "tc(X,Y) Bench., Ver.2: Rel/Var->Attrs, Cursor Interface";
127  }
128 
129  // file: List of data files.
130  str_t file(int i) const;
131 
132  // result: List of correct results of eval method.
133  long result(int i) const;
134 
135  // Open cursor (note: load() must be called before this method).
136  void open();
137 
138  // fetch: Get next tuple, returns false if there is no further tuple.
139  bool fetch();
140 
141  // There are two exit points:
142  // answer(v2_1,v2_2):
143  // answer(v3_1,v2_2):
144 
145  // c1: Return value for column 1 of current row in cursor.
146  inline int c1() {
147  if(first_exit_point)
148  return v2_1;
149  else
150  return v3_1;
151  }
152 
153  // c2: Return value for column 2 of current row in cursor.
154  inline int c2() {
155  return v2_2;
156  }
157 
158  // error: Did an error occur?
159  inline bool error() {
160  if(par_ff.mem_err())
161  return true;
162  if(par_fb.mem_err())
163  return true;
164  if(tc_bb.mem_err())
165  return true;
166  return Error;
167  }
168 
169  // close: Close cursor.
170  inline void close() {
171  }
172 
173 //-----------------------------------------------------------------------------
174 // Copy-constructor and assignment operator are not supported for this class:
175 //-----------------------------------------------------------------------------
176 
177  private:
178 
179  // These methods are not implemented:
180  bench_tcff_2_c(const bench_tcff_2_c& obj);
181  bench_tcff_2_c& operator=(const bench_tcff_2_c& obj);
182 
183 
184 //-----------------------------------------------------------------------------
185 // Debugging Support:
186 //-----------------------------------------------------------------------------
187 
188 #if VER_DEBUG
189  // Integrity check:
190  public:
191  str_t check() const;
192 
193  // Magic number (identifies objects of this class for debugging).
194  private:
195  long Magic; // Must be "BENCH_TCFF_2_MAGIC".
196 #endif
197 
198 
199 #if VER_DUMP
200  public:
201  // Display data structure:
202  void dump(str_t headline = STR_NULL) const;
203 #endif
204 
205 //-----------------------------------------------------------------------------
206 // Private Object Members:
207 //-----------------------------------------------------------------------------
208 
209  private:
210 
211 //-----------------------------------------------------------------------------
212 // Relations for EDB body literals:
213 //-----------------------------------------------------------------------------
214 
215  list_2_c par_ff;
216  rel_n_n_c par_fb;
217 
218 //-----------------------------------------------------------------------------
219 // Relations for duplicate check (IDB predicates):
220 //-----------------------------------------------------------------------------
221 
222  set_2_c tc_bb;
223 
224 //-----------------------------------------------------------------------------
225 // Variables to hold values during the bottom-up evaluation:
226 //-----------------------------------------------------------------------------
227 
228  int v2_1;
229  int v2_2;
230  int v3_1;
231 
232 //-----------------------------------------------------------------------------
233 // Exit point (at which label was an answer-fact derived)?
234 //-----------------------------------------------------------------------------
235 
236  bool first_exit_point;
237 
238 //-----------------------------------------------------------------------------
239 // Cursors for loops during the bottom-up evaluation:
240 //-----------------------------------------------------------------------------
241 
242  cur_2_c c2_1_ff;
243  cur_n_n_c c3_1_fb;
244 
245 //-----------------------------------------------------------------------------
246 // Stacks for the bottom-up evaluation:
247 //-----------------------------------------------------------------------------
248 
249  stack_c<int> backtrack_stack;
250  stack_c<int> int_value_stack;
251 
252 //-----------------------------------------------------------------------------
253 // Did an error occur?
254 //-----------------------------------------------------------------------------
255 
256  bool Error;
257 
258 
259 //=============================================================================
260 // End of Class:
261 //=============================================================================
262 
263 };
264 
265 
266 //=============================================================================
267 // End of Conditional Compilation of this Benchmark (VER_BENCH_TCFF_2):
268 //=============================================================================
269 
270 #endif
271 
272 
273 //=============================================================================
274 // End of Include File:
275 //=============================================================================
276 
277 #endif
278 
Abstract Superclass of Standard Benchmarks with load() and eval()
Abstract superclass for Standard Benchmarks with load() and eval() Methods.
Definition: bench.h:67
Definition: bench_tcff_2.h:98
Definition: cur_n_n.h:68
Definition: list_2.h:58
const char * str_t
Definition: str.h:41
bool load(str_t filename)
Definition: bench_tcff_2.cpp:110
#define STR_NULL
Definition: str.h:52
Definition: rel_n_n.h:78
Definition: cur_2.h:62
Definition: set_2.h:58