|
@ -1,16 +1,13 @@ |
|
|
#pragma once |
|
|
#pragma once |
|
|
#include <cstddef> |
|
|
|
|
|
|
|
|
#include <cstdint> |
|
|
|
|
|
|
|
|
#include "storm/utility/macros.h" |
|
|
#include "storm/utility/macros.h" |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* \return 2^n - 1 |
|
|
* \return 2^n - 1 |
|
|
*/ |
|
|
*/ |
|
|
inline size_t smallestIntWithNBitsSet(size_t n) { |
|
|
|
|
|
static_assert(sizeof(size_t) == 8, "size_t has wrong size."); |
|
|
|
|
|
STORM_LOG_ASSERT( |
|
|
|
|
|
n < 64, |
|
|
|
|
|
"Input is too large."); // TODO fix this for 32 bit architectures! |
|
|
|
|
|
|
|
|
inline uint64_t smallestIntWithNBitsSet(uint64_t n) { |
|
|
|
|
|
STORM_LOG_ASSERT(n < 64, "Input is too large."); |
|
|
if (n == 0) return 0; |
|
|
if (n == 0) return 0; |
|
|
return (1 << n) - 1; |
|
|
return (1 << n) - 1; |
|
|
} |
|
|
} |
|
@ -23,8 +20,8 @@ inline size_t smallestIntWithNBitsSet(size_t n) { |
|
|
* |
|
|
* |
|
|
* From https://graphics.stanford.edu/~seander/bithacks.html#NextBitPermutation |
|
|
* From https://graphics.stanford.edu/~seander/bithacks.html#NextBitPermutation |
|
|
*/ |
|
|
*/ |
|
|
inline size_t nextBitPermutation(size_t v) { |
|
|
|
|
|
if (v == 0) return static_cast<size_t>(0); |
|
|
|
|
|
size_t t = (v | (v - 1)) + 1; |
|
|
|
|
|
|
|
|
inline uint64_t nextBitPermutation(uint64_t v) { |
|
|
|
|
|
if (v == 0) return 0; |
|
|
|
|
|
uint64_t t = (v | (v - 1)) + 1; |
|
|
return t | ((((t & -t) / (v & -v)) >> 1) - 1); |
|
|
return t | ((((t & -t) / (v & -v)) >> 1) - 1); |
|
|
} |
|
|
} |