Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.24)
project(dice-sparse-map
VERSION 0.2.11
DESCRIPTION "C++ implementation of a memory efficient hash map and hash set based on [tsl::sparse_map](https://github.com/Tessil/sparse-map). We added support for fancy pointers.")
set(POBR_VERSION 1) # Persisted Object Binary Representation Version
set(POBR_VERSION 2) # Persisted Object Binary Representation Version

include(cmake/boilerplate_init.cmake)
boilerplate_init()
Expand Down
1 change: 1 addition & 0 deletions cmake/boilerplate_init.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
macro(boilerplate_init)
## enforce standard compliance
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_EXTENSIONS OFF)

Expand Down
1 change: 0 additions & 1 deletion doxygen.conf
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,6 @@ EXCLUDE_PATTERNS =
EXCLUDE_SYMBOLS = \
tsl::detail_popcount::* \
tsl::detail_sparse_hash::has_is_transparent* \
tsl::detail_sparse_hash::make_void* \
tsl::detail_sparse_hash::is_power_of_two_policy* \
tsl::detail_sparse_hash::sparse_array*

Expand Down
355 changes: 84 additions & 271 deletions include/dice/sparse-map/sparse_hash.hpp

Large diffs are not rendered by default.

93 changes: 36 additions & 57 deletions include/dice/sparse-map/sparse_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ namespace dice::sparse_map {
dice::sparse_map::sh::sparsity Sparsity = dice::sparse_map::sh::sparsity::medium>
class sparse_map {
private:
template<typename U>
using has_is_transparent = dice::sparse_map::detail_sparse_hash::has_is_transparent<U>;

class KeySelect {
public:
using key_type = Key;
Expand Down Expand Up @@ -391,9 +388,8 @@ namespace dice::sparse_map {
* `KeyEqual::is_transparent` exists. If so, `K` must be hashable and
* comparable to `Key`.
*/
template<
class K, class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
template<class K>
requires (detail_sparse_hash::has_is_transparent<KeyEqual>)
size_type erase(K const &key) {
return m_ht.erase(key);
}
Expand All @@ -406,9 +402,8 @@ namespace dice::sparse_map {
* behaviour is undefined. Useful to speed-up the lookup if you already have
* the hash.
*/
template<
class K, class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
template<class K>
requires (detail_sparse_hash::has_is_transparent<KeyEqual>)
size_type erase(K const &key, std::size_t precalculated_hash) {
return m_ht.erase(key, precalculated_hash);
}
Expand Down Expand Up @@ -450,9 +445,8 @@ namespace dice::sparse_map {
* `KeyEqual::is_transparent` exists. If so, `K` must be hashable and
* comparable to `Key`.
*/
template<
class K, class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
template<class K>
requires (detail_sparse_hash::has_is_transparent<KeyEqual>)
T &at(K const &key) {
return m_ht.at(key);
}
Expand All @@ -465,29 +459,26 @@ namespace dice::sparse_map {
* behaviour is undefined. Useful to speed-up the lookup if you already have
* the hash.
*/
template<
class K, class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
template<class K>
requires (detail_sparse_hash::has_is_transparent<KeyEqual>)
T &at(K const &key, std::size_t precalculated_hash) {
return m_ht.at(key, precalculated_hash);
}

/**
* @copydoc at(const K& key)
*/
template<
class K, class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
template<class K>
requires (detail_sparse_hash::has_is_transparent<KeyEqual>)
T const &at(K const &key) const {
return m_ht.at(key);
}

/**
* @copydoc at(const K& key, std::size_t precalculated_hash)
*/
template<
class K, class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
template<class K>
requires (detail_sparse_hash::has_is_transparent<KeyEqual>)
T const &at(K const &key, std::size_t precalculated_hash) const {
return m_ht.at(key, precalculated_hash);
}
Expand Down Expand Up @@ -518,9 +509,8 @@ namespace dice::sparse_map {
* `KeyEqual::is_transparent` exists. If so, `K` must be hashable and
* comparable to `Key`.
*/
template<
class K, class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
template<class K>
requires (detail_sparse_hash::has_is_transparent<KeyEqual>)
size_type count(K const &key) const {
return m_ht.count(key);
}
Expand All @@ -533,9 +523,8 @@ namespace dice::sparse_map {
* behaviour is undefined. Useful to speed-up the lookup if you already have
* the hash.
*/
template<
class K, class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
template<class K>
requires (detail_sparse_hash::has_is_transparent<KeyEqual>)
size_type count(K const &key, std::size_t precalculated_hash) const {
return m_ht.count(key, precalculated_hash);
}
Expand Down Expand Up @@ -570,9 +559,8 @@ namespace dice::sparse_map {
* `KeyEqual::is_transparent` exists. If so, `K` must be hashable and
* comparable to `Key`.
*/
template<
class K, class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
template<class K>
requires (detail_sparse_hash::has_is_transparent<KeyEqual>)
iterator find(K const &key) {
return m_ht.find(key);
}
Expand All @@ -585,19 +573,17 @@ namespace dice::sparse_map {
* behaviour is undefined. Useful to speed-up the lookup if you already have
* the hash.
*/
template<
class K, class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
template<class K>
requires (detail_sparse_hash::has_is_transparent<KeyEqual>)
iterator find(K const &key, std::size_t precalculated_hash) {
return m_ht.find(key, precalculated_hash);
}

/**
* @copydoc find(const K& key)
*/
template<
class K, class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
template<class K>
requires (detail_sparse_hash::has_is_transparent<KeyEqual>)
const_iterator find(K const &key) const {
return m_ht.find(key);
}
Expand All @@ -610,9 +596,8 @@ namespace dice::sparse_map {
* behaviour is undefined. Useful to speed-up the lookup if you already have
* the hash.
*/
template<
class K, class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
template<class K>
requires (detail_sparse_hash::has_is_transparent<KeyEqual>)
const_iterator find(K const &key, std::size_t precalculated_hash) const {
return m_ht.find(key, precalculated_hash);
}
Expand All @@ -635,9 +620,8 @@ namespace dice::sparse_map {
* KeyEqual::is_transparent exists. If so, K must be hashable and comparable
* to Key.
*/
template<
class K, class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
template<class K>
requires (detail_sparse_hash::has_is_transparent<KeyEqual>)
bool contains(K const &key) const {
return m_ht.contains(key);
}
Expand All @@ -649,9 +633,8 @@ namespace dice::sparse_map {
* hash value should be the same as hash_function()(key). Useful to speed-up
* the lookup if you already have the hash.
*/
template<
class K, class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
template<class K>
requires (detail_sparse_hash::has_is_transparent<KeyEqual>)
bool contains(K const &key, std::size_t precalculated_hash) const {
return m_ht.contains(key, precalculated_hash);
}
Expand Down Expand Up @@ -688,9 +671,8 @@ namespace dice::sparse_map {
* `KeyEqual::is_transparent` exists. If so, `K` must be hashable and
* comparable to `Key`.
*/
template<
class K, class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
template<class K>
requires (detail_sparse_hash::has_is_transparent<KeyEqual>)
std::pair<iterator, iterator> equal_range(K const &key) {
return m_ht.equal_range(key);
}
Expand All @@ -703,9 +685,8 @@ namespace dice::sparse_map {
* behaviour is undefined. Useful to speed-up the lookup if you already have
* the hash.
*/
template<
class K, class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
template<class K>
requires (detail_sparse_hash::has_is_transparent<KeyEqual>)
std::pair<iterator, iterator> equal_range(K const &key,
std::size_t precalculated_hash) {
return m_ht.equal_range(key, precalculated_hash);
Expand All @@ -714,19 +695,17 @@ namespace dice::sparse_map {
/**
* @copydoc equal_range(const K& key)
*/
template<
class K, class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
template<class K>
requires (detail_sparse_hash::has_is_transparent<KeyEqual>)
std::pair<const_iterator, const_iterator> equal_range(K const &key) const {
return m_ht.equal_range(key);
}

/**
* @copydoc equal_range(const K& key, std::size_t precalculated_hash)
*/
template<
class K, class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
template<class K>
requires (detail_sparse_hash::has_is_transparent<KeyEqual>)
std::pair<const_iterator, const_iterator> equal_range(
K const &key, std::size_t precalculated_hash) const {
return m_ht.equal_range(key, precalculated_hash);
Expand Down
Loading