16 #ifndef STXXL_COMMON_UTILS_HEADER
17 #define STXXL_COMMON_UTILS_HEADER
38 #if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)))
39 # define STXXL_ATTRIBUTE_UNUSED __attribute__ ((unused))
41 # define STXXL_ATTRIBUTE_UNUSED
46 #if defined(__GXX_EXPERIMENTAL_CXX0X__)
47 #define STXXL_STATIC_ASSERT(x) static_assert(x, #x)
49 #define STXXL_STATIC_ASSERT(x) { typedef int static_assert_dummy_type[(x) ? 1 : -1] STXXL_ATTRIBUTE_UNUSED; }
56 static inline std::vector<std::string>
57 split(
const std::string& str,
const std::string& sep,
58 unsigned int min_fields = 0,
61 std::vector<std::string> result;
63 result.resize(min_fields);
67 std::string::size_type CurPos(0), LastPos(0);
70 if (result.size() + 1 == limit_fields)
73 CurPos = str.find(sep, LastPos);
74 if (CurPos == std::string::npos)
79 std::string::size_type(CurPos - LastPos))
82 LastPos = CurPos + sep.size();
85 std::string sub = str.substr(LastPos);
86 result.push_back(sub);
88 if (result.size() < min_fields)
89 result.resize(min_fields);
97 template <
typename Type>
100 std::ostringstream oss;
137 return _strtoui64(s, NULL, 10);
139 return strtoull(s, NULL, 10);
145 template <
typename Tp>
149 return std::min<Tp>(a, b);
152 template <
typename Tp>
156 return std::max<Tp>(a, b);
162 template <
typename Integral>
165 return Integral(ceil(log2(i)));
169 template <
typename Integral>
172 return Integral(log2(i));
178 template <
typename IntegerType>
182 while (i >= 256) i >>= 8, p += 8;
188 template <
typename IntegerType>
191 if (i <= 1)
return 0;
197 template <
typename Integral,
typename Integral2>
199 typename compat::remove_const<Integral>::type
202 #if 0 // ambiguous overload for std::div(unsigned_anything, unsigned_anything)
203 typedef __typeof__ (std::div(__n, __d)) div_type;
204 div_type result = std::div(__n, __d);
205 return result.quot + (result.rem != 0);
207 return __n / __d + ((__n % __d) != 0);
214 #define HAVE_BUILTIN_EXPECT
217 #ifdef HAVE_BUILTIN_EXPECT
218 #define LIKELY(c) __builtin_expect((c), 1)
223 #ifdef HAVE_BUILTIN_EXPECT
224 #define UNLIKELY(c) __builtin_expect((c), 0)
226 #define UNLIKELY(c) c
233 key_ += ~(key_ << 32);
234 key_ ^= (key_ >> 22);
235 key_ += ~(key_ << 13);
238 key_ ^= (key_ >> 15);
239 key_ += ~(key_ << 27);
240 key_ ^= (key_ >> 31);
250 std::swap(a[i], b[i]);
256 template <
typename Integral>
259 Integral pot = Integral(1) << power,
262 return (n & ~mask) + pot;
269 template <
class Container>
270 inline typename Container::value_type
pop(Container& c)
272 typename Container::value_type r = c.top();
277 template <
class Container>
278 inline typename Container::value_type
pop_front(Container& c)
280 typename Container::value_type r = c.front();
285 template <
class Container>
286 inline typename Container::value_type
pop_back(Container& c)
288 typename Container::value_type r = c.back();
293 template <
class Container>
294 inline typename Container::value_type
pop_begin(Container& c)
296 typename Container::value_type r = *c.begin();
305 #endif // !STXXL_COMMON_UTILS_HEADER
const Tp & STXXL_MIN(const Tp &a, const Tp &b)
Integral log2_floor(Integral i)
calculate the log2 ceiling of an integral type using math.h
void swap_1D_arrays(T *a, T *b, unsigned_type size)
unsigned long long int uint64
std::string format_SI_size(uint64 number)
Format a byte size using SI (K, M, G, T) suffixes (powers of ten). Returns "123 M" or similar...
Container::value_type pop_begin(Container &c)
uint64 longhash1(uint64 key_)
stxxl::uint64 atouint64(const char *s)
stxxl::int64 atoi64(const char *s)
Integral log2_ceil(Integral i)
calculate the log2 floor of an integral type using math.h
const Tp & STXXL_MAX(const Tp &a, const Tp &b)
Container::value_type pop_back(Container &c)
Container::value_type pop(Container &c)
static std::vector< std::string > split(const std::string &str, const std::string &sep, unsigned int min_fields=0, unsigned int limit_fields=std::numeric_limits< unsigned int >::max())
Split a string by given separator string. Returns a vector of strings with at least min_fields and at...
std::string to_str(const Type &t)
Format any ostream-able type into a string.
#define STXXL_BEGIN_NAMESPACE
static uint_pair max()
return an uint_pair instance containing the largest value possible
bool parse_SI_IEC_size(const std::string &str, uint64 &size, char def_unit=0)
Parse a string like "343KB" or "44 GiB" into the corresponding size in bytes. Returns the number of b...
unsigned int ilog2_floor(IntegerType i)
calculate the log2 floor of an integer type (by repeated bit shifts)
std::string format_IEC_size(uint64 number)
Format a byte size using IEC (Ki, Mi, Gi, Ti) suffixes (powers of two). Returns "123 Ki" or similar...
Container::value_type pop_front(Container &c)
choose_int_types< my_pointer_size >::unsigned_type unsigned_type
unsigned int ilog2_ceil(const IntegerType &i)
calculate the log2 ceiling of an integer type (by repeated bit shifts)
compat::remove_const< Integral >::type div_ceil(Integral __n, Integral2 __d)
Integral round_up_to_power_of_two(Integral n, unsigned_type power)
round n up to next larger multiple of 2^power. example: (48,4) = 64, (48,3) = 48. ...
#define STXXL_END_NAMESPACE