16 #ifndef STXXL_COMMON_UTILS_HEADER
17 #define STXXL_COMMON_UTILS_HEADER
37 #if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)))
38 # define STXXL_ATTRIBUTE_UNUSED __attribute__ ((unused))
40 # define STXXL_ATTRIBUTE_UNUSED
45 #if defined(__GXX_EXPERIMENTAL_CXX0X__)
46 #define STXXL_STATIC_ASSERT(x) static_assert(x, #x)
48 #define STXXL_STATIC_ASSERT(x) { typedef int static_assert_dummy_type[(x) ? 1 : -1] STXXL_ATTRIBUTE_UNUSED; }
55 static inline std::vector<std::string>
56 split(
const std::string& str,
const std::string& sep,
57 unsigned int min_fields = 0,
60 std::vector<std::string> result;
62 result.resize(min_fields);
66 std::string::size_type CurPos(0), LastPos(0);
69 if (result.size() + 1 == limit_fields)
72 CurPos = str.find(sep, LastPos);
73 if (CurPos == std::string::npos)
78 std::string::size_type(CurPos - LastPos))
81 LastPos = CurPos + sep.size();
84 std::string sub = str.substr(LastPos);
85 result.push_back(sub);
87 if (result.size() < min_fields)
88 result.resize(min_fields);
96 template <
typename Type>
99 std::ostringstream oss;
136 return _strtoui64(s, NULL, 10);
138 return strtoull(s, NULL, 10);
144 template <
typename Type>
148 return std::min<Type>(a, b);
151 template <
typename Type>
155 return std::max<Type>(a, b);
161 template <
typename Integral>
164 return Integral(ceil(log2(i)));
168 template <
typename Integral>
171 return Integral(log2(i));
177 template <
typename IntegerType>
181 while (i >= 256) i >>= 8, p += 8;
187 template <
typename IntegerType>
190 if (i <= 1)
return 0;
196 template <
typename Integral,
typename Integral2>
198 typename compat::remove_const<Integral>::type
201 #if 0 // ambiguous overload for std::div(unsigned_anything, unsigned_anything)
202 typedef __typeof__ (std::div (n, d)) div_type;
203 div_type result = std::div(n, d);
204 return result.quot + (result.rem != 0);
206 return n / d + ((n % d) != 0);
213 #define HAVE_BUILTIN_EXPECT
216 #ifdef HAVE_BUILTIN_EXPECT
217 #define LIKELY(c) __builtin_expect((c), 1)
222 #ifdef HAVE_BUILTIN_EXPECT
223 #define UNLIKELY(c) __builtin_expect((c), 0)
225 #define UNLIKELY(c) c
232 key_ += ~(key_ << 32);
233 key_ ^= (key_ >> 22);
234 key_ += ~(key_ << 13);
237 key_ ^= (key_ >> 15);
238 key_ += ~(key_ << 27);
239 key_ ^= (key_ >> 31);
245 template <
class Type>
249 std::swap(a[i], b[i]);
254 template <
typename Integral>
258 for (
int k = 1; k != 8 *
sizeof(n); k <<= 1)
265 template <
typename Integral>
268 Integral pot = Integral(1) << power,
271 return (n & ~mask) + pot;
278 template <
class Container>
279 inline typename Container::value_type
pop(Container& c)
281 typename Container::value_type r = c.top();
286 template <
class Container>
287 inline typename Container::value_type
pop_front(Container& c)
289 typename Container::value_type r = c.front();
294 template <
class Container>
295 inline typename Container::value_type
pop_back(Container& c)
297 typename Container::value_type r = c.back();
302 template <
class Container>
303 inline typename Container::value_type
pop_begin(Container& c)
305 typename Container::value_type r = *c.begin();
314 #endif // !STXXL_COMMON_UTILS_HEADER
compat::remove_const< Integral >::type div_ceil(Integral n, Integral2 d)
Integral log2_floor(Integral i)
calculate the log2 ceiling of an integral type using math.h
const Type & STXXL_MIN(const Type &a, const Type &b)
size_t longhash1(uint64 key_)
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)
void swap_1D_arrays(Type *a, Type *b, unsigned_type size)
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
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...
const Type & STXXL_MAX(const Type &a, const Type &b)
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)
static Integral round_up_to_power_of_two(Integral n)
#define STXXL_END_NAMESPACE