Skip to content

Commit

Permalink
Rename CustomHashSetWithMemoryLimit to NodeHashSetWithMemoryLimit
Browse files Browse the repository at this point in the history
…. Change the default template argument of `SizeGetter` from `SizeOfSizeGetter` to `DefaultValueSizeGetter`.
  • Loading branch information
s1dharth-s committed Nov 11, 2024
1 parent 71d7075 commit 2067fb3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/engine/LocalVocab.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class LocalVocab {
// `LiteralOrIri`) to remain stable over their lifetime in the hash map
// because we hand out pointers to them.
using Set =
ad_utility::CustomHashSetWithMemoryLimit<LiteralOrIri, IriSizeGetter>;
ad_utility::NodeHashSetWithMemoryLimit<LiteralOrIri, IriSizeGetter>;
ad_utility::detail::AllocationMemoryLeftThreadsafe limit_;
std::shared_ptr<Set> primaryWordSet_;

Expand Down
12 changes: 6 additions & 6 deletions src/util/HashSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "util/AllocatorWithLimit.h"
#include "util/DefaultValueSizeGetter.h"
#include "util/MemorySize/MemorySize.h"
#include "util/ValueSizeGetters.h"

using std::string;

Expand All @@ -43,10 +44,10 @@ using HashSetWithMemoryLimit =
// Wrapper around absl::node_hash_set with a memory limit. All operations that
// may change the allocated memory of the hash set is tracked using a
// `AllocationMemoryLeftThreadsafe` object.
template <class T, class SizeGetter = SizeOfSizeGetter,
template <class T, class SizeGetter = DefaultValueSizeGetter<T>,
class HashFct = absl::container_internal::hash_default_hash<T>,
class EqualElem = absl::container_internal::hash_default_eq<T>>
class CustomHashSetWithMemoryLimit {
class NodeHashSetWithMemoryLimit {
private:
using HashSet = absl::node_hash_set<T, HashFct, EqualElem>;
HashSet hashSet_;
Expand All @@ -70,9 +71,8 @@ class CustomHashSetWithMemoryLimit {
constexpr static size_t slotMemoryCost = sizeof(void*) + 1;

public:
CustomHashSetWithMemoryLimit(
detail::AllocationMemoryLeftThreadsafe memoryLeft,
SizeGetter sizeGetter = {})
NodeHashSetWithMemoryLimit(detail::AllocationMemoryLeftThreadsafe memoryLeft,
SizeGetter sizeGetter = {})
: memoryLeft_{memoryLeft},
memoryUsed_{MemorySize::bytes(0)},
sizeGetter_{sizeGetter},
Expand All @@ -82,7 +82,7 @@ class CustomHashSetWithMemoryLimit {
updateSlotArrayMemoryUsage();
}

~CustomHashSetWithMemoryLimit() { decreaseMemoryUsed(memoryUsed_); }
~NodeHashSetWithMemoryLimit() { decreaseMemoryUsed(memoryUsed_); }

// Try to allocate the amount of memory requested
void increaseMemoryUsed(ad_utility::MemorySize amount) {
Expand Down
4 changes: 2 additions & 2 deletions test/CustomHashSetWithMemoryLimitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using ad_utility::makeAllocationMemoryLeftThreadsafeObject;
using namespace ad_utility::memory_literals;

using Set = ad_utility::CustomHashSetWithMemoryLimit<int>;
using Set = ad_utility::NodeHashSetWithMemoryLimit<int>;

TEST(CustomHashSetWithMemoryLimitTest, sizeAndInsert) {
Set hashSet{makeAllocationMemoryLeftThreadsafeObject(100_B)};
Expand Down Expand Up @@ -142,7 +142,7 @@ struct StringSizeGetter {
};

using StringSet =
ad_utility::CustomHashSetWithMemoryLimit<std::string, StringSizeGetter>;
ad_utility::NodeHashSetWithMemoryLimit<std::string, StringSizeGetter>;

TEST(CustomHashSetWithMemoryLimitTest, stringInsertAndMemoryTracking) {
StringSet hashSet{makeAllocationMemoryLeftThreadsafeObject(1000_B)};
Expand Down

0 comments on commit 2067fb3

Please sign in to comment.