Classes | Namespaces | Macros | Typedefs | Functions | Variables
util.h File Reference

Defines minor utility functions and common classes used by FastBit. More...

#include "const.h"
#include <map>
#include <string>
#include <limits>
#include <sstream>
#include <cctype>
#include <cstring>
#include <float.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/file.h>
#include <atomic>

Go to the source code of this file.

Classes

class  ibis::bad_alloc
 A specialization of std::bad_alloc. More...
 
class  ibis::nameList
 A data structure to store a small set of names. More...
 
class  ibis::util::counter
 A simple shared counter. More...
 
class  ibis::util::flock
 A simple wrapper on flock. More...
 
class  ibis::util::guardBase
 A class hierarchy for cleaning up after durable resources. More...
 
class  ibis::util::guardImpl0< F >
 A concrete class for cleanup jobs that take a function without any argument. More...
 
class  ibis::util::guardImpl1< F, A >
 A concrete class for cleanup jobs that take a function with one argument. More...
 
class  ibis::util::guardImpl2< F, A1, A2 >
 A concrete class for cleanup jobs that take a function with two arguments. More...
 
class  ibis::util::guardObj0< C, F >
 A class to work with class member functions with no arguments. More...
 
class  ibis::util::ioLock
 A global I/O lock. More...
 
class  ibis::util::logger
 A class for logging messages. More...
 
class  ibis::util::mutexLock
 An wrapper class for perform pthread_mutex_lock/unlock. More...
 
class  ibis::util::quietLock
 An wrapper class for perform pthread_mutex_lock/unlock. More...
 
class  ibis::util::readLock
 An wrapper class for perform pthread_rwlock_rdlock/unlock. More...
 
class  ibis::util::refHolder< T >
 A template to hold a reference to an object. More...
 
class  ibis::util::sharedInt32
 A shared unsigned 32-bit integer class. More...
 
class  ibis::util::sharedInt64
 A unsigned 64-bit shared integer class. More...
 
class  ibis::util::softLock
 An wrapper class for perform pthread_mutex_trylock/unlock. More...
 
class  ibis::util::timer
 Print simple timing information. More...
 
class  ibis::util::writeLock
 An wrapper class for perform pthread_rwlock_wrlock/unlock. More...
 
struct  std::equal_to< const char * >
 
struct  std::less< char * >
 
struct  std::less< const char * >
 
struct  std::less< const ibis::rid_t * >
 
struct  std::less< ibis::rid_t >
 

Namespaces

 ibis
 The current implementation of FastBit is code named IBIS; most data structures and functions are in the name space ibis.
 
 ibis::util
 Organize the miscellaneous functions under the name util.
 

Macros

#define BIG_CONSTANT(x)   (x##LLU)
 
#define DBL_EPSILON   2.2204460492503131e-16
 
#define FASTBIT_CASE_SENSITIVE_COMPARE   1
 
#define FASTBIT_MIN_MAP_SIZE   1048576
 
#define FASTBIT_ROTL32(x, y)    _rotl32(x,y)
 
#define FASTBIT_ROTL64(x, y)    _rotl64(x,y)
 
#define FORCE_INLINE   inline __attribute__((always_inline))
 
#define IBIS_2STR(x)   #x
 
#define IBIS_BLOCK_GUARD   ibis::util::guard IBIS_GUARD_NAME = ibis::util::makeGuard
 
#define IBIS_FILE_LINE   " -- " __FILE__ ":" IBIS_INT_STR(__LINE__)
 
#define IBIS_GUARD_NAME   IBIS_JOIN_MACRO(_guard, __LINE__)
 
#define IBIS_INT_STR(x)   IBIS_2STR(x)
 
#define IBIS_JOIN_MACRO(X, Y)   IBIS_JOIN_MACRO2(X, Y)
 
#define IBIS_JOIN_MACRO2(X, Y)   X##Y
 
#define LOGGER(v)    if (false == (v)) ; else ibis::util::logger(0)()
 
#define OPEN_FILEMODE   S_IRUSR | S_IWUSR
 
#define Stat_T   struct stat
 
#define STRMATCH_META_CSH_ANY   '*'
 
#define STRMATCH_META_CSH_ONE   '?'
 
#define STRMATCH_META_ESCAPE   '\\'
 
#define STRMATCH_META_SQL_ANY   '%'
 
#define STRMATCH_META_SQL_ONE   '_'
 
#define UnixClose   ::close
 
#define UnixFlush   ::fsync
 
