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