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