Skip to content

Commit

Permalink
Merge pull request #227 from arximboldi/fix-debug-stats
Browse files Browse the repository at this point in the history
Fix debug stats
  • Loading branch information
arximboldi authored Aug 16, 2022
2 parents d98e82d + 0e07630 commit 006461c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
21 changes: 13 additions & 8 deletions immer/detail/hamts/champ.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,26 @@ struct champ_debug_stats
100. * (value_count * value_size + child_count * child_size) /
(capacity * value_size + capacity * child_size);

auto value_capacity = m * inner_node_w_value_count;
auto child_capacity = m * inner_node_w_child_count;
auto dense_child_utilization = 100. * child_count / child_capacity;
auto dense_value_utilization = 100. * value_count / value_capacity;
auto value_capacity = m * inner_node_w_value_count;
auto child_capacity = m * inner_node_w_child_count;
auto dense_child_utilization =
child_capacity == 0 ? 100. : 100. * child_count / child_capacity;
auto dense_value_utilization =
value_capacity == 0 ? 100. : 100. * value_count / value_capacity;
auto dense_utilization =
100. * (value_count * value_size + child_count * child_size) /
(value_capacity * value_size + child_capacity * child_size);
value_capacity + child_capacity == 0
? 100.
: 100. * (value_count * value_size + child_count * child_size) /
(value_capacity * value_size +
child_capacity * child_size);

return {collision_ratio,
utilization,
child_utilization,
value_utilization,
dense_utilization,
dense_child_utilization,
dense_value_utilization};
dense_value_utilization,
dense_child_utilization};
}
};
#endif
Expand Down
17 changes: 17 additions & 0 deletions test/map/generic.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,23 @@ TEST_CASE("equals and setting")
#endif
}

#if IMMER_DEBUG_STATS
TEST_CASE("debug stats")
{
{
std::cout
<< immer::map<int, int>{}.impl().get_debug_stats().get_summary();
}
{
immer::map<int, int> map;
for (int i = 0; i <= 10; i++) {
map = std::move(map).set(i, i);
}
std::cout << map.impl().get_debug_stats().get_summary();
}
}
#endif

TEST_CASE("iterator")
{
const auto N = 666u;
Expand Down

0 comments on commit 006461c

Please sign in to comment.