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