#define UnixFStat   ::fstat
 
#define UnixOpen   ::open
 Guess about GCC atomic operations. More...
 
#define UnixRead   ::read
 
#define UnixSeek   ::lseek
 
#define UnixSnprintf   ::snprintf
 
#define UnixStat   ::stat
 
#define UnixWrite   ::write
 

Typedefs

typedef std::vector< colValues * > ibis::colList
 
typedef const guardBase & ibis::util::guard
 The type to be used by client code. More...
 
typedef std::map< const char *, part *, lessi > ibis::partAssoc
 An associative array for data partitions. More...
 

Functions

uint32_t _rotl32 (uint32_t x, int8_t r)
 
uint64_t _rotl64 (uint64_t x, int8_t r)
 
void ibis::util::clear (ibis::array_t< ibis::bitvector * > &bv) throw ()
 Clear an array of bit vectors.
 
void ibis::util::clear (ibis::partList &pl) throw ()
 Deallocate the list of data partitions.
 
template<typename T >
void ibis::util::clearVec (std::vector< T * > &v)
 A template to clean up a vector of pointers.
 
void ibis::util::closeLogFile ()
 Close the log file. More...
 
int ibis::util::copy (const char *to, const char *from)
 Copy file named "from" to a file named "to". More...
 
void ibis::util::emptyCache (void)
 Attempt to remove all currently unused data from memory cache. More...
 
off_t ibis::util::getFileSize (const char *name)
 Return size of the file in bytes. More...
 
void ibis::util::getGMTime (char *str)
 Return the current GMT time in string format. More...
 
void ibis::util::getLocalTime (char *str)
 Return the current time in string format as asctime_r. More...
 
FILE * ibis::util::getLogFile ()
 Retrieve the pointer to the log file. More...
 
const char * ibis::util::getLogFileName ()
 Return name the of the current log file. More...
 
char * ibis::util::getString (const char *buf)
 Extract a string from the given buf. More...
 
const char * ibis::util::getToken (char *&str, const char *tok_chrs)
 Return a null-terminated string from the beginning of input string str. More...
 
int ibis::util::getVersionNumber ()
 Return an integer designating the version of this software. More...
 
const char * ibis::util::getVersionString ()
 Return a pointer to the string designating the version of this software. More...
 
ibis::resourceibis::gParameters ()
 List of in-memory data. More...
 
long ibis::util::intersect (const std::vector< ibis::bitvector > &bits1, const std::vector< ibis::bitvector > &bits2, std::vector< ibis::bitvector > &res)
 Intersect two sets of bit vectors. More...
 
long ibis::util::intersect (const std::vector< ibis::bitvector > &bits1, const std::vector< ibis::bitvector > &bits2, const std::vector< ibis::bitvector > &bits3, std::vector< ibis::bitvector > &res)
 Intersect three sets of bit vectors. More...
 
char * ibis::util::itoa (int value, char *str, int)
 
void ibis::util::logMessage (const char *event, const char *fmt,...)
 Print a message to standard output. More...
 
int ibis::util::makeDir (const char *dir)
 Recursivly create directory "dir". More...
 
template<typename F >
guardImpl0< F > ibis::util::makeGuard (F f)
 
template<typename F , typename A >
guardImpl1< F, A > ibis::util::makeGuard (F f, A a)
 
template<typename F , typename A1 , typename A2 >
guardImpl2< F, A1, A2 > ibis::util::makeGuard (F f, A1 a1, A2 a2)
 
bool ibis::util::nameMatch (const char *str, const char *pat)
 Match the string str against a simple pattern pat without considering cases. More...
 
template<class C , typename F >
guardObj0< C, F > ibis::util::objectGuard (C o, F f)
 
std::ostream & operator<< (std::ostream &out, const ibis::rid_t &rid)
 Print a rid_t to an output stream.
 
std::istream & operator>> (std::istream &is, ibis::rid_t &rid)
 Read a rid_t from an input stream.
 
const ibis::bitvector64ibis::util::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. More...
 
const ibis::bitvector64ibis::util::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. More...
 
double ibis::util::rand ()
 A very simple pseudo-random number generator. More...
 
int64_t ibis::util::read (int, void *, int64_t)
 A wrapper over POSIX read function. More...
 
int ibis::util::readDouble (double &val, const char *&str, const char *del=ibis::util::delimiters)
 Attempt to convert the incoming string into a double. More...
 
