From aa0fe082d7481d113ab7e76e6c1e43d7b6adfc6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Basg=C3=B6ze?= Date: Thu, 2 Apr 2020 21:03:09 +0200 Subject: [PATCH] Document bitoperations.h --- src/storm/utility/bitoperations.h | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/storm/utility/bitoperations.h b/src/storm/utility/bitoperations.h index e12ff6d40..ad444ae2d 100644 --- a/src/storm/utility/bitoperations.h +++ b/src/storm/utility/bitoperations.h @@ -1,17 +1,30 @@ #pragma once -#include +#include + #include "storm/utility/macros.h" +/** + * \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! - if(n==0) return 0; + STORM_LOG_ASSERT( + n < 64, + "Input is too large."); // TODO fix this for 32 bit architectures! + if (n == 0) return 0; return (1 << n) - 1; } +/** + * The next bit permutation in a lexicographical sense. + * + * Example: 00010011, 00010101, 00010110, 00011001, + * 00011010, 00011100, 00100011, and so forth + * + * From https://graphics.stanford.edu/~seander/bithacks.html#NextBitPermutation + */ inline size_t nextBitPermutation(size_t v) { - if (v==0) return static_cast(0); - // From https://graphics.stanford.edu/~seander/bithacks.html#NextBitPermutation + if (v == 0) return static_cast(0); size_t t = (v | (v - 1)) + 1; return t | ((((t & -t) / (v & -v)) >> 1) - 1); }