Skip to content

Commit

Permalink
feat: drop dependency on Sparsehash if it is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSeemaier committed Jul 19, 2024
1 parent 1822293 commit 0ac838d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,11 @@ message(" dist::BlockWeight = std::int64_t")
################################################################################

# Google Sparsehash
find_package(Sparsehash REQUIRED)
find_package(Sparsehash)
if (Sparsehash_FOUND)
message(STATUS "Found Google Sparsehash")
list(APPEND KAMINPAR_DEFINITIONS "-DKAMINPAR_SPARSEHASH_FOUND")
endif ()

if (KAMINPAR_BUILD_WITH_CCACHE)
find_program(CCACHE_PROGRAM ccache)
Expand Down
24 changes: 16 additions & 8 deletions kaminpar-common/datastructures/rating_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
******************************************************************************/
#pragma once

#ifdef KAMINPAR_SPARSEHASH_FOUND
#include <google/dense_hash_map>
#endif

#include <unordered_map>

#include "kaminpar-common/datastructures/fast_reset_array.h"
Expand All @@ -24,12 +27,8 @@ using FastResetArray = ::kaminpar::FastResetArray<Value, Key>;

template <typename Key, typename Value> using SparseMap = ::kaminpar::SparseMap<Key, Value>;

template <typename Key, typename Value> class Sparsehash {
template <typename Key, typename Value> class UnorderedMap {
public:
Sparsehash() {
map.set_empty_key(std::numeric_limits<Key>::max());
}

Value &operator[](const Key key) {
return map[key];
}
Expand All @@ -49,11 +48,16 @@ template <typename Key, typename Value> class Sparsehash {
void resize(std::size_t) {}

private:
google::dense_hash_map<Key, Value> map;
std::unordered_map<Key, Value> map;
};

template <typename Key, typename Value> class UnorderedMap {
#ifdef KAMINPAR_SPARSEHASH_FOUND
template <typename Key, typename Value> class Sparsehash {
public:
Sparsehash() {
map.set_empty_key(std::numeric_limits<Key>::max());
}

Value &operator[](const Key key) {
return map[key];
}
Expand All @@ -73,8 +77,12 @@ template <typename Key, typename Value> class UnorderedMap {
void resize(std::size_t) {}

private:
std::unordered_map<Key, Value> map;
google::dense_hash_map<Key, Value> map;
};
#else
// @todo decide whether we want this silent fallback or trigger an error
template <typename Key, typename Value> using Sparsehash = SparseMap<Key, Value>;
#endif
} // namespace rm_backyard

template <
Expand Down
6 changes: 5 additions & 1 deletion kaminpar-shm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ file(GLOB_RECURSE KAMINPAR_SHM_SOURCE_FILES CONFIGURE_DEPENDS

add_library(kaminpar_shm ${KAMINPAR_SHM_SOURCE_FILES})
target_include_directories(kaminpar_shm PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../")
target_link_libraries(kaminpar_shm PUBLIC kaminpar_common Sparsehash::Sparsehash)
target_link_libraries(kaminpar_shm PUBLIC kaminpar_common)

if (Sparsehash_FOUND)
target_link_libraries(kaminpar_shm PUBLIC Sparsehash::Sparsehash)
endif ()

# If we can find Mt-KaHyPar, make it available as an option for refinement
if (KAMINPAR_BUILD_WITH_MTKAHYPAR)
Expand Down
9 changes: 9 additions & 0 deletions kaminpar-shm/refinement/gains/dense_gain_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
******************************************************************************/
#pragma once

#ifdef KAMINPAR_SPARSEHASH_FOUND
#include <google/dense_hash_map>
#else // KAMINPAR_SPARSEHASH_FOUND
#include <unordered_map>
#endif // KAMINPAR_SPARSEHASH_FOUND

#include <limits>
#include <vector>

Expand Down Expand Up @@ -729,6 +734,10 @@ template <typename _DeltaPartitionedGraph, typename _GainCache> class LargeKDens
BlockID _k;
const GainCache &_gain_cache;
DynamicFlatMap<std::size_t, EdgeWeight> _gain_cache_delta;
#ifdef KAMINPAR_SPARSEHASH_FOUND
google::dense_hash_map<NodeID, std::vector<BlockID>> _adjacent_blocks_delta;
#else // KAMINPAR_SPARSEHASH_FOUND
std::unordered_map<NodeID, std::vector<BlockID>> _adjacent_blocks_delta;
#endif // KAMINPAR_SPARSEHASH_FOUND
};
} // namespace kaminpar::shm

0 comments on commit 0ac838d

Please sign in to comment.