int ibis::util::readInt (int64_t &val, const char *&str, const char *del=ibis::util::delimiters)
 Attempt to convert the incoming string into an integer. More...
 
int ibis::util::readString (std::string &str, const char *&buf, const char *delim=0)
 Copy the next string to the output variable str. More...
 
const char * ibis::util::readString (char *&buf, const char *delim=0)
 Attempt to extract a string token from the incoming buffer. More...
 
int ibis::util::readUInt (uint64_t &val, const char *&str, const char *del=ibis::util::delimiters)
 Attempt to convert the incoming string into a unsigned integer. More...
 
template<class T >
refHolder< T > ibis::util::ref (T &r)
 A function template to produce refHolder.
 
void ibis::util::removeDir (const char *name, bool leaveDir=false)
 Remove the content of named directory. More...
 
void ibis::util::removeTail (char *str, char tail)
 Remove trailing character 'tail' from str.
 
void ibis::util::secondsToString (const time_t, char *str)
 Converts the given time in seconds (as returned by function time) into the string (as from asctime_r). More...
 
uint32_t ibis::util::serialNumber ()
 Compute a serial number. More...
 
int ibis::util::setLogFileName (const char *filename)
 Change the current log file to the named file. More...
 
void ibis::util::setVerboseLevel (int v)
 Set the verboseness level. More...
 
bool ibis::util::strMatch (const char *str, const char *pat)
 Match the string str against a simple pattern pat. More...
 
char * ibis::util::strnewdup (const char *s)
 Duplicate string content with C++ default new operator. More...
 
char * ibis::util::strnewdup (const char *s, const uint32_t n)
 Duplicate no more than n characters.
 
char * ibis::util::trim (char *str)
 Remove leading and trailing blank space.
 
void ibis::util::uniformFraction (const long unsigned idx, long unsigned &denominator, long unsigned &numerator)
 Compute a denominator and numerator pair. More...
 
void ibis::util::updateDatasets (void)
 Update the metadata about the data partitions. More...
 
const char * ibis::util::userName ()
 Return the user name. More...
 
int64_t ibis::util::write (int, const void *, int64_t)
 A wrapper over POSIX write function. More...
 
int ibis::util::writeLogFileHeader (FILE *fptr, const char *fname)
 Write a header to the log file. More...
 
uint32_t ibis::util::checksum (const char *str, uint32_t sz)
 Fletcher's arithmetic checksum with 32-bit result.
 
uint32_t ibis::util::checksum (uint32_t a, uint32_t b)
 Fletcher's checksum on two integers. Returns an integer.
 
std::string ibis::util::shortName (const std::string &longname)
 Use the Fletcher's checksum to produce a short string. More...
 
std::string ibis::util::randName (const std::string &longname)
 Generate a short string to be used as a table/partition name.
 
void ibis::util::int2string (std::string &str, unsigned val)
 Pack a 32-bit integer into six base-64 alphabets.
 
void ibis::util::int2string (std::string &str, unsigned v1, unsigned v2)
 Pack two 32-bit integers into 11 base-64 alphabets.
 
void ibis::util::int2string (std::string &str, unsigned v1, unsigned v2, unsigned v3)
 Pack three 32-bit integers into 16 base-64 alphabets.
 
void ibis::util::int2string (std::string &str, const std::vector< unsigned > &val)
 Convert the incoming numbers into a base-64 alpha-numeric representation. More...
 
void ibis::util::encode64 (uint64_t, std::string &)
 Turn the incoming integer into a 64-bit representation. More...
 
int ibis::util::decode64 (uint64_t &, const std::string &)
 Decode a number encoded using ibis::util::encode64.
 
int ibis::util::decode16 (uint64_t &, const char *)
 Convert a string of hexadecimal digits back to an integer. More...
 
std::string ibis::util::groupby1000 (uint64_t)
 Produce a string version of the unsigned integer value with the decimal digits grouped into 1000s. More...
 
double ibis::util::incrDouble (const double &)
 Functions to handle manipulation of floating-point numbers. More...
 
double ibis::util::decrDouble (const double &)
 Decrease the input value to the next smaller value. More...
 
void ibis::util::eq2range (const double &, double &, double &)
 Generate a range [left, right) that contains exactly the input value in. More...
 
double ibis::util::coarsen (const double in, unsigned prec=2)
 Reduce the decimal precision of the incoming floating-point value to specified precision. More...
 
double ibis::util::compactValue (double left, double right, double start=0.0)
 Compute a compact 64-bit floating-point value with a short decimal representation. More...
 
