include/lshkit/common.h

Go to the documentation of this file.
00001 /* 
00002     Copyright (C) 2008 Wei Dong <wdong@princeton.edu>. All Rights Reserved.
00003   
00004     This file is part of LSHKIT.
00005   
00006     LSHKIT is free software: you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation, either version 3 of the License, or
00009     (at your option) any later version.
00010 
00011     LSHKIT is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with LSHKIT.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 
00020 #ifndef __LSHKIT_COMMON__
00021 #define __LSHKIT_COMMON__
00022 
00029 #include <cmath>
00030 #include <limits>
00031 #include <vector>
00032 #include <stdexcept>
00033 #include <boost/foreach.hpp>
00034 #include <boost/random.hpp>
00035 
00037 
00040 //#define CONCEPT_CHECK 0
00041 
00042 #ifdef CONCEPT_CHECK
00043 #include <lshkit/concept.h>
00044 #else
00045 #define BOOST_CONCEPT_ASSERT(A)
00046 #endif
00047 
00053 #ifndef panic
00054 #if defined(WIN32)
00055 #define panic(_fmt, ...) \
00056     do { \
00057         lshkit::panic_intern("%s: %s: %d: "_fmt, \
00058                         __FILE__, \
00059                         __FUNCTION__, \
00060                         __LINE__ , \
00061                         ## __VA_ARGS__); \
00062     } while (0)
00063 #else
00064 #define panic(_fmt, _args...) \
00065     do { \
00066         lshkit::panic_intern("%s: %s: %d: "_fmt, \
00067                         __FILE__, \
00068                         __FUNCTION__, \
00069                         __LINE__ , \
00070                         ## _args); \
00071     } while (0)
00072 #endif
00073 #endif
00074 
00078 #ifndef verify
00079 #define verify(_x) \
00080     do { \
00081         if (_x) { \
00082             /* noop */ \
00083         } else { \
00084             panic("!(%s)", #_x); \
00085         } \
00086     } while (0)
00087 #endif
00088 
00089 namespace lshkit {
00090 
00092 typedef boost::mt19937 DefaultRng;
00093 
00094 // Some of the frequently used distributions.
00095 
00097 typedef boost::normal_distribution<float> Gaussian;
00099 typedef boost::cauchy_distribution<float> Cauchy;
00101 typedef boost::uniform_real<float> Uniform;
00103 typedef boost::uniform_int<int> UniformInt;
00105 typedef boost::uniform_int<unsigned> UniformUnsigned;
00106 
00108 /* We define this so that <algorithm> doesn't have to be included solely for
00109    this simple function.
00110  */
00111 template <typename T>
00112 T min (T a, T b) { return a < b ? a : b; }
00113 
00115 template <typename T>
00116 T max (T a, T b) { return a < b ? b : a; }
00117 
00119 template <typename T> T sqr (const T &x) { return x * x; }
00120 
00121 void panic_intern(const char *fmt, ...);
00122 
00123 }
00124 
00125 
00126 #endif
00127 

Get LSHKIT at SourceForge.net. Fast, secure and Free Open Source software downloads doxygen