BAM
Abstract Machine for Bottom-Up Evaluation with the Push Method
bench_j1axy_5.h
Go to the documentation of this file.
1 // ============================================================================
2 // Project: Deductive Database
3 // Filename: bench_j1axy_5.h
4 // Purpose: Benchmark Join1, a(X,Y), Ver. 5: functions without args, bitmap
5 // Last Change: 17.09.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) 2016-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_J1AXY_5_INCLUDED
28 #define BENCH_J1AXY_5_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_J1AXY_5
40 
41 
42 //=============================================================================
43 // Used Types and Macros:
44 //=============================================================================
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 LIST_2_INCLUDED
56 #include "../rel/list_2.h"
57 #endif
58 
59 #ifndef CUR_2_INCLUDED
60 #include "../rel/cur_2.h"
61 #endif
62 
63 #ifndef SET_TT_INCLUDED
64 #include "../rel/set_tt.h"
65 #endif
66 
67 #ifndef REL_N_N_INCLUDED
68 #include "../rel/rel_n_n.h"
69 #endif
70 
71 #ifndef CUR_N_N_INCLUDED
72 #include "../rel/cur_n_n.h"
73 #endif
74 
75 #ifndef OUT_INCLUDED
76 #include "out.h"
77 #endif
78 
79 #ifndef BENCH_INCLUDED
80 #include "bench.h"
81 #endif
82 
83 
84 //=============================================================================
85 // Private Constants:
86 //=============================================================================
87 
88 //-----------------------------------------------------------------------------
89 // BENCH_J1AXY_5_MAGIC: Magic number (identifies objects of this class).
90 //-----------------------------------------------------------------------------
91 
92 static const long BENCH_J1AXY_5_MAGIC = 0x4A31410AL; // 'J1A\n'
93 
94 
95 //=============================================================================
96 // Benchmark Join1, a(X,Y), Ver. 5: functions without args, bitmap dupcheck
97 //=============================================================================
98 
99 class bench_j1axy_5_c : public bench_c {
100  public:
101 
102 
103 //-----------------------------------------------------------------------------
104 // Constructor, Destructor:
105 //-----------------------------------------------------------------------------
106 
107  public:
108 
109  // Constructor:
110  bench_j1axy_5_c();
111 
112  // Destructor:
113  ~bench_j1axy_5_c();
114 
115 //-----------------------------------------------------------------------------
116 // (Object) Methods:
117 //-----------------------------------------------------------------------------
118 
119  // load: Load data file with EDB facts.
120  bool load(str_t filename);
121 
122  // eval: Do bottom-up evaluation.
123  long eval();
124 
125  // name: Name of this benchmark.
126  str_t name() const {
127  return "Join 1, a(X,Y), Ver. 5: functions without args, bitmap";
128  }
129 
130  // file: List of data files.
131  str_t file(int i) const;
132 
133  // result: List of correct results of the eval method.
134  long result(int i) const;
135 
136  // Open cursor (note: load() must be called before this method).
137  void open();
138 
139  // fetch: Get next tuple, returns false if there is no further tuple.
140  inline bool fetch() {
141  return result_cursor.fetch();
142  }
143 
144 
145  // c1: Return value for column 1 of current row in cursor.
146  inline int c1() {
147  return result_cursor.c1();
148  }
149 
150  // c2: Return value for column 2 of current row in cursor.
151  inline int c2() {
152  return result_cursor.c2();
153  }
154 
155  // error: Did an error occur?
156  inline bool error() {
157  // EDB relations:
158  if(c2_bf.mem_err())
159  return true;
160  if(c3_ff.mem_err())
161  return true;
162  if(c4_bf.mem_err())
163  return true;
164  if(d1_ff.mem_err())
165  return true;
166  if(d2_bf.mem_err())
167  return true;
168 
169  // Derived b1 tuples (for rule with two IDB lit):
170  if(b1_fb.mem_err())
171  return true;
172 
173  // Sets for duplicate checks:
174  if(b1_bb.mem_err())
175  return true;
176  if(b2_bb.mem_err())
177  return true;
178  if(c1_bb.mem_err())
179  return true;
180  if(a_bb.mem_err())
181  return true;
182 
183  // Error with backtrack stacks:
184  return Error;
185  }
186 
187  // close: Close cursor.
188  inline void close() {
189  result_cursor.close();
190  }
191 
192 //-----------------------------------------------------------------------------
193 // Copy-constructor and assignment operator are not supported for this class:
194 //-----------------------------------------------------------------------------
195 
196  private:
197 
198  // These methods are not implemented:
199  bench_j1axy_5_c(const bench_j1axy_5_c& obj);
200  bench_j1axy_5_c& operator=(const bench_j1axy_5_c& obj);
201 
202 
203 //-----------------------------------------------------------------------------
204 // Debugging Support:
205 //-----------------------------------------------------------------------------
206 
207 #if VER_DEBUG
208  // Integrity check:
209  public:
210  str_t check() const;
211 
212  // Magic number (identifies objects of this class for debugging).
213  private:
214  long Magic; // Must be "BENCH_J1AXY_5_MAGIC".
215 #endif
216 
217 
218 #if VER_DUMP
219  public:
220  // Display data structure:
221  void dump(str_t headline = STR_NULL) const;
222 #endif
223 
224 //-----------------------------------------------------------------------------
225 // Private Object Members:
226 //-----------------------------------------------------------------------------
227 
228  private:
229 
230 //-----------------------------------------------------------------------------
231 // Data storage for EDB relations:
232 //-----------------------------------------------------------------------------
233 
234  rel_n_n_c c2_bf;
235  list_2_c c3_ff;
236  rel_n_n_c c4_bf;
237  list_2_c d1_ff;
238  rel_n_n_c d2_bf;
239 
240 //-----------------------------------------------------------------------------
241 // Relation for storing derived b1 tuples (for rule with two IDB lit):
242 //-----------------------------------------------------------------------------
243 
244  rel_n_n_c b1_fb;
245  // Note that columns 1 and 2 are exchanged,
246  // because c1 is always input to the mapping, and c2 output.
247 
248 //-----------------------------------------------------------------------------
249 // Sets for duplicate checks:
250 //-----------------------------------------------------------------------------
251 
252  set_tt_c b1_bb;
253  set_tt_c b2_bb;
254  set_tt_c c1_bb;
255  set_tt_c a_bb;
256 
257 //-----------------------------------------------------------------------------
258 // Cursors for loops over relations:
259 //-----------------------------------------------------------------------------
260 
261  cur_2_c c4_1_ff;
262  cur_n_n_c c4_2_bf;
263  cur_n_n_c c3_2_bf;
264  cur_2_c c5_1_ff;
265  cur_n_n_c c5_2_bf;
266  cur_n_n_c c2_1_fb;
267 
268 
269 //-----------------------------------------------------------------------------
270 // Result list and cursor:
271 //-----------------------------------------------------------------------------
272 
273  list_2_c result_list;
274  cur_2_c result_cursor;
275 
276 //-----------------------------------------------------------------------------
277 // Variable declarations:
278 //-----------------------------------------------------------------------------
279 
280  int v_2_1;
281  int v_3_2;
282  int v_4_1;
283  int v_4_2;
284  int v_5_1;
285  int v_5_2;
286 
287 //-----------------------------------------------------------------------------
288 // Call Depth for Trace Output:
289 //-----------------------------------------------------------------------------
290 
291  OUT_TRACE_DEPTH_DECL;
292 
293 //-----------------------------------------------------------------------------
294 // Did an error occur?
295 //-----------------------------------------------------------------------------
296 
297  bool Error;
298 
299 //-----------------------------------------------------------------------------
300 // Auxiliary functions:
301 //-----------------------------------------------------------------------------
302 
303  private:
304 
305  // start_rule_4: Compute c1 facts for rule with only EDB body literals.
306  inline void start_rule_4();
307 
308  // derived_c1: Function to call when c1(v_4_1,v_4_2) was derived.
309  inline void derived_c1();
310 
311  // derived_b1: Function to call when b1(v_4_1,v_3_2) was derived.
312  inline void derived_b1();
313 
314  // start_rule_5: Compute b2 facts for rule with only EDB body literals.
315  inline void start_rule_5();
316 
317  // derived_b2: Function to call when b2(v_5_1,v_5_2) was derived.
318  inline void derived_b2();
319 
320  // derived_a: Function to call when a(v_2_1,v_5_2) was derived.
321  inline void derived_a();
322 
323 //=============================================================================
324 // End of Class:
325 //=============================================================================
326 
327 };
328 
329 
330 //=============================================================================
331 // End of Conditional Compilation of this Test (VER_BENCH_J1AXY_5):
332 //=============================================================================
333 
334 #endif
335 
336 
337 //=============================================================================
338 // End of Include File:
339 //=============================================================================
340 
341 #endif
342 
Abstract Superclass of Standard Benchmarks with load() and eval()
Abstract superclass for Standard Benchmarks with load() and eval() Methods.
Definition: bench.h:67
Selective Output for Tests/Benchmarks.
Definition: cur_n_n.h:68
Definition: list_2.h:58
bool load(str_t filename)
Definition: bench_j1axy_5.cpp:166
Definition: bench_j1axy_5.h:99
const char * str_t
Definition: str.h:41
Definition: set_tt.h:121
#define STR_NULL
Definition: str.h:52
Definition: rel_n_n.h:78
Definition: cur_2.h:62