BAM
Abstract Machine for Bottom-Up Evaluation with the Push Method
bench_j1axy_3.h
Go to the documentation of this file.
1 // ============================================================================
2 // Project: Deductive Database
3 // Filename: bench_j1axy_3.h
4 // Purpose: Benchmark Join1, a(X,Y), Ver. 7: goto, bitmap dupcheck, cursor
5 // Last Change: 24.08.2016
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-2016 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_3_INCLUDED
28 #define BENCH_J1AXY_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_J1AXY_3
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 BENCH_INCLUDED
76 #include "bench.h"
77 #endif
78 
79 
80 //=============================================================================
81 // Private Constants:
82 //=============================================================================
83 
84 //-----------------------------------------------------------------------------
85 // BENCH_J1AXY_3_MAGIC: Magic number (identifies objects of this class).
86 //-----------------------------------------------------------------------------
87 
88 static const long BENCH_J1AXY_3_MAGIC = 0x4A31410AL; // 'J1A\n'
89 
90 
91 //=============================================================================
92 // Benchmark Join1, a(X,Y), Ver. 7: goto, duplicate check, cursor interface
93 //=============================================================================
94 
95 class bench_j1axy_3_c : public bench_c {
96  public:
97 
98 
99 //-----------------------------------------------------------------------------
100 // Constructor, Destructor:
101 //-----------------------------------------------------------------------------
102 
103  public:
104 
105  // Constructor:
106  bench_j1axy_3_c();
107 
108  // Destructor:
109  ~bench_j1axy_3_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. 7: goto, bitmap dupcheck, cursor";
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  bool fetch();
137 
138 
139  // c1: Return value for column 1 of current row in cursor.
140  inline int c1() {
141  // answer(v_2_1,v_5_2)
142  return v_2_1;
143  }
144 
145  // c2: Return value for column 2 of current row in cursor.
146  inline int c2() {
147  // answer(v_2_1,v_5_2)
148  return v_5_2;
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  }
186 
187 //-----------------------------------------------------------------------------
188 // Copy-constructor and assignment operator are not supported for this class:
189 //-----------------------------------------------------------------------------
190 
191  private:
192 
193  // These methods are not implemented:
194  bench_j1axy_3_c(const bench_j1axy_3_c& obj);
195  bench_j1axy_3_c& operator=(const bench_j1axy_3_c& obj);
196 
197 
198 //-----------------------------------------------------------------------------
199 // Debugging Support:
200 //-----------------------------------------------------------------------------
201 
202 #if VER_DEBUG
203  // Integrity check:
204  public:
205  str_t check() const;
206 
207  // Magic number (identifies objects of this class for debugging).
208  private:
209  long Magic; // Must be "BENCH_J1AXY_3_MAGIC".
210 #endif
211 
212 
213 #if VER_DUMP
214  public:
215  // Display data structure:
216  void dump(str_t headline = STR_NULL) const;
217 #endif
218 
219 //-----------------------------------------------------------------------------
220 // Private Object Members:
221 //-----------------------------------------------------------------------------
222 
223  private:
224 
225 //-----------------------------------------------------------------------------
226 // Data storage for EDB relations:
227 //-----------------------------------------------------------------------------
228 
229  rel_n_n_c c2_bf;
230  list_2_c c3_ff;
231  rel_n_n_c c4_bf;
232  list_2_c d1_ff;
233  rel_n_n_c d2_bf;
234 
235 //-----------------------------------------------------------------------------
236 // Relation for storing derived b1 tuples (for rule with two IDB lit):
237 //-----------------------------------------------------------------------------
238 
239  rel_n_n_c b1_fb;
240  // Note that columns 1 and 2 are exchanged,
241  // because c1 is always input to the mapping, and c2 output.
242 
243 //-----------------------------------------------------------------------------
244 // Sets for duplicate checks:
245 //-----------------------------------------------------------------------------
246 
247  set_tt_c b1_bb;
248  set_tt_c b2_bb;
249  set_tt_c c1_bb;
250  set_tt_c a_bb;
251 
252 //-----------------------------------------------------------------------------
253 // Cursors for loops over relations:
254 //-----------------------------------------------------------------------------
255 
256  cur_2_c c4_1_ff;
257  cur_n_n_c c4_2_bf;
258  cur_n_n_c c3_2_bf;
259  cur_2_c c5_1_ff;
260  cur_n_n_c c5_2_bf;
261  cur_n_n_c c2_1_fb;
262 
263 
264 //-----------------------------------------------------------------------------
265 // Stack declarations:
266 //-----------------------------------------------------------------------------
267 
268  stack_c<int> backtrack_stack;
269 
270 //-----------------------------------------------------------------------------
271 // Variable declarations:
272 //-----------------------------------------------------------------------------
273 
274  int v_2_1;
275  int v_3_2;
276  int v_4_1;
277  int v_4_2;
278  int v_5_1;
279  int v_5_2;
280 
281 //-----------------------------------------------------------------------------
282 // Did an error occur?
283 //-----------------------------------------------------------------------------
284 
285  bool Error;
286 
287 //=============================================================================
288 // End of Class:
289 //=============================================================================
290 
291 };
292 
293 
294 //=============================================================================
295 // End of Conditional Compilation of this Test (VER_BENCH_J1AXY_3):
296 //=============================================================================
297 
298 #endif
299 
300 
301 //=============================================================================
302 // End of Include File:
303 //=============================================================================
304 
305 #endif
306 
Abstract Superclass of Standard Benchmarks with load() and eval()
Abstract superclass for Standard Benchmarks with load() and eval() Methods.
Definition: bench.h:67
bool load(str_t filename)
Definition: bench_j1axy_3.cpp:161
Definition: cur_n_n.h:68
Definition: bench_j1axy_3.h:95
Definition: list_2.h:58
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