15 #ifndef STXXL_UTILS_HEADER
16 #define STXXL_UTILS_HEADER
23 #ifdef STXXL_BOOST_CONFIG
24 #include <boost/config.hpp>
27 #include <stxxl/bits/namespace.h>
28 #include <stxxl/bits/common/types.h>
29 #include <stxxl/bits/compat/type_traits.h>
30 #include <stxxl/bits/msvc_compatibility.h>
33 __STXXL_BEGIN_NAMESPACE
37 #if defined(__GXX_EXPERIMENTAL_CXX0X__)
38 #define STXXL_STATIC_ASSERT(x) static_assert(x, #x)
40 #define STXXL_STATIC_ASSERT(x) { typedef int static_assert_dummy_type[(x) ? 1 : -1]; }
45 inline std::vector<std::string>
46 split(
const std::string & str,
const std::string & sep)
48 std::vector<std::string> result;
52 std::string::size_type CurPos(0), LastPos(0);
55 CurPos = str.find(sep, LastPos);
56 if (CurPos == std::string::npos)
61 std::string::size_type(CurPos -
64 result.push_back(sub);
66 LastPos = CurPos + sep.size();
69 std::string sub = str.substr(LastPos);
71 result.push_back(sub);
78 inline stxxl::int64 atoint64(
const char * s)
89 template <
typename Tp>
91 STXXL_MIN(
const Tp & a,
const Tp & b)
93 return std::min<Tp>(a, b);
96 template <
typename Tp>
98 STXXL_MAX(
const Tp & a,
const Tp & b)
100 return std::max<Tp>(a, b);
105 template <
typename Integral>
106 inline Integral log2_ceil(Integral i)
108 return Integral(ceil(log2(i)));
111 template <
typename Integral>
112 inline Integral log2_floor(Integral i)
114 return Integral(log2(i));
119 template <
typename Integral,
typename Integral2>
121 typename compat::remove_const<Integral>::type
122 div_ceil(Integral __n, Integral2 __d)
124 #if 0 // ambiguous overload for std::div(unsigned_anything, unsigned_anything)
125 typedef __typeof__(std::div(__n, __d)) div_type;
126 div_type result = std::div(__n, __d);
127 return result.quot + (result.rem != 0);
129 return __n / __d + ((__n % __d) != 0);
136 #define HAVE_BUILTIN_EXPECT
139 #ifdef HAVE_BUILTIN_EXPECT
140 #define LIKELY(c) __builtin_expect((c), 1)
145 #ifdef HAVE_BUILTIN_EXPECT
146 #define UNLIKELY(c) __builtin_expect((c), 0)
148 #define UNLIKELY(c) c
153 inline uint64 longhash1(uint64 key_)
155 key_ += ~(key_ << 32);
156 key_ ^= (key_ >> 22);
157 key_ += ~(key_ << 13);
160 key_ ^= (key_ >> 15);
161 key_ += ~(key_ << 27);
162 key_ ^= (key_ >> 31);
169 inline void swap_1D_arrays(T * a, T * b, unsigned_type size)
171 for (unsigned_type i = 0; i < size; ++i)
172 std::swap(a[i], b[i]);
177 __STXXL_END_NAMESPACE
179 #endif // !STXXL_UTILS_HEADER