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