const.h
Go to the documentation of this file.
1 // File: $Id$
2 // Author: John Wu <John.Wu at acm.org>
3 // Lawrence Berkeley National Laboratory
4 // Copyright (c) 2000-2016 the Regents of the University of California
5 #ifndef IBIS_CONST_H
6 #define IBIS_CONST_H
7 // Primary contact: John Wu <John.Wu at acm.org>
8 //
14 
15 #if defined(DEBUG) && !defined(_DEBUG)
16 # define _DEBUG DEBUG
17 #elif !defined(DEBUG) && defined(_DEBUG) && _DEBUG + 0 > 1
18 # define DEBUG _DEBUG - 1
19 #endif
20 // gcc's stl header files needs this one to work correctly
21 #ifndef _PTHREADS
22 # define _PTHREADS
23 #endif
24 #ifndef _REENTRANT
25 # define _REENTRANT
26 #endif
27 #ifndef _ISOC90_SOURCE
28 # define _ISOC90_SOURCE
29 #endif
30 // machine related feature selection
31 #if defined(__SUNPRO_CC)
32 # ifndef __EXTENSIONS__
33 # define __EXTENSIONS__
34 # endif
35 #elif defined(__KCC)
36 // the following combination appears to get the right functions
37 # ifdef _POSIX_C_SOURCE
38 # undef _POSIX_C_SOURCE
39 # endif
40 # ifndef _XOPEN_VERSION
41 # define _XOPEN_VERSION 4
42 # else
43 # undef _XOPEN_VERSION
44 # define _XOPEN_VERSION 4
45 # endif
46 #endif
47 // #if defined(__unix__) && !defined(__USE_UNIX98)
48 // #define __USE_UNIX98
49 // #endif
50 #ifndef HAVE_STRUCT_TIMESPEC
51 #if defined(__CYGWIN__) || defined(__MINGW32__) || (_MSC_VER+0 >= 1900)
52 # define HAVE_STRUCT_TIMESPEC
53 #endif
54 #endif
55 // // require every compiler to support mutable keyword
56 // #if __cplusplus >= 199711L
57 // # define HAVE_MUTABLE 1
58 // #elif defined(__GNUC__)
59 // # define HAVE_MUTABLE (__GNUC__>2 || (__GNUC__>1 && __GNUC_MINOR__-0>=95))
60 // #elif defined(__SUNPROC_CC)
61 // # define HAVE_MUTABLE (__SUNPRO_CC >= 0x500)
62 // #elif defined(_MSC_VER)
63 // # define HAVE_MUTABLE (_MSC_VER >= 1200)
64 // #elif defined(__PGI)
65 // # define HAVE_MUTABLE 1
66 // #elif defined(__sgi)
67 // # define HAVE_MUTABLE (_COMPILER_VERSION > 600)
68 // #else
69 // # define HAVE_MUTABLE 0
70 // #endif
71 
72 //
73 // common headers needed
74 #if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG)
75 // Enable memory debugging on windows environments
76 # define _CRTDBG_MAP_ALLOC
77 # include <stdlib.h>
78 # include <crtdbg.h>
79 #endif
80 
81 #include <errno.h> // errno
82 #include <string.h> // strerr, strcasecmp, strcmp, memcpy, strlen
83 #include <pthread.h> // mutex lock, rwlock, conditional variables
84 #if !defined(WITHOUT_FASTBIT_CONFIG_H) && !defined(__MINGW32__) && !defined(_MSC_VER)
85 # include "fastbit-config.h" // macros defined by the configure script
86 # ifdef HAVE_SYS_TYPES_H
87 # include <sys/types.h> // timespec, etc
88 # endif
89 # ifdef HAVE_STDINT_H
90 # include <stdint.h>
91 # endif
92 #else
93 # if defined(__unix__)||defined(__linux__)||defined(__APPLE__)||defined(__CYGWIN__)||defined(__FreeBSD__)
94 # define HAVE_VPRINTF 1
95 # define HAVE_DIRENT_H 1
96 # endif
97 # if !defined(_MSC_VER)
98 # include <stdint.h>
99 # endif
100 #endif
101 
102 // section to handle errno in a multithread program
103 #if defined(__SUNPRO_CC)
104 # if defined(_REENTRANT)
105 # ifdef errno
106 # undef errno
107 # endif
108 # define errno (*(::___errno()))
109 # endif // defined(_REENTRANT)
110 // #elif defined(_WIN32)
111 // # if defined(_MT) || defined(_DLL)
112 // extern int * __cdecl _errno(void);
113 // # define errno (*_errno(void))
114 // # else /* ndef _MT && ndef _DLL */
115 // extern int errno;
116 // # endif /* _MT || _DLL */
117 #endif /* errno */
118 
119 // Compiler independent definitions:
120 #ifndef FASTBIT_STRING
121 #define FASTBIT_STRING "FastBit ibis"
122 #endif
123 //#define TIME_BUF_LEN 32
124 #ifndef MAX_LINE
125 #define MAX_LINE 2048
126 #endif
127 // #ifndef mmax
128 // #define mmax(x,y) ((x)>(y))?(x):(y)
129 // #endif
130 
136 #ifndef PREFERRED_BLOCK_SIZE
137 #define PREFERRED_BLOCK_SIZE 1048576
138 //#define PREFERRED_BLOCK_SIZE 262144
139 #endif
140 
141 //
142 // Compiler dependent definitions:
143 #if defined(_CRAY) | defined(__KCC)
144 # define __LIM_H_PARAM_
145 # include <sys/param.h>
146 # include <inttypes.h> // int32_t, ...
147 
148 #elif defined(__sun)
149 # include <limits.h> // PATH_MAX, OPEN_MAX
150 # include <inttypes.h> // int32_t, ...
151 
152 // use rwlock_t to simulate pthread_rwlock_t
153 # ifndef PTHREAD_RWLOCK_INITIALIZER
154 # include <synch.h> // rwlock
155 # define pthread_rwlock_t rwlock_t
156 # define pthread_rwlock_init(lk, attr) rwlock_init(lk, attr, 0)
157 # define pthread_rwlock_destroy rwlock_destroy
158 # define pthread_rwlock_rdlock rw_rdlock
159 # define pthread_rwlock_wrlock rw_wrlock
160 # define pthread_rwlock_tryrdlock rw_tryrdlock
161 # define pthread_rwlock_trywrlock rw_trywrlock
162 # define pthread_rwlock_unlock rw_unlock
163 # define PTHREAD_RWLOCK_INITIALIZER DEFAULTRWLOCK;
164 # endif
165 
166 #elif defined(__unix__) || defined(__HOS_AIX__)
167 # include <limits.h> // PATH_MAX, OPEN_MAX
168 # ifdef __CYGWIN__ // cygwin port of gcc compiler
169 //commented out 2005/04/12 # define __INSIDE_CYGWIN__
170 # include <cygwin/types.h>
171 # endif
172 
173 #elif defined(_WIN32)
174 // don't need too many things from Windows header files
175 # define WIN32_LEAN_AND_MEAN
176 // if WINVER is not define, pretend to be on windows vista
177 # ifndef WINVER
178 # ifdef _WIN32_WINNT
179 # define WINVER _WIN32_WINNT
180 # else
181 # define WINVER 0x0600
182 # endif
183 # endif
184 # include <limits.h> // PATH_MAX, OPEN_MAX
185 # include <windows.h>
186 # include <direct.h> // _mkdir
187 # define mkdir(x,y) _mkdir(x)
188 # define chmod _chmod
189 
190 # if defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__)
191 # include <stdint.h>
192 # else
193  // MS windows has its own exact-width types, use them
194 # ifndef int16_t
195 # define int16_t __int16
196 # endif
197 # ifndef uint16_t
198 # define uint16_t unsigned __int16
199 # endif
200 # ifndef int32_t
201 # define int32_t __int32
202 # endif
203 # ifndef uint32_t
204 # define uint32_t unsigned __int32
205 # endif
206 # ifndef int64_t
207 # define int64_t __int64
208 # endif
209 # ifndef uint64_t
210 # define uint64_t unsigned __int64
211 # endif
212 # endif
213 
214 #elif defined(__APPLE__)
215 # include <stdint.h> // int32_t, ...
216 # include <sys/syslimits.h>
217 
218 #else
219 # include <stdint.h> // int32_t, ...
220 # include <syslimits.h> // PATH_MAX
221 
222 #endif
223 
224 // a hack to check for exact-width data types -- according the Open Group's
225 // definition of stdint.h, when the exact-width integer types are defined,
226 // their corresponding MAX values are also defined with #define. Since the
227 // types themselves may be typedefs, the corresponding INTx_MAX are more
228 // reliable checks.
229 #if !(defined(HAVE_STDINT_H) || defined(__unix__) || defined(_WIN32) || defined(__APPLE__) || defined(__x86_64__) || defined(_STDINT_H))
230 # ifndef INT16_MAX
231 # define int16_t short int
232 # define INT16_MAX (32767)
233 # endif
234 # ifndef UINT16_MAX
235 # define uint16_t unsigned short int
236 # define UINT16_MAX (65535)
237 # endif
238 # ifndef INT32_MAX
239 # define int32_t int
240 # define INT32_MAX (2147483647)
241 # endif
242 # ifndef UINT32_MAX
243 # define uint32_t unsigned int
244 # define UINT32_MAX (4294967295UL)
245 # endif
246 # ifndef INT64_MAX
247 # define int64_t long long int
248 # define INT64_MAX (9223372036854775807LL)
249 # endif
250 # ifndef UINT64_MAX
251 # define uint64_t unsigned long long int
252 # define UINT64_MAX (18446744073709551615ULL)
253 # endif
254 #endif
255 
256 #ifndef PATH_MAX
257 # define PATH_MAX 512
258 #endif
259 
260 // things for MS Windows only
261 // FASTBIT_DIRSEP == the directory name separator
262 // FASTBIT_CXX_DLLSPEC == export/import symbols to/from DLL library under windows system
263 #if defined(_WIN32) && defined(_MSC_VER)
264 # define FASTBIT_DIRSEP '\\'
265 #else
266 # define FASTBIT_DIRSEP '/'
267 #endif
268 
269 #if defined(_WIN32) && (defined(_MSC_VER) || defined(__MINGW32__))
270 # if defined(_USRDLL) || defined(CXX_USE_DLL)
271 # if defined(DLL_EXPORT)
272 # define FASTBIT_CXX_DLLSPEC __declspec(dllexport)
273 # else
274 # define FASTBIT_CXX_DLLSPEC __declspec(dllimport)
275 # endif
276 # else
277 # define FASTBIT_CXX_DLLSPEC
278 # endif
279 #else
280 # define FASTBIT_CXX_DLLSPEC
281 #endif
282 
283 /* causes problems on solaris 2.8
284 #ifdef PTHREAD_RWLOCK_INITIALIZER
285 #if xPTHREAD_RWLOCK_INITIALIZER == x
286 #undef PTHREAD_RWLOCK_INITIALIZER
287 #endif
288 #endif
289 */
290 #if defined(__APPLE__) && !defined(PTHREAD_RWLOCK_INITIALIZER)
291 #define PTHREAD_RWLOCK_INITIALIZER
292 #endif
293 // still don't have correct RWLOCK, then use mutex lock instead
294 #ifndef PTHREAD_RWLOCK_INITIALIZER
295 #define IBIS_REPLACEMENT_RWLOCK
296 #define THREAD_RWLOCK_INITIALIZER \
297  {PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, \
298  PTHREAD_COND_INITIALIZER, 0, 0}
299 typedef struct _rwlock {
300  pthread_mutex_t lock; // lock for structure
301  pthread_cond_t readers; // waiting readers
302  pthread_cond_t writers; // waiting writers
303  int state; // -1:writer,0:free,>0:readers
304  int waiters; // number of waiting writers
306 int pthread_rwlock_init(pthread_rwlock_t *rwlock, void*);
307 int pthread_rwlock_destroy(pthread_rwlock_t *rwlock);
308 int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
309 int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
310 int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
311 int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock);
312 int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
313 #endif
314 
340 typedef int (*FastBitReadBitmaps)
341 (void *context, uint64_t start, uint64_t count, uint32_t *data);
342 
364 typedef int (*FastBitReadExtArray)
365 (void *context, uint64_t nd, uint64_t *starts, uint64_t *counts, void *data);
366 
367 //
368 // functions for case-insensitive string comparisons
369 //
370 #ifdef _WIN32
371 # if _MSC_VER >= 1500 || defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__)
372 # define strnicmp _strnicmp
373 # define stricmp _stricmp
374 # endif
375 #else
376 # include <strings.h> // strcasecmp, strncasecmp
377 # define MessageBox(x1,x2,x3,x4); {} // fake message box
378 # define strnicmp strncasecmp
379 # define stricmp strcasecmp
380 #endif
381 
382 // C++ portion
383 #ifdef __cplusplus
384 
385 #if defined(__SUNPRO_CC)
386 # if (__SUNPRO_CC < 0x500)
387 # include <iostream.h>
388  typedef int bool;
389 # define false 0
390 # define true 1
391 # define std
392 # define mutable
393 # define explicit
394 # else
395 # include <iosfwd> // std::cout, std::clog
396 # endif
397 #else
398 # include <iosfwd> // std::cout, std::clog
399 #endif
400 // #ifndef REASON
401 // # define REASON " " << strerror(errno) << std::endl;
402 // #endif // ifndef REASON
403 
404 #include <vector> // std::vector
405 #include <functional> // std::less, std::binary_function<>
406 // namespace of ibis contains most of the useful classes of the implementation
407 namespace ibis { // forward definition of all the classes in IBIS
410  class part;
411  class query;
412  class qExpr;
413 
415  template<class T> class array_t;
417  typedef FASTBIT_CXX_DLLSPEC std::vector< part* > partList;
419  typedef FASTBIT_CXX_DLLSPEC std::vector< const part* > constPartList;
420 
422  union FASTBIT_CXX_DLLSPEC rid_t {
423  uint64_t value;
424  struct name {
426  uint32_t run;
427  uint32_t event;
428  } num;
429 
430  // (num.run < r.num.run) |
431  // (num.run == r.num.run && num.event < r.num.event))
432  bool operator<(const rid_t& r) const {return(value < r.value);}
433  bool operator>(const rid_t& r) const {return(value > r.value);}
434  bool operator<=(const rid_t& r) const {return(value <= r.value);}
435  bool operator>=(const rid_t& r) const {return(value >= r.value);}
436  bool operator==(const rid_t& r) const {return(value == r.value);}
437  bool operator!=(const rid_t& r) const {return(value != r.value);}
438  rid_t operator+(const rid_t& r) const {
439  rid_t tmp; tmp.value = value + r.value; return tmp;}
440  rid_t operator-(const rid_t& r) const {
441  rid_t tmp; tmp.value = value - r.value; return tmp;}
442  rid_t operator*(const rid_t& r) const {
443  rid_t tmp; tmp.value = value * r.value; return tmp;}
444  rid_t operator/(const rid_t& r) const {
445  rid_t tmp; tmp.value = value / r.value; return tmp;}
446  }; // rid_t
447 
449  class FASTBIT_CXX_DLLSPEC opaque {
450  public:
452  const char* address() const {return buf_;}
454  uint64_t size() const {return len_;}
455  int copy(const void* ptr, uint64_t len);
464  void assign(void* ptr, uint64_t len) {
465  delete [] buf_;
466  buf_ = static_cast<char*>(ptr);
467  len_ = len;
468  }
470  void assign(opaque &rhs) {
471  delete [] buf_;
472  buf_ = rhs.buf_;
473  len_ = rhs.len_;
474  rhs.buf_ = 0;
475  rhs.len_ = 0;
476  }
477 
479  void swap(opaque& rhs) {
480  char* ptr = buf_;
481  buf_ = rhs.buf_;
482  rhs.buf_ = ptr;
483  uint64_t len = len_;
484  len_ = rhs.len_;
485  rhs.len_ = len;
486  }
487 
489  ~opaque() {delete [] buf_;}
491  opaque() : buf_(0), len_(0) {};
494  opaque(void* ptr, uint64_t len)
495  : buf_(static_cast<char*>(ptr)), len_(len) {}
496 
498  opaque(const opaque &rhs) : buf_(0), len_(0) {
499  copy(rhs.buf_, rhs.len_);
500  }
502  opaque& operator=(const opaque &rhs) {
503  copy(rhs.buf_, rhs.len_);
504  return *this;
505  }
506 
507  protected:
508  char* buf_;
509  uint64_t len_;
510  }; // opaque
511 
514  struct lessi :
515  public std::binary_function< const char*, const char*, bool > {
516  bool operator()(const char* x, const char* y) const {
517  return (x && y ? stricmp(x, y) < 0 : false);
518  }
519  }; // lessi
520 
523  extern FASTBIT_CXX_DLLSPEC int gVerbose;
524 } // namespace ibis
525 #endif // C++ portion
526 #endif // ifndef IBIS_CONST_H
int(* FastBitReadExtArray)(void *context, uint64_t nd, uint64_t *starts, uint64_t *counts, void *data)
A function prototype for reading a portion of an external array.
Definition: const.h:365
The current implementation of FastBit is code named IBIS; most data structures and functions are in t...
Definition: bord.h:16
int copy(const char *to, const char *from)
Copy file named "from" to a file named "to".
Definition: util.cpp:894
int(* FastBitReadBitmaps)(void *context, uint64_t start, uint64_t count, uint32_t *data)
A function prototype for delayed index reconstruction.
Definition: const.h:341
Definition: const.h:299

Make It A Bit Faster
Contact us
Disclaimers
FastBit source code
FastBit mailing list archive