Skip to content

Commit

Permalink
Don't use absl for memory limited data structures.
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Kalmbach <[email protected]>
  • Loading branch information
joka921 committed Dec 18, 2024
1 parent 97c195a commit 9a0b981
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
12 changes: 9 additions & 3 deletions src/util/HashMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
#pragma once

#include <absl/container/flat_hash_map.h>
#include <util/AllocatorWithLimit.h>

#include <unordered_map>

#include "util/AllocatorWithLimit.h"

namespace ad_utility {
// Wrapper for HashMaps to be used everywhere throughout code for the semantic
Expand All @@ -15,10 +18,13 @@ namespace ad_utility {
template <typename... Ts>
using HashMap = absl::flat_hash_map<Ts...>;

// A HashMap with a memory limit.
// A HashMap with a memory limit. Note: We cannot use `absl::flat_hash_map`
// here, because it is inherently not exception safe, and the
// `AllocatorWithLimit` uses exceptions.
template <class K, class V,
class HashFct = absl::container_internal::hash_default_hash<K>,
class EqualElem = absl::container_internal::hash_default_eq<K>,
class Alloc = ad_utility::AllocatorWithLimit<std::pair<const K, V>>>
using HashMapWithMemoryLimit = HashMap<K, V, HashFct, EqualElem, Alloc>;
using HashMapWithMemoryLimit =
std::unordered_map<K, V, HashFct, EqualElem, Alloc>;
} // namespace ad_utility
10 changes: 5 additions & 5 deletions src/util/HashSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@

#pragma once

#include <string>
#include <unordered_set>

#include "absl/container/flat_hash_set.h"
#include "util/AllocatorWithLimit.h"

using std::string;

namespace ad_utility {
// Wrapper for HashSets (with elements of type T) to be used everywhere
// throughout code for the semantic search. This wrapper interface is not
Expand All @@ -25,11 +23,13 @@ template <class T,
using HashSet = absl::flat_hash_set<T, HashFct, EqualElem, Alloc>;

// A hash set (with elements of type T) with a memory Limit.
// Note: We cannot use `absl::flat_hash_set`
// here, because it is inherently not exception safe, and the
// `AllocatorWithLimit` uses exceptions.
template <class T,
class HashFct = absl::container_internal::hash_default_hash<T>,
class EqualElem = absl::container_internal::hash_default_eq<T>,
class Alloc = ad_utility::AllocatorWithLimit<T>>
using HashSetWithMemoryLimit =
absl::flat_hash_set<T, HashFct, EqualElem, Alloc>;
using HashSetWithMemoryLimit = std::unordered_set<T, HashFct, EqualElem, Alloc>;

} // namespace ad_utility
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ addLinkAndDiscoverTest(TextLimitOperationTest engine)

addLinkAndDiscoverTestSerial(QueryPlannerTest engine)

addLinkAndDiscoverTest(HashMapTest)
addLinkAndDiscoverTestNoLibs(HashMapTest)

addLinkAndDiscoverTest(HashSetTest)

Expand Down
2 changes: 1 addition & 1 deletion test/HashMapTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <utility>
#include <vector>

#include "../src/util/HashMap.h"
#include "util/HashMap.h"

// Note: Since the HashMap class is a wrapper for a well tested hash map
// implementation the following tests only check the API for functionality and
Expand Down

0 comments on commit 9a0b981

Please sign in to comment.