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]);
255 template <
typename Integral>
258 Integral pot = Integral(1) << power,
261 return (n & ~mask) + pot;
268 template <
class Container>
269 inline typename Container::value_type
pop(Container& c)
271 typename Container::value_type r = c.top();
276 template <
class Container>
277 inline typename Container::value_type
pop_front(Container& c)
279 typename Container::value_type r = c.front();
284 template <
class Container>
285 inline typename Container::value_type
pop_back(Container& c)
287 typename Container::value_type r = c.back();
292 template <
class Container>
293 inline typename Container::value_type
pop_begin(Container& c)
295 typename Container::value_type r = *c.begin();
304 #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)
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