25 #if !defined(unix) && defined(_WIN32) 
   30 #  include <sys/stat.h>    
   32    int truncate(
const char*, uint32_t);
 
   37 #if defined(HAVE_FLOCK) 
   38 #  include <sys/file.h>    
   40 #if defined(HAVE_ATOMIC_TEMPLATE) 
   45 #ifndef FASTBIT_MIN_MAP_SIZE 
   46 #define FASTBIT_MIN_MAP_SIZE 1048576 
   49 #if ! (defined(HAVE_MMAP) || defined(_MSC_VER)) 
   50 #  if defined(unix)||defined(__linux__)||defined(__APPLE__)||defined(__CYGWIN__) 
   52 #  elif defined(__MINGW32__) 
   54 #  elif defined(_XOPEN_SOURCE) 
   55 #    define HAVE_MMAP _XOPEN_SOURCE - 0 >= 500 
   56 #  elif defined(_POSIX_C_SOURCE) 
   57 #    define HAVE_MMAP _POSIX_C_SOURCE - 0 >= 0 
   63 #if (HAVE_MMAP+0>0) || (defined(_WIN32) && defined(_MSC_VER)) 
   64 #define HAVE_FILE_MAP 1 
   68 #define DBL_EPSILON 2.2204460492503131e-16 
   72 #define DBL_EPSILON 2.2204460492503131e-16 
   75 #ifndef FASTBIT_FLOAT_NULL 
   76 #define FASTBIT_FLOAT_NULL std::numeric_limits<float>::quiet_NaN() 
   78 #ifndef FASTBIT_DOUBLE_NULL 
   79 #define FASTBIT_DOUBLE_NULL std::numeric_limits<double>::quiet_NaN() 
   83 #if !defined(HAVE_GCC_ATOMIC32) && defined(WITHOUT_FASTBIT_CONFIG_H) 
   84 #if __GNUC__+0 >= 4 && defined(__linux__) 
   85 #define HAVE_GCC_ATOMIC32 2 
   88 #if !defined(HAVE_GCC_ATOMIC64) && defined(WITHOUT_FASTBIT_CONFIG_H) 
   89 #if defined(__IA64__) || defined(__x86_64__) || defined(__ppc64__) 
   90 #if __GNUC__+0 >= 4 && defined(__linux__) 
   91 #define HAVE_GCC_ATOMIC64 2 
   97 #if defined(_MSC_VER) && defined(_WIN32) 
   98 #ifndef HAVE_WIN_ATOMIC32 
   99 #if defined(NTDDI_VERSION) && defined(NTDDI_WIN2K) 
  100 #if NTDDI_VERSION >= NTDDI_WIN2K 
  101 #define HAVE_WIN_ATOMIC32 
  103 #elif defined(WINVER) 
  105 #define HAVE_WIN_ATOMIC32 
  109 #ifndef HAVE_WIN_ATOMIC64 
  110 #if defined(NTDDI_VERSION) && defined(NTDDI_WINVISTA) 
  111 #if NTDDI_VERSION >= NTDDI_WINVISTA 
  112 #define HAVE_WIN_ATOMIC64 
  114 #elif defined(WINVER) 
  116 #define HAVE_WIN_ATOMIC64 
  123 #if defined(_MSC_VER) && defined(_WIN32) 
  124 #define UnixOpen  ::_open 
  125 #define UnixClose ::_close 
  126 #define UnixRead  ::_read 
  127 #define UnixWrite ::_write 
  128 #define UnixSeek  ::_lseek 
  129 #define UnixFlush  ::_commit 
  130 #define UnixSnprintf ::_snprintf 
  131 #define UnixStat  ::_stat 
  132 #define UnixFStat ::_fstat 
  133 #define Stat_T    struct _stat 
  134 #else //_BSD_SOURCE || _ISOC99_SOURCE || _XOPEN_SOURCE >= 500 || _POSIX_C_SOURCE >= 200112L 
  135 #define UnixOpen  ::open 
  136 #define UnixClose ::close 
  137 #define UnixRead  ::read 
  138 #define UnixWrite ::write 
  139 #define UnixSeek  ::lseek 
  140 #define UnixFlush ::fsync 
  141 #define UnixSnprintf ::snprintf 
  142 #define UnixStat  ::stat 
  143 #define UnixFStat ::fstat 
  144 #define Stat_T    struct stat 
  148 #if defined(O_RDONLY) 
  149 #if defined(O_LARGEFILE) 
  150 #if defined(O_BINARY) 
  151 #define OPEN_READONLY O_RDONLY | O_BINARY | O_LARGEFILE 
  153 #define OPEN_READONLY O_RDONLY | O_LARGEFILE 
  155 #elif defined(O_BINARY) 
  156 #define OPEN_READONLY O_RDONLY | O_BINARY 
  158 #define OPEN_READONLY O_RDONLY 
  160 #elif defined(_O_RDONLY) 
  161 #if defined(_O_LARGEFILE) 
  162 #define OPEN_READONLY _O_RDONLY | _O_LARGEFILE | _O_BINARY 
  164 #define OPEN_READONLY _O_RDONLY | _O_BINARY 
  168 #if defined(O_WRONLY) 
  169 #if defined(O_LARGEFILE) 
  170 #if defined(O_BINARY) 
  171 #define OPEN_WRITENEW O_WRONLY | O_BINARY | O_CREAT | O_TRUNC | O_LARGEFILE 
  173 #define OPEN_WRITENEW O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE 
  175 #elif defined(O_BINARY) 
  176 #define OPEN_WRITENEW O_WRONLY | O_BINARY | O_CREAT | O_TRUNC 
  178 #define OPEN_WRITENEW O_WRONLY | O_CREAT | O_TRUNC 
  180 #elif defined(_O_WRONLY) 
  181 #if defined(_O_LARGEFILE) 
  182 #define OPEN_WRITENEW _O_WRONLY|_O_CREAT|_O_TRUNC|_O_LARGEFILE|_O_BINARY 
  184 #define OPEN_WRITENEW _O_WRONLY|_O_CREAT|_O_TRUNC|_O_BINARY 
  188 #if defined(O_WRONLY) 
  189 #if defined(O_LARGEFILE) 
  190 #if defined(O_BINARY) 
  191 #define OPEN_WRITEADD O_WRONLY | O_BINARY | O_CREAT | O_LARGEFILE 
  193 #define OPEN_WRITEADD O_WRONLY | O_CREAT| O_LARGEFILE 
  195 #elif defined(O_BINARY) 
  196 #define OPEN_WRITEADD O_WRONLY | O_BINARY | O_CREAT 
  198 #define OPEN_WRITEADD O_WRONLY | O_CREAT 
  200 #elif defined(_O_WRONLY) 
  201 #if defined(_O_LARGEFILE) 
  202 #define OPEN_WRITEADD _O_WRONLY | _O_CREAT | _O_LARGEFILE | _O_BINARY 
  204 #define OPEN_WRITEADD _O_WRONLY | _O_CREAT | _O_BINARY 
  209 #if defined(O_LARGEFILE) 
  210 #if defined(O_BINARY) 
  211 #define OPEN_READWRITE O_RDWR | O_BINARY | O_CREAT | O_LARGEFILE 
  213 #define OPEN_READWRITE O_RDWR | O_CREAT | O_LARGEFILE 
  215 #elif defined(O_BINARY) 
  216 #define OPEN_READWRITE O_RDWR | O_BINARY | O_CREAT 
  218 #define OPEN_READWRITE O_RDWR | O_CREAT 
  220 #elif defined(_O_RDWR) 
  221 #if defined(_O_LARGEFILE) 
  222 #define OPEN_READWRITE _O_RDWR | _O_CREAT | _O_LARGEFILE | _O_BINARY 
  224 #define OPEN_READWRITE _O_RDWR | _O_CREAT | _O_BINARY 
  228 #if defined(O_WRONLY) 
  229 #if defined(O_LARGEFILE) 
  230 #if defined(O_BINARY) 
  231 #define OPEN_APPENDONLY O_WRONLY | O_BINARY | O_CREAT | O_APPEND | O_LARGEFILE 
  233 #define OPEN_APPENDONLY O_WRONLY | O_CREAT | O_APPEND | O_LARGEFILE 
  235 #elif defined(O_BINARY) 
  236 #define OPEN_APPENDONLY O_WRONLY | O_BINARY | O_CREAT | O_APPEND 
  238 #define OPEN_APPENDONLY O_WRONLY | O_CREAT | O_APPEND 
  240 #elif defined(_O_WRONLY) 
  241 #if defined(_O_LARGEFILE) 
  242 #define OPEN_APPENDONLY _O_WRONLY | _O_CREAT | _O_APPEND | _O_LARGEFILE | _O_BINARY 
  244 #define OPEN_APPENDONLY _O_WRONLY | _O_CREAT | _O_APPEND | _O_BINARY 
  248 #if defined(_MSC_VER) && defined(_WIN32) 
  249 #define OPEN_FILEMODE _S_IREAD | _S_IWRITE 
  250 #elif defined(S_IRGRP) && defined(S_IWGRP) && defined(S_IROTH) 
  251 #define OPEN_FILEMODE S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH 
  253 #define OPEN_FILEMODE S_IRUSR | S_IWUSR 
  256 #if defined(_MSC_VER) 
  258 #define FORCE_INLINE    __forceinline 
  262 #define BIG_CONSTANT(x) (x) 
  266 #else   // defined(_MSC_VER) 
  268 #define FORCE_INLINE inline __attribute__((always_inline)) 
  270 inline uint32_t _rotl32( uint32_t x, int8_t r ) {
 
  271     return (x << r) | (x >> (32 - r));
 
  274 inline uint64_t _rotl64( uint64_t x, int8_t r ) {
 
  275     return (x << r) | (x >> (64 - r));
 
  278 #define BIG_CONSTANT(x) (x##LLU) 
  279 #endif // !defined(_MSC_VER) 
  280 #define FASTBIT_ROTL32(x,y)     _rotl32(x,y) 
  281 #define FASTBIT_ROTL64(x,y)     _rotl64(x,y) 
  283 #if defined(_WIN32) && defined(_MSC_VER) 
  293 #ifndef FASTBIT_CASE_SENSITIVE_COMPARE 
  297 #define FASTBIT_CASE_SENSITIVE_COMPARE 1 
  301 #define STRMATCH_META_CSH_ANY '*' 
  302 #define STRMATCH_META_CSH_ONE '?' 
  303 #define STRMATCH_META_SQL_ANY '%' 
  304 #define STRMATCH_META_SQL_ONE '_' 
  305 #define STRMATCH_META_ESCAPE '\\' 
  315 #define IBIS_2STR(x) #x 
  316 #define IBIS_INT_STR(x) IBIS_2STR(x) 
  317 #define IBIS_FILE_LINE " -- " __FILE__ ":" IBIS_INT_STR(__LINE__) 
  320     if (false == (v)) ; else ibis::util::logger(0)()  
  323 #define IBIS_JOIN_MACRO2(X, Y) X##Y 
  324 #define IBIS_JOIN_MACRO(X, Y) IBIS_JOIN_MACRO2(X, Y) 
  326 #define IBIS_GUARD_NAME IBIS_JOIN_MACRO(_guard, __LINE__) __attribute__( ( unused ) ) 
  328 #define IBIS_GUARD_NAME IBIS_JOIN_MACRO(_guard, __LINE__) 
  330 #define IBIS_BLOCK_GUARD                                        \ 
  331     ibis::util::guard IBIS_GUARD_NAME = ibis::util::makeGuard 
  335     template <> 
struct less< char* > {
 
  336         bool operator()(
const char*x, 
const char*y)
 const {
 
  337             return std::strcmp(x, y) < 0;
 
  342     template <> 
struct less< const char* > {
 
  343         bool operator()(
const char* x, 
const char* y)
 const {
 
  344             return std::strcmp(x, y) < 0;
 
  349     template <> 
struct equal_to< const char* > {
 
  350         bool operator()(
const char* x, 
const char* y)
 const {
 
  351             return std::strcmp(x, y) == 0;
 
  355     template <> 
struct less< 
ibis::rid_t > {
 
  356         bool operator()(
const ibis::rid_t& x, 
const ibis::rid_t& y)
 const {
 
  361     template <> 
struct less< const 
ibis::rid_t* > {
 
  362         bool operator()(
const ibis::rid_t* x, 
const ibis::rid_t* y)
 const {
 
  390     extern FASTBIT_CXX_DLLSPEC partList 
datasets;
 
  392     typedef std::vector<colValues*> colList; 
 
  402         nameList(
const char* str) : cstr(0), buff(0) {select(str);}
 
  405         bool empty()
 const {
return cstr == 0;}
 
  406         const char* operator*()
 const {
return cstr;};
 
  407         uint32_t size()
 const {
return cvec.size();};
 
  410         void select(
const char* str);
 
  412         void add(
const char* str);
 
  416         uint32_t 
find(
const char* key) 
const;
 
  418         const char* operator[](uint32_t i)
 const {
return cvec[i];}
 
  419         typedef std::vector< const char* >::const_iterator const_iterator;
 
  420         const_iterator begin()
 const {
return cvec.begin();}
 
  421         const_iterator end()
 const {
return cvec.end();}
 
  424         {cvec.clear(); 
delete [] cstr; 
delete [] buff; buff=0; cstr=0;}
 
  427         typedef std::vector< const char * > compStore;
 
  438     typedef std::map< const char*, part*, lessi > 
partAssoc;
 
  446         bad_alloc(
const char *m=
"unknown") throw() : mesg_(m) {};
 
  448         virtual const char* what() 
const throw() {
return mesg_;}
 
  472         extern FASTBIT_CXX_DLLSPEC pthread_mutex_t 
envLock;
 
  475         inline char* 
trim(
char* str);
 
  479         char* 
strnewdup(
const char* s, 
const uint32_t n);
 
  483         const char* 
getToken(
char*& str, 
const char* tok_chrs);
 
  484         int readInt(int64_t& val, 
const char *&str,
 
  486         int readUInt(uint64_t& val, 
const char *&str,
 
  490         FASTBIT_CXX_DLLSPEC 
int 
  491         readString(std::string& str, 
const char*& buf,
 
  492                    const char *delim=0);
 
  493         FASTBIT_CXX_DLLSPEC 
const char*
 
  496         int64_t 
read(
int, 
void*, int64_t);
 
  497         int64_t 
write(
int, 
const void*, int64_t);
 
  499         void removeDir(
const char* name, 
bool leaveDir=
false);
 
  501         FASTBIT_CXX_DLLSPEC off_t 
getFileSize(
const char* name);
 
  502         int copy(
const char* to, 
const char* from);
 
  509         FASTBIT_CXX_DLLSPEC 
const char* 
userName();
 
  512                              long unsigned &denominator,
 
  513                              long unsigned &numerator);
 
  514         inline double rand();
 
  517         FASTBIT_CXX_DLLSPEC uint32_t 
checksum(
const char* str, uint32_t sz);
 
  518         inline uint32_t 
checksum(uint32_t a, uint32_t b);
 
  519         std::string 
shortName(
const std::string& longname);
 
  520         std::string 
randName(
const std::string& longname);
 
  524         void int2string(std::string &str, 
unsigned val);
 
  525         void int2string(std::string &str, 
unsigned v1, 
unsigned v2);
 
  526         void int2string(std::string &str, 
unsigned v1,
 
  527                         unsigned v2, 
unsigned v3);
 
  528         void int2string(std::string &str, 
const std::vector<unsigned>& val);
 
  529         void encode64(uint64_t, std::string&);
 
  530         int  decode64(uint64_t&, 
const std::string&);
 
  531         int  decode16(uint64_t&, 
const char*);
 
  539         void   eq2range(
const double&, 
double&, 
double&);
 
  542         inline double coarsen(
const double in, 
unsigned prec=2);
 
  560         template <
typename Tin, 
typename Tout>
 
  562             outval = (std::numeric_limits<Tout>::min() > inval ?
 
  563                       std::numeric_limits<Tout>::min() :
 
  564                       (double)std::numeric_limits<Tout>::max() <= inval ?
 
  565                       std::numeric_limits<Tout>::max() :
 
  566                       static_cast<Tout
>(inval));
 
  571         template <
typename Tin, 
typename Tout>
 
  573             outval = (std::numeric_limits<Tout>::min() >= inval ?
 
  574                       std::numeric_limits<Tout>::min() :
 
  575                       (double) std::numeric_limits<Tout>::max() < inval ?
 
  576                       std::numeric_limits<Tout>::max() :
 
  577                       static_cast<Tout
>(inval) +
 
  578                       ((inval-static_cast<Tin>(static_cast<Tout>(inval))) > 0));
 
  581         template <
typename Tin>
 
  582         void round_up(
const Tin& inval, 
float&);
 
  584         template <
typename Tin>
 
  586             outval = 
static_cast<double>(inval);
 
  592             return (xx = x >> 16)
 
  593                 ? (xxx = xx >> 8) ? 24 + log2table[xxx] : 16 + log2table[xx]
 
  594                 : (xxx = x >> 8) ? 8 + log2table[xxx] : log2table[x];
 
  599             return (xx = x >> 32)
 
  601                 : 
log2(static_cast<uint32_t>(x));
 
  605         FASTBIT_CXX_DLLSPEC 
void 
  606         logMessage(
const char* event, 
const char* fmt, ...);
 
  613         FASTBIT_CXX_DLLSPEC 
bool strMatch(
const char* str, 
const char* pat);
 
  614         FASTBIT_CXX_DLLSPEC 
bool nameMatch(
const char* str, 
const char* pat);
 
  627         long intersect(
const std::vector<ibis::bitvector> &bits1,
 
  628                        const std::vector<ibis::bitvector> &bits2,
 
  629                        std::vector<ibis::bitvector> &res);
 
  631         long intersect(
const std::vector<ibis::bitvector> &bits1,
 
  632                        const std::vector<ibis::bitvector> &bits2,
 
  633                        const std::vector<ibis::bitvector> &bits3,
 
  634                        std::vector<ibis::bitvector> &res);
 
  636         void clear(ibis::partList &pl) 
throw();
 
  643             return FASTBIT_STRING;
 
  652 #ifdef FASTBIT_IBIS_INT_VERSION 
  653             return FASTBIT_IBIS_INT_VERSION;
 
  666 #if defined(WIN32) && ! defined(__CYGWIN__) 
  667         char* getpass_r(
const char *prompt, 
char *buffer, uint32_t buflen);
 
  668         char* getpass(
const char* prompt);
 
  670         inline char *itoa(
int value, 
char *str, 
int ) {
 
  671             sprintf(str,
"%d",value);
 
  677         template <
typename T> 
inline void 
  679             const size_t nv = v.size();
 
  680             for (
size_t j = 0; j < nv; ++j)
 
  701             std::string str() 
const;
 
  702             const char* c_str() 
const;
 
  718 #if defined(PTW32_STATIC_LIB) 
  719                 if (mutex == PTHREAD_MUTEX_INITIALIZER) {
 
  720                     int ierr = pthread_mutex_init(&mutex, 0);
 
  722                         throw "ioLock failed to initialize the necessary mutex";
 
  725                 if (0 != pthread_mutex_lock(&mutex))
 
  726                     throw "ioLock failed to obtain a lock";
 
  729                 (void) pthread_mutex_unlock(&mutex);
 
  733             static pthread_mutex_t mutex;
 
  742             mutexLock(pthread_mutex_t* lk, 
const char* m)
 
  743                 : mesg(m), lock(lk) {
 
  744                 LOGGER(ibis::gVerbose > 10)
 
  745                     << 
"util::mutexLock -- acquiring lock (" << lock
 
  747                 if (0 != pthread_mutex_lock(lock)) {
 
  748                     throw "mutexLock failed to obtain a lock";
 
  752                 LOGGER(ibis::gVerbose > 10)
 
  753                     << 
"util::mutexLock -- releasing lock (" << lock
 
  755                 (void) pthread_mutex_unlock(lock);
 
  760             pthread_mutex_t *lock;
 
  774                 if (0 != pthread_mutex_lock(lock))
 
  775                     throw "quietLock failed to obtain a mutex lock";
 
  779                 (void) pthread_mutex_unlock(lock);
 
  784             pthread_mutex_t *lock;
 
  797                 : lock_(lk), locked_(pthread_mutex_trylock(lock_)) {}
 
  803                 (void) pthread_mutex_unlock(lock_);
 
  808             pthread_mutex_t *lock_;
 
  821                 : mesg(m), lock(lk) {
 
  822                 if (0 != pthread_rwlock_rdlock(lock)) {
 
  823                     throw "readLock failed to obtain a lock";
 
  827                 (void) pthread_rwlock_unlock(lock);
 
  844                 : mesg(m), lock(lk) {
 
  845                 if (0 != pthread_rwlock_wrlock(lock)) {
 
  846                     throw "writeLock failed to obtain a lock";
 
  851                 (void) pthread_rwlock_unlock(lock);
 
  859             writeLock(
const writeLock&); 
 
  860             writeLock& operator=(
const writeLock&);
 
  872 #if defined(HAVE_GCC_ATOMIC32) 
  873 #elif defined(HAVE_WIN_ATOMIC32) 
  875                 (void)pthread_mutex_destroy(&lock_);
 
  879 #if defined(HAVE_GCC_ATOMIC32) 
  880 #elif defined(HAVE_WIN_ATOMIC32) 
  882                 if (0 != pthread_mutex_init(&lock_, 0))
 
  884                         (
"util::counter failed to initialize mutex lock");
 
  890 #if defined(HAVE_GCC_ATOMIC32) 
  891                 return __sync_fetch_and_add(&count_, 1);
 
  892 #elif defined(HAVE_WIN_ATOMIC32) 
  893                 return InterlockedIncrement((
volatile long *)&count_)-1;
 
  896                 uint32_t ret = count_;
 
  903 #if defined(HAVE_GCC_ATOMIC32) 
  904                 (void) __sync_fetch_and_sub(&count_, count_);
 
  905 #elif defined(HAVE_WIN_ATOMIC32) 
  906                 (void) InterlockedExchange((
volatile long *)&count_, 0);
 
  918 #if defined(HAVE_GCC_ATOMIC32) 
  919 #elif defined(HAVE_WIN_ATOMIC32) 
  921             mutable pthread_mutex_t lock_; 
 
  923             volatile uint32_t count_; 
 
  948 #if defined(HAVE_ATOMIC_TEMPLATE) 
  949 #elif defined(HAVE_GCC_ATOMIC32) 
  950 #elif defined(HAVE_WIN_ATOMIC32) 
  952                 if (pthread_mutex_init(&mytex, 0) != 0)
 
  953                     throw "pthread_mutex_init failed for sharedInt";
 
  958 #if defined(HAVE_ATOMIC_TEMPLATE) 
  959 #elif defined(HAVE_GCC_ATOMIC32) 
  960 #elif defined(HAVE_WIN_ATOMIC32) 
  962                 (void)pthread_mutex_destroy(&mytex);
 
  968 #if defined(HAVE_ATOMIC_TEMPLATE) 
  970 #elif defined(HAVE_GCC_ATOMIC32) 
  971                 return __sync_add_and_fetch(const_cast<uint32_t*>(&val_), 0);
 
  972 #elif defined(HAVE_WIN_ATOMIC32) 
  982 #if defined(HAVE_ATOMIC_TEMPLATE) 
  985 #elif defined(HAVE_GCC_ATOMIC32) 
  986                 return __sync_add_and_fetch(&val_, 1);
 
  987 #elif defined(HAVE_WIN_ATOMIC32) 
  988                 return InterlockedIncrement((
volatile long *)&val_);
 
  998 #if defined(HAVE_ATOMIC_TEMPLATE) 
 1001 #elif defined(HAVE_GCC_ATOMIC32) 
 1002                 return __sync_sub_and_fetch(&val_, 1);
 
 1003 #elif defined(HAVE_WIN_ATOMIC32) 
 1004                 return InterlockedDecrement((
volatile long *)&val_);
 
 1014 #if defined(HAVE_ATOMIC_TEMPLATE) 
 1015                 (void) val_.fetch_add(rhs);
 
 1016 #elif defined(HAVE_GCC_ATOMIC32) 
 1017                 (void) __sync_add_and_fetch(&val_, rhs);
 
 1018 #elif defined(HAVE_WIN_ATOMIC32) 
 1019                 (void) InterlockedExchangeAdd((
volatile long *)&val_, rhs);
 
 1028 #if defined(HAVE_ATOMIC_TEMPLATE) 
 1029                 (void) val_.fetch_sub(rhs);
 
 1030 #elif defined(HAVE_GCC_ATOMIC32) 
 1031                 (void) __sync_sub_and_fetch(&val_, rhs);
 
 1032 #elif defined(HAVE_WIN_ATOMIC32) 
 1033                 (void) InterlockedExchangeAdd((
volatile long *)&val_,
 
 1060 #if defined(HAVE_ATOMIC_TEMPLATE) 
 1061             std::atomic<uint32_t> val_;
 
 1063 #elif defined(HAVE_GCC_ATOMIC32) 
 1064             uint32_t 
volatile val_;
 
 1066 #elif defined(HAVE_WIN_ATOMIC32) 
 1067             uint32_t 
volatile val_;
 
 1070             uint32_t 
volatile val_;
 
 1073             pthread_mutex_t mytex;
 
 1089 #if defined(HAVE_ATOMIC_TEMPLATE) 
 1090 #elif defined(HAVE_GCC_ATOMIC64) 
 1091 #elif defined(HAVE_WIN_ATOMIC64) 
 1093                 if (pthread_mutex_init(&mytex, 0) != 0)
 
 1094                     throw "pthread_mutex_init failed for sharedInt";
 
 1099 #if defined(HAVE_ATOMIC_TEMPLATE) 
 1100 #elif defined(HAVE_GCC_ATOMIC64) 
 1101 #elif defined(HAVE_WIN_ATOMIC64) 
 1103                 (void)pthread_mutex_destroy(&mytex);
 
 1109 #if defined(HAVE_ATOMIC_TEMPLATE) 
 1111 #elif defined(HAVE_GCC_ATOMIC64) 
 1112                 return __sync_add_and_fetch(const_cast<uint64_t*>(&val_), 0);
 
 1113 #elif defined(HAVE_WIN_ATOMIC64) 
 1123 #if defined(HAVE_ATOMIC_TEMPLATE) 
 1126 #elif defined(HAVE_GCC_ATOMIC64) 
 1127                 return __sync_add_and_fetch(&val_, 1);
 
 1128 #elif defined(HAVE_WIN_ATOMIC64) 
 1129                 return InterlockedIncrement64((
volatile LONGLONG *)&val_);
 
 1139 #if defined(HAVE_ATOMIC_TEMPLATE) 
 1142 #elif defined(HAVE_GCC_ATOMIC64) 
 1143                 return __sync_sub_and_fetch(&val_, 1);
 
 1144 #elif defined(HAVE_WIN_ATOMIC64) 
 1145                 return InterlockedDecrement64((
volatile LONGLONG *)&val_);
 
 1155 #if defined(HAVE_ATOMIC_TEMPLATE) 
 1156                 (void) val_.fetch_add(rhs);
 
 1157 #elif defined(HAVE_GCC_ATOMIC64) 
 1158                 (void) __sync_add_and_fetch(&val_, rhs);
 
 1159 #elif defined(HAVE_WIN_ATOMIC64) 
 1160                 (void) InterlockedExchangeAdd64((
volatile LONGLONG *)&val_,
 
 1170 #if defined(HAVE_ATOMIC_TEMPLATE) 
 1171                 (void) val_.fetch_sub(rhs);
 
 1172 #elif defined(HAVE_GCC_ATOMIC64) 
 1173                 (void) __sync_sub_and_fetch(&val_, rhs);
 
 1174 #elif defined(HAVE_WIN_ATOMIC64) 
 1175                 (void) InterlockedExchangeAdd64((
volatile LONGLONG *)&val_,
 
 1202 #if defined(HAVE_ATOMIC_TEMPLATE) 
 1203             std::atomic<uint64_t> val_;
 
 1205 #elif defined(HAVE_GCC_ATOMIC64) 
 1206             uint64_t 
volatile val_;
 
 1208 #elif defined(HAVE_WIN_ATOMIC64) 
 1209             uint64_t 
volatile val_;
 
 1212             uint64_t 
volatile val_;
 
 1215             pthread_mutex_t mytex;
 
 1232             explicit timer(
const char* msg, 
int lvl=1);
 
 1248             operator T& () 
const {
return ref_;}
 
 1269             mutable volatile bool done_;
 
 1274             guardBase(
const guardBase& rhs) : done_(rhs.done_) {
 
 1282             template <
typename T>
 
 1288                 catch (
const std::exception& e) {
 
 1289                     LOGGER(ibis::gVerbose > 1)
 
 1290                         << 
" ... caught a std::exception (" << e.what()
 
 1291                         << 
") in util::gard";
 
 1293                 catch (
const char* s) {
 
 1294                     LOGGER(ibis::gVerbose > 1)
 
 1295                         << 
" ... caught a string exception (" << s
 
 1296                         << 
") in util::guard";
 
 1299                     LOGGER(ibis::gVerbose > 1)
 
 1300                         << 
" ... caught a unknown exception in util::guard";
 
 1323         template <
typename F>
 
 1335             void execute() {fun_();}
 
 1348         template <
typename F>
 
 1349         inline guardImpl0<F> makeGuard(F f) {
 
 1350             return guardImpl0<F>::makeGuard(f);
 
 1355         template <
typename F, 
typename A>
 
 1367             void execute() {fun_(arg_);}
 
 1382         template <
typename F, 
typename A>
 
 1383         inline guardImpl1<F, A> makeGuard(F f, A a) {
 
 1384             return guardImpl1<F, A>::makeGuard(f, a);
 
 1389         template <
typename F, 
typename A1, 
typename A2>
 
 1401             void execute() {fun_(arg1_, arg2_);}
 
 1405                 : fun_(f), arg1_(a1), arg2_(a2) {}
 
 1420         template <
typename F, 
typename A1, 
typename A2>
 
 1421         inline guardImpl2<F, A1, A2> makeGuard(F f, A1 a1, A2 a2) {
 
 1422             return guardImpl2<F, A1, A2>::makeGuard(f, a1, a2);
 
 1426         template <
class C, 
typename F>
 
 1438             void execute() {(obj_.*fun_)();}
 
 1451         template <
class C, 
typename F>
 
 1452         inline guardObj0<C, F> objectGuard(C o, F f) {
 
 1453             return guardObj0<C, F>::makeGuard(o, f);
 
 1456 #if defined(HAVE_FLOCK) 
 1464                   locked(0 == ::
flock(fd, LOCK_EX|LOCK_NB)) {
 
 1469                     (void) ::
flock(fd_, LOCK_UN);
 
 1483 #if defined(WIN32) && ! defined(__CYGWIN__) 
 1484 char* getpass(
const char* prompt);
 
 1499     static uint32_t seed = 1;
 
 1500     static const uint32_t alpha = 69069;
 
 1501     static const double scale = ::pow(0.5, 32);
 
 1502     seed = 
static_cast<uint32_t
>(seed * alpha);
 
 1503     return(scale * seed);
 
 1508     uint32_t a0 = (a >> 16);
 
 1509     uint32_t a1 = (a & 0xFFFF);
 
 1510     uint32_t b0 = (b >> 16);
 
 1511     uint32_t b1 = (b & 0xFFFF);
 
 1512     return ((((a0<<2)+a1*3+(b0<<1)+b1) << 16) | ((a0+a1+b0+b1) & 0xFFFF));
 
 1523 #if defined(HAVE_NEXTAFTER) 
 1524     return nextafter(in, DBL_MAX);
 
 1525 #elif defined(_MSC_VER) && defined(_WIN32) 
 1526     return _nextafter(in, DBL_MAX);
 
 1528     double tmp = fabs(in) * DBL_EPSILON;
 
 1529     if (tmp > 0.0) tmp += in;
 
 1530     else tmp = in + DBL_MIN;
 
 1538 #if defined(HAVE_NEXTAFTER) 
 1539     return nextafter(in, -DBL_MAX);
 
 1540 #elif defined(_MSC_VER) && defined(_WIN32) 
 1541     return _nextafter(in, -DBL_MAX);
 
 1543     double tmp = fabs(in) * DBL_EPSILON;
 
 1544     if (tmp > 0.0) tmp = in - tmp;
 
 1545     else tmp = in - DBL_MIN;
 
 1555                                  double& left, 
double& right) {
 
 1556 #if defined(HAVE_NEXTAFTER) 
 1557     right = nextafter(in, DBL_MAX);
 
 1558 #elif defined(_MSC_VER) && defined(_WIN32) 
 1559     right = _nextafter(in, DBL_MAX);
 
 1561     double tmp = fabs(in) * DBL_EPSILON;
 
 1562     if (tmp > 0.0) {right = in + tmp;}
 
 1563     else {right = in + DBL_MIN;}
 
 1571 template <
typename Tin>
 
 1574     outval = 
static_cast<float>(inval);
 
 1575     if (static_cast<Tin>(outval) < inval) {
 
 1578 #if defined(HAVE_NEXTAFTER) 
 1579         outval = nextafterf(static_cast<float>(inval), FLT_MAX);
 
 1581         float tmp = fabsf(outval) * FLT_EPSILON;
 
 1582         if (tmp > 0.0) outval += tmp;
 
 1583         else outval += FLT_MIN;
 
 1590     if (str != 0 && *str != 0) {
 
 1592         while (*tmp != 0) ++ tmp;
 
 1594         while (tmp > str && *tmp == tail) {
 
 1595             *tmp = 
static_cast<char>(0);
 
 1604     if (str == 0) 
return head;
 
 1605     if (*str == 0) 
return head;
 
 1609         if (std::isspace(*head))
 
 1617     for (str = head; *str != 0; ++ str);
 
 1619     while (str >= head && std::isspace(*str)) {
 
 1620         *str = 
static_cast<char>(0);
 
 1638     else if (in == 0.0) {
 
 1643         if (ret < DBL_MIN) { 
 
 1646         else if (ret < DBL_MAX) { 
 
 1650             const int ixp = 
static_cast<int>(floor(ret)) -
 
 1651                 static_cast<int>(prec);
 
 1652             ret = floor(0.5 + pow(1e1, ret-ixp));
 
 1654                 ret *= pow(1e1, ixp);
 
 1656                 ret /= pow(1e1, -ixp);
 
 1668 inline std::ostream& 
operator<<(std::ostream& out, 
const ibis::rid_t& rid) {
 
 1669     out << 
'(' << rid.num.run << 
", " << rid.num.event << 
')';
 
 1674 inline std::istream& 
operator>>(std::istream& is, ibis::rid_t& rid) {
 
 1678         is >> rid.num.run >> c;
 
 1680             is >> rid.num.event >> c;
 
 1684             is.clear(std::ios::badbit); 
 
 1688         is >> rid.num.run >> c;
 
 1691         is >> rid.num.event;
 
 1695 #endif // IBIS_UTIL_H 
void round_up(const Tin &inval, Tout &outval)
Round the incoming value to the smallest output value that is no less than the input. 
Definition: util.h:572
 
const char * charTable
charTable lists the 64 printable characters to be used for names 
Definition: util.cpp:56
 
const ibis::bitvector64 & outerProduct(const ibis::bitvector &a, const ibis::bitvector &b, ibis::bitvector64 &c)
Compute the outer product of a and b, add the result to c. 
Definition: bitvector64.cpp:3761
 
uint32_t checksum(const char *str, uint32_t sz)
Fletcher's arithmetic checksum with 32-bit result. 
Definition: util.cpp:1486
 
int64_t write(int, const void *, int64_t)
A wrapper over POSIX write function. 
Definition: util.cpp:999
 
void updateDatasets(void)
Update the metadata about the data partitions. 
Definition: part.cpp:20879
 
void emptyCache(void)
Attempt to remove all currently unused data from memory cache. 
Definition: part.cpp:20890
 
guardObj0(C &o, F f)
Constructor. 
Definition: util.h:1441
 
double decrDouble(const double &)
Decrease the input value to the next smaller value. 
Definition: util.h:1537
 
void int2string(std::string &str, unsigned val)
Pack a 32-bit integer into six base-64 alphabets. 
Definition: util.cpp:1572
 
A simple wrapper on flock. 
Definition: util.h:1458
 
std::map< const char *, part *, lessi > partAssoc
An associative array for data partitions. 
Definition: util.h:438
 
std::string shortName(const std::string &longname)
Use the Fletcher's checksum to produce a short string. 
Definition: util.cpp:1587
 
A concrete class for cleanup jobs that take a function without any argument. 
Definition: util.h:1324
 
void removeTail(char *str, char tail)
Remove trailing character 'tail' from str. 
Definition: util.h:1589
 
char * strnewdup(const char *s)
Duplicate string content with C++ default new operator. 
Definition: util.cpp:1420
 
int getVersionNumber()
Return an integer designating the version of this software. 
Definition: util.h:651
 
An wrapper class for perform pthread_mutex_trylock/unlock. 
Definition: util.h:793
 
void setVerboseLevel(int v)
Set the verboseness level. 
Definition: util.h:507
 
A unsigned 64-bit shared integer class. 
Definition: util.h:1086
 
void operator+=(const uint32_t rhs)
In-place addition operator. 
Definition: util.h:1013
 
int log2(uint32_t x)
Log_2 of a 32-bit integer. 
Definition: util.h:590
 
An wrapper class for perform pthread_rwlock_rdlock/unlock. 
Definition: util.h:818
 
A container for name-value pairs. 
Definition: resource.h:38
 
guardImpl2(F f, A1 a1, A2 a2)
Construct a guard object from a function. 
Definition: util.h:1404
 
int readUInt(uint64_t &val, const char *&str, const char *del=ibis::util::delimiters)
Attempt to convert the incoming string into a unsigned integer. 
Definition: util.cpp:687
 
guardImpl1(F f, A a)
Construct a guard object from a function. 
Definition: util.h:1370
 
uint64_t operator++()
Increment operator. 
Definition: util.h:1122
 
An wrapper class for perform pthread_mutex_lock/unlock. 
Definition: util.h:770
 
long intersect(const std::vector< ibis::bitvector > &bits1, const std::vector< ibis::bitvector > &bits2, std::vector< ibis::bitvector > &res)
Intersect two sets of bit vectors. 
Definition: bitvector.cpp:4595
 
A template to hold a reference to an object. 
Definition: util.h:1245
 
void clear(ibis::partList &pl)
Deallocate the list of data partitions. 
Definition: part.cpp:20869
 
void getLocalTime(char *str)
Return the current time in string format as asctime_r. 
Definition: util.cpp:2550
 
size_t find(const std::vector< T > &, const T &, size_t)
Find the first position where the value is no less than val. 
Definition: utilidor.cpp:3795
 
partList datasets
!< Select clause. 
Definition: util.cpp:83
 
~softLock()
Destructor. 
Definition: util.h:802
 
double coarsen(const double in, unsigned prec=2)
Reduce the decimal precision of the incoming floating-point value to specified precision. 
Definition: util.h:1633
 
uint32_t serialNumber()
Compute a serial number. 
Definition: util.cpp:1413
 
pthread_mutex_t envLock
A mutex for serialize operations FastBit wide. 
Definition: util.cpp:49
 
void dismiss() const 
Tell the guard that it does not need to invoke clean up function any more. 
Definition: util.h:1266
 
static void cleanup(T &task)
A template to invoke the function registered. 
Definition: util.h:1283
 
uint32_t operator()()
Return the current count and increment the count. 
Definition: util.h:889
 
void secondsToString(const time_t, char *str)
Converts the given time in seconds (as returned by function time) into the string (as from asctime_r)...
Definition: util.cpp:2528
 
void closeLogFile()
Close the log file. 
Definition: util.cpp:2120
 
char * trim(char *str)
Remove leading and trailing blank space. 
Definition: util.h:1602
 
std::string groupby1000(uint64_t)
Produce a string version of the unsigned integer value with the decimal digits grouped into 1000s...
Definition: util.cpp:1640
 
The current implementation of FastBit is code named IBIS; most data structures and functions are in t...
Definition: bord.h:16
 
void operator-=(const uint64_t rhs)
In-place subtraction operator. 
Definition: util.h:1169
 
const short unsigned charIndex[]
charIndex maps the characters (ASCII) back to integer [0-64] 
Definition: util.cpp:60
 
void clearVec(std::vector< T * > &v)
A template to clean up a vector of pointers. 
Definition: util.h:678
 
uint32_t value() const 
Return the current count value. 
Definition: util.h:913
 
A data structure to represent a sequence of bits. 
Definition: bitvector64.h:54
 
bool strMatch(const char *str, const char *pat)
Match the string str against a simple pattern pat. 
Definition: util.cpp:2244
 
~guardObj0()
Desutructor. 
Definition: util.h:1434
 
Horometer – a primitive timing instrument. 
Definition: horometer.h:62
 
~guardBase()
Destructor. No need to be virtual. 
Definition: util.h:1272
 
off_t getFileSize(const char *name)
Return size of the file in bytes. 
Definition: util.cpp:875
 
refHolder< T > ref(T &r)
A function template to produce refHolder. 
Definition: util.h:1258
 
std::string randName(const std::string &longname)
Generate a short string to be used as a table/partition name. 
Definition: util.cpp:1613
 
void getGMTime(char *str)
Return the current GMT time in string format. 
Definition: util.cpp:2570
 
ibis::resource & gParameters()
List of in-memory data. 
Definition: resource.cpp:545
 
~guardImpl2()
Destructor calls the cleanup function of the base class. 
Definition: util.h:1397
 
uint32_t operator()() const 
Read the current value. 
Definition: util.h:967
 
char * getString(const char *buf)
Extract a string from the given buf. 
Definition: util.cpp:166
 
uint32_t operator++()
Increment operator. 
Definition: util.h:981
 
softLock(pthread_mutex_t *lk)
Constructor. 
Definition: util.h:796
 
void setNaN(double &val)
Set a double to NaN. 
Definition: util.cpp:1404
 
quietLock(pthread_mutex_t *lk)
Constructor. 
Definition: util.h:773
 
void operator+=(const uint64_t rhs)
In-place addition operator. 
Definition: util.h:1154
 
int writeLogFileHeader(FILE *fptr, const char *fname)
Write a header to the log file. 
Definition: util.cpp:1993
 
int copy(const char *to, const char *from)
Copy file named "from" to a file named "to". 
Definition: util.cpp:894
 
int readInt(int64_t &val, const char *&str, const char *del=ibis::util::delimiters)
Attempt to convert the incoming string into an integer. 
Definition: util.cpp:619
 
const guardBase & guard
The type to be used by client code. 
Definition: util.h:1319
 
~flock()
Destructor. 
Definition: util.h:1467
 
bool isLocked() const 
Has a mutex lock being acquired? Returns true if yes, otherwise false. 
Definition: util.h:800
 
~timer()
Destructor. 
Definition: util.cpp:2215
 
void logMessage(const char *event, const char *fmt,...)
Print a message to standard output. 
Definition: util.cpp:1902
 
std::istream & operator>>(std::istream &is, ibis::rid_t &rid)
Read a rid_t from an input stream. 
Definition: util.h:1674
 
~quietLock()
Destructor. 
Definition: util.h:778
 
A concrete class for cleanup jobs that take a function with two arguments. 
Definition: util.h:1390
 
guardImpl0(F f)
Construct a guard object from a function. 
Definition: util.h:1338
 
const char * getLogFileName()
Return name the of the current log file. 
Definition: util.cpp:2111
 
const int log2table[256]
log base 2 of an integer, the lookup table 
Definition: util.cpp:74
 
void operator-=(const uint32_t rhs)
In-place subtraction operator. 
Definition: util.h:1027
 
double compactValue2(double left, double right, double start=0.0)
Compute a compact 64-bit floating-point value with a short binary representation. ...
Definition: util.cpp:1320
 
const char * userName()
Return the user name. 
Definition: util.cpp:1815
 
void round_down(const Tin &inval, Tout &outval)
Round the incoming value to the largest output value that is no more than the input. 
Definition: util.h:561
 
std::ostringstream mybuffer
The message is stored in this buffer. 
Definition: util.h:706
 
A simple shared counter. 
Definition: util.h:869
 
uint64_t operator--()
Decrement operator. 
Definition: util.h:1138
 
A global I/O lock. 
Definition: util.h:715
 
uint64_t operator()() const 
Read the current value. 
Definition: util.h:1108
 
double incrDouble(const double &)
Functions to handle manipulation of floating-point numbers. 
Definition: util.h:1522
 
const ibis::bitvector64 & outerProductUpper(const ibis::bitvector &a, const ibis::bitvector &b, ibis::bitvector64 &c)
Add the strict upper triangular portion of the outer production between a and b to c...
Definition: bitvector64.cpp:3858
 
A data structure to store a small set of names. 
Definition: util.h:399
 
void encode64(uint64_t, std::string &)
Turn the incoming integer into a 64-bit representation. 
Definition: util.cpp:1679
 
double rand()
A very simple pseudo-random number generator. 
Definition: util.h:1496
 
Defines common data types, constants and macros. 
 
int64_t read(int, void *, int64_t)
A wrapper over POSIX read function. 
Definition: util.cpp:973
 
bool nameMatch(const char *str, const char *pat)
Match the string str against a simple pattern pat without considering cases. 
Definition: util.cpp:2396
 
int readString(std::string &str, const char *&buf, const char *delim=0)
Copy the next string to the output variable str. 
Definition: util.cpp:248
 
void clear(ibis::array_t< ibis::bitvector * > &bv)
Clear an array of bit vectors. 
Definition: bitvector.cpp:4662
 
int decode16(uint64_t &, const char *)
Convert a string of hexadecimal digits back to an integer. 
Definition: util.cpp:1725
 
A concrete class for cleanup jobs that take a function with one argument. 
Definition: util.h:1356
 
~guardImpl1()
Destructor calls the cleanup function of the base class. 
Definition: util.h:1363
 
flock(int fd)
Constructor. 
Definition: util.h:1462
 
int readDouble(double &val, const char *&str, const char *del=ibis::util::delimiters)
Attempt to convert the incoming string into a double. 
Definition: util.cpp:780
 
A data structure to represent a sequence of bits. 
Definition: bitvector.h:62
 
void eq2range(const double &, double &, double &)
Generate a range [left, right) that contains exactly the input value in. 
Definition: util.h:1554
 
Print simple timing information. 
Definition: util.h:1230
 
~writeLock()
Destructor. 
Definition: util.h:850
 
int decode64(uint64_t &, const std::string &)
Decode a number encoded using ibis::util::encode64. 
Definition: util.cpp:1695
 
const char * delimiters
Delimiters used to separate a string of names. 
Definition: util.cpp:71
 
void reset()
Reset count to zero. 
Definition: util.h:902
 
A specialization of std::bad_alloc. 
Definition: util.h:441
 
std::ostream & operator()(void)
Return an output stream for caller to build a message. 
Definition: util.h:700
 
void removeDir(const char *name, bool leaveDir=false)
Remove the content of named directory. 
Definition: util.cpp:1023
 
double compactValue(double left, double right, double start=0.0)
Compute a compact 64-bit floating-point value with a short decimal representation. 
Definition: util.cpp:1227
 
std::ostream & operator<<(std::ostream &out, const ibis::rid_t &rid)
Print a rid_t to an output stream. 
Definition: util.h:1668
 
const char * getVersionString()
Return a pointer to the string designating the version of this software. 
Definition: util.h:642
 
void uniformFraction(const long unsigned idx, long unsigned &denominator, long unsigned &numerator)
Compute a denominator and numerator pair. 
Definition: util.cpp:1448
 
bad_alloc(const char *m="unknown")
Constructor. 
Definition: util.h:446
 
A shared unsigned 32-bit integer class. 
Definition: util.h:945
 
bool isLocked() const 
Was a lock acquired successfully? Returns true for yes, otherwise no. 
Definition: util.h:1473
 
A class for logging messages. 
Definition: util.h:693
 
int setLogFileName(const char *filename)
Change the current log file to the named file. 
Definition: util.cpp:1952
 
const char * getToken(char *&str, const char *tok_chrs)
Return a null-terminated string from the beginning of input string str. 
Definition: util.cpp:94
 
A class hierarchy for cleaning up after durable resources. 
Definition: util.h:1262
 
int makeDir(const char *dir)
Recursivly create directory "dir". 
Definition: util.cpp:112
 
A class to work with class member functions with no arguments. 
Definition: util.h:1427
 
~guardImpl0()
Destructor calls the cleanup function of the base class. 
Definition: util.h:1331
 
FILE * getLogFile()
Retrieve the pointer to the log file. 
Definition: util.cpp:2070
 
An wrapper class for perform pthread_rwlock_wrlock/unlock. 
Definition: util.h:840
 
An wrapper class for perform pthread_mutex_lock/unlock. 
Definition: util.h:740
 
uint32_t operator--()
Decrement operator. 
Definition: util.h:997
 
writeLock(pthread_rwlock_t *lk, const char *m)
Constructor. 
Definition: util.h:843