Skip to content

Commit

Permalink
Update to not use unsigned long to obtain 64-bit integer
Browse files Browse the repository at this point in the history
Signed-off-by: yamacir-kit <[email protected]>
  • Loading branch information
yamacir-kit committed Aug 31, 2024
1 parent 8cbfba6 commit 0065de0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Procedures for each standard are provided by the following R7RS-style libraries:
cmake -B build -DCMAKE_BUILD_TYPE=Release
cd build
make package
sudo apt install build/meevax_0.5.227_amd64.deb
sudo apt install build/meevax_0.5.228_amd64.deb
```

or
Expand Down Expand Up @@ -122,9 +122,9 @@ sudo rm -rf /usr/local/share/meevax

| Target Name | Description
|-------------|-------------
| `all` | Build shared-library `libmeevax.0.5.227.so` and executable `meevax`
| `all` | Build shared-library `libmeevax.0.5.228.so` and executable `meevax`
| `test` | Test executable `meevax`
| `package` | Generate debian package `meevax_0.5.227_amd64.deb`
| `package` | Generate debian package `meevax_0.5.228_amd64.deb`
| `install` | Copy files into `/usr/local` directly

## Usage
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.227
0.5.228
27 changes: 16 additions & 11 deletions include/meevax/memory/integer_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ inline namespace memory
template <typename T>
constexpr auto compressible_bitwidth_of = std::is_pointer_v<T> ? log2(alignof(std::remove_pointer_t<T>)) - 1 : 0;

constexpr auto operator ""_u64(unsigned long long int value)
{
return static_cast<std::uint64_t>(value);
}

template <typename T, std::size_t E, std::size_t... Es>
struct integer_set
{
Expand Down Expand Up @@ -277,9 +282,9 @@ inline namespace memory
template <typename T, std::size_t E>
struct integer_set<T, E>
{
static_assert(std::is_same_v<decltype(0ul), std::uint64_t>);
static_assert(std::is_same_v<decltype(0_u64), std::uint64_t>);

static constexpr auto N = 1ul << E;
static constexpr auto N = 1_u64 << E;

std::uint64_t data[N / 64] {};

Expand All @@ -303,18 +308,18 @@ inline namespace memory
{
if (auto i = index / 64; i < N/64)
{
if (auto datum = data[i] & (~0ul << index % 64); datum)
if (auto datum = data[i] & (~0_u64 << index % 64); datum)
{
index = i * 64 + __builtin_ctzl(datum);
assert(data[index / 64] & (1ul << index % 64));
assert(data[index / 64] & (1_u64 << index % 64));
return;
}
else while (++i < N/64)
{
if (auto datum = data[i]; datum)
{
index = i * 64 + __builtin_ctzl(datum);
assert(data[index / 64] & (1ul << index % 64));
assert(data[index / 64] & (1_u64 << index % 64));
return;
}
}
Expand All @@ -329,18 +334,18 @@ inline namespace memory
{
if (auto i = index / 64; i < N/64)
{
if (auto datum = data[i] & (~0ul >> (63 - index % 64)); datum)
if (auto datum = data[i] & (~0_u64 >> (63 - index % 64)); datum)
{
index = i * 64 + (63 - __builtin_clzl(datum));
assert(data[index / 64] & (1ul << index % 64));
assert(data[index / 64] & (1_u64 << index % 64));
return;
}
else while (--i < N/64)
{
if (auto datum = data[i]; datum)
{
index = i * 64 + (63 - __builtin_clzl(datum));
assert(data[index / 64] & (1ul << index % 64));
assert(data[index / 64] & (1_u64 << index % 64));
return;
}
}
Expand Down Expand Up @@ -418,21 +423,21 @@ inline namespace memory
{
auto i = reinterpret_cast<std::size_t>(value) / 64;
auto j = reinterpret_cast<std::size_t>(value) % 64;
data[i] |= (1ul << j);
data[i] |= (1_u64 << j);
}

auto erase(T value) noexcept
{
auto i = reinterpret_cast<std::size_t>(value) / 64;
auto j = reinterpret_cast<std::size_t>(value) % 64;
data[i] &= ~(1ul << j);
data[i] &= ~(1_u64 << j);
}

auto contains(T value) noexcept -> bool
{
auto i = reinterpret_cast<std::size_t>(value) / 64;
auto j = reinterpret_cast<std::size_t>(value) % 64;
return data[i] & (1ul << j);
return data[i] & (1_u64 << j);
}

auto lower_bound(T value) const noexcept
Expand Down

0 comments on commit 0065de0

Please sign in to comment.