double ibis::util::compactValue2 (double left, double right, double start=0.0)
 Compute a compact 64-bit floating-point value with a short binary representation. More...
 
void ibis::util::setNaN (double &val)
 Set a double to NaN.
 
void ibis::util::setNaN (float &val)
 Functions to handle manipulation of floating-point numbers. More...
 
template<typename Tin , typename Tout >
void ibis::util::round_down (const Tin &inval, Tout &outval)
 Round the incoming value to the largest output value that is no more than the input. More...
 
template<typename Tin , typename Tout >
void ibis::util::round_up (const Tin &inval, Tout &outval)
 Round the incoming value to the smallest output value that is no less than the input. More...
 
template<typename Tin >
void ibis::util::round_up (const Tin &inval, float &)
 A specialization of round_up for the output type float. More...
 
template<typename Tin >
void ibis::util::round_up (const Tin &inval, double &outval)
 A specialization of round_up for the output in double.
 
int ibis::util::log2 (uint32_t x)
 Log_2 of a 32-bit integer.
 
int ibis::util::log2 (uint64_t x)
 Log_2 of a 64-bit integer.
 

Variables

const short unsigned ibis::util::charIndex []
 charIndex maps the characters (ASCII) back to integer [0-64] More...
 
const char * ibis::util::charTable
 charTable lists the 64 printable characters to be used for names More...
 
partList ibis::datasets
 !< Select clause. More...
 
const char * ibis::util::delimiters = ";, \v\b\f\r\t\n'\""
 Delimiters used to separate a string of names. More...
 
pthread_mutex_t ibis::util::envLock = PTHREAD_MUTEX_INITIALIZER
 A mutex for serialize operations FastBit wide. More...
 
const int ibis::util::log2table [256]
 log base 2 of an integer, the lookup table More...
 

Detailed Description

Defines minor utility functions and common classes used by FastBit.

Macro Definition Documentation

#define UnixOpen   ::open

Guess about GCC atomic operations.

Guess about MS Windows automic operation support

Referenced by ibis::index::activate(), ibis::text::append(), ibis::blob::append(), ibis::category::append(), ibis::column::append(), ibis::column::appendStrings(), ibis::column::appendValues(), ibis::bord::backup(), ibis::bin::binningT(), ibis::bin::binOrderT(), ibis::util::copy(), ibis::blob::countRawBytes(), ibis::index::create(), ibis::part::doCompare(), ibis::fileManager::roFile::doRead(), ibis::blob::extractAll(), ibis::blob::extractSome(), ibis::category::fillIndex(), ibis::index::isIndex(), ibis::roster::mergeBlock2(), ibis::bin::mergeValues(), ibis::part::negativeCompare(), ibis::roster::oocSearch(), ibis::part::barrel::open(), ibis::part::vault::open(), ibis::query::orderPairs(), ibis::keywords::parseTextFile(), ibis::relic::read(), ibis::bin::read(), ibis::direkte::read(), ibis::keywords::read(), ibis::fileManager::storage::read(), ibis::skive::read(), ibis::fade::read(), ibis::range::read(), ibis::fuzz::read(), ibis::bylt::read(), ibis::zona::read(), ibis::ambit::read(), ibis::pale::read(), ibis::pack::read(), ibis::zone::read(), ibis::fuge::read(), ibis::egale::read(), ibis::blob::readBlob(), ibis::bundle::readRIDs(), ibis::text::readString(), ibis::text::readStrings1(), ibis::text::readStrings2(), ibis::query::recordDeltaPairs(), ibis::query::recordEqualPairs(), ibis::part::reorderValues(), ibis::column::searchSortedOOCC(), ibis::column::searchSortedOOCD(), ibis::text::selectStrings(), ibis::column::selectValuesT(), ibis::category::setDictionary(), ibis::roster::write(), ibis::relic::write(), ibis::bin::write(), ibis::direkte::write(), ibis::keywords::write(), ibis::skive::write(), ibis::slice::write(), ibis::fade::write(), ibis::sbiad::write(), ibis::sapid::write(), ibis::range::write(), ibis::fuzz::write(), ibis::mesa::write(), ibis::bylt::write(), ibis::zona::write(), ibis::ambit::write(), ibis::pale::write(), ibis::pack::write(), ibis::zone::write(), ibis::fuge::write(), ibis::egale::write(), ibis::moins::write(), ibis::entre::write(), ibis::blob::writeData(), ibis::text::writeStrings(), and ibis::part::writeValues().

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