Skip to content

Commit

Permalink
Remove data member cache from class pointer_set
Browse files Browse the repository at this point in the history
Signed-off-by: yamacir-kit <[email protected]>
  • Loading branch information
yamacir-kit committed Jan 13, 2024
1 parent 5a93a8a commit 96fe91d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 34 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.110_amd64.deb
sudo apt install build/meevax_0.5.111_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.110.so` and executable `meevax`
| `all` | Build shared-library `libmeevax.0.5.111.so` and executable `meevax`
| `test` | Test executable `meevax`
| `package` | Generate debian package `meevax_0.5.110_amd64.deb`
| `package` | Generate debian package `meevax_0.5.111_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.110
0.5.111
40 changes: 10 additions & 30 deletions include/meevax/memory/pointer_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace meevax
inline namespace memory
{
template <typename Pointer,
template <typename...> typename Map = simple_flat_map,
template <typename...> typename OrderedMap = simple_flat_map,
template <std::size_t> typename Bitset = simple_bitset,
std::size_t N = 4096 * 8> // getconf PAGE_SIZE
class pointer_set
Expand Down Expand Up @@ -92,9 +92,7 @@ inline namespace memory
}
};

Map<std::size_t, chunk> chunks;

std::unordered_map<std::size_t, typename Map<std::size_t, chunk>::iterator> cache;
OrderedMap<std::size_t, chunk> chunks;

public:
struct iterator
Expand All @@ -109,14 +107,14 @@ inline namespace memory

using difference_type = std::ptrdiff_t;

Map<std::size_t, chunk> const& chunks;
OrderedMap<std::size_t, chunk> const& chunks;

typename Map<std::size_t, chunk>::const_iterator outer;
typename OrderedMap<std::size_t, chunk>::const_iterator outer;

typename chunk::const_iterator inner;

explicit iterator(Map<std::size_t, chunk> const& chunks,
typename Map<std::size_t, chunk>::const_iterator outer,
explicit iterator(OrderedMap<std::size_t, chunk> const& chunks,
typename OrderedMap<std::size_t, chunk>::const_iterator outer,
std::size_t hint)
: chunks { chunks }
, outer { outer }
Expand All @@ -129,7 +127,7 @@ inline namespace memory
}
}

explicit iterator(Map<std::size_t, chunk> const& chunks)
explicit iterator(OrderedMap<std::size_t, chunk> const& chunks)
: chunks { chunks }
, outer { chunks.end() }
, inner {}
Expand Down Expand Up @@ -240,45 +238,27 @@ inline namespace memory
assert(begin() == end());
}

auto chunks_lower_bound(std::size_t offset)
{
if (auto iter = cache.find(offset); iter != cache.end())
{
return iter->second;
}
else if (auto iter = chunks.lower_bound(offset); iter != chunks.end())
{
cache.emplace(iter->first, iter);
return iter;
}
else
{
return iter;
}
}

auto size() const -> std::size_t
{
return std::distance(begin(), end());
}

auto insert(compact_pointer p)
{
if (auto iter = chunks_lower_bound(p.offset()); iter != chunks.end() and iter->first == p.offset())
if (auto iter = chunks.lower_bound(p.offset()); iter != chunks.end() and iter->first == p.offset())
{
iter->second.set(p.index());
}
else
{
assert(iter == chunks.end() or p.offset() < iter->first);
chunks.emplace_hint(iter, p.offset(), p.index());
cache.clear();
}
}

auto erase(compact_pointer p)
{
auto iter = chunks_lower_bound(p.offset());
auto iter = chunks.lower_bound(p.offset());
assert(iter != chunks.end());
iter->second.reset(p.index());
}
Expand All @@ -295,7 +275,7 @@ inline namespace memory

auto lower_bound(compact_pointer p)
{
if (auto iter = chunks_lower_bound(p.offset()); iter != chunks.end())
if (auto iter = chunks.lower_bound(p.offset()); iter != chunks.end())
{
return iterator(chunks, iter, p.index());
}
Expand Down

0 comments on commit 96fe91d

Please sign in to comment.