Skip to content

Commit

Permalink
Update pointer_set::chunk to provide std::bitset-like interfaces
Browse files Browse the repository at this point in the history
Signed-off-by: yamacir-kit <[email protected]>
  • Loading branch information
yamacir-kit committed Nov 6, 2023
1 parent 8036582 commit c246d72
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,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.79_amd64.deb
sudo apt install build/meevax_0.5.80_amd64.deb
```

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

| Target Name | Description
|-------------|-------------
| `all` | Build shared-library `libmeevax.0.5.79.so` and executable `meevax`
| `all` | Build shared-library `libmeevax.0.5.80.so` and executable `meevax`
| `test` | Test executable `meevax`
| `package` | Generate debian package `meevax_0.5.79_amd64.deb`
| `package` | Generate debian package `meevax_0.5.80_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.79
0.5.80
37 changes: 27 additions & 10 deletions include/meevax/memory/pointer_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ inline namespace memory
{
static_assert(std::is_pointer_v<Pointer>);

static constexpr auto width = sizeof(std::uintmax_t) * 8;
static constexpr auto width = sizeof(std::uintptr_t) * 8;

static_assert(Capacity % width == 0);

Expand Down Expand Up @@ -76,15 +76,32 @@ inline namespace memory
}
};

struct chunk : public std::array<bool, Capacity>
struct chunk
{
std::array<bool, Capacity> data;

std::size_t offset;

explicit constexpr chunk(compact_pointer const p)
: std::array<bool, Capacity> { false }
explicit chunk(compact_pointer const p) noexcept
: data { false }
, offset { p.offset() }
{
(*this)[p.index()] = true;
data[p.index()] = true;
}

auto test(std::size_t i) const noexcept -> bool
{
return data[i];
}

auto set(std::size_t i) noexcept -> void
{
data[i] = true;
}

auto reset(std::size_t i) noexcept -> void
{
data[i] = false;
}
};

Expand Down Expand Up @@ -116,7 +133,7 @@ inline namespace memory
, i { static_cast<std::size_t>(std::distance(chunks.begin(), iter)) }
, j { j }
{
if (not (i < chunks.size() and j < Capacity and chunks[i][j]))
if (not (i < chunks.size() and j < Capacity and chunks[i].test(j)))
{
operator ++();
}
Expand All @@ -141,7 +158,7 @@ inline namespace memory
{
for (; j < Capacity; ++j)
{
if (chunks[i][j])
if (chunks[i].test(j))
{
return *this;
}
Expand Down Expand Up @@ -179,7 +196,7 @@ inline namespace memory
{
for (; j < Capacity; --j)
{
if (chunks[i][j])
if (chunks[i].test(j))
{
return *this;
}
Expand Down Expand Up @@ -233,7 +250,7 @@ inline namespace memory
{
if (auto iter = lower_bound_chunk(p); iter != chunks.end() and iter->offset == p.offset())
{
(*iter)[p.index()] = true;
iter->set(p.index());
}
else
{
Expand All @@ -246,7 +263,7 @@ inline namespace memory
{
auto iter = lower_bound_chunk(p);
assert(iter != chunks.end());
(*iter)[p.index()] = false;
iter->reset(p.index());
}

auto begin() const noexcept
Expand Down

0 comments on commit c246d72

Please sign in to comment.