Skip to content

Commit

Permalink
Merge pull request #282 from LLNL/feature/boost_open_addressing_conta…
Browse files Browse the repository at this point in the history
…iner

Add Boost open-addressing set/map containers
  • Loading branch information
KIwabuchi authored Jun 20, 2023
2 parents a6a5e07 + 7b283e9 commit 63adaf1
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 1 deletion.
29 changes: 28 additions & 1 deletion example/metall_containers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@
#include <metall/container/priority_queue.hpp>
#include <metall/container/string.hpp>

// Boost 1.81 or later is required
#if BOOST_VERSION >= 108100
#include <metall/container/unordered_flat_map.hpp>
#include <metall/container/unordered_flat_set.hpp>
#endif

// Boost 1.82 or later is required
#if BOOST_VERSION >= 108200
#include <metall/container/unordered_node_map.hpp>
#include <metall/container/unordered_node_set.hpp>
#endif

using namespace metall;
namespace mc = metall::container;

Expand All @@ -33,14 +45,29 @@ int main() {
mg.construct<mc::set<int>>("set")(mg.get_allocator());
mg.construct<mc::multiset<int>>("multiset")(mg.get_allocator());

mg.construct<mc::unordered_map<int, int>>("umap")(mg.get_allocator());
mg.construct<mc::unordered_map<int, int>>("unordered_map")(
mg.get_allocator());
mg.construct<mc::unordered_multimap<int, int>>("unordered_multimap")(
mg.get_allocator());

mg.construct<mc::unordered_set<int>>("unordered_set")(mg.get_allocator());
mg.construct<mc::unordered_multiset<int>>("unordered_multiset")(
mg.get_allocator());

#if BOOST_VERSION >= 108100
mg.construct<mc::unordered_flat_map<int, int>>("unordered_flat_map")(
mg.get_allocator());
mg.construct<mc::unordered_flat_set<int>>("unordered_flat_set")(
mg.get_allocator());
#endif

#if BOOST_VERSION >= 108200
mg.construct<mc::unordered_node_map<int, int>>("unordered_node_map")(
mg.get_allocator());
mg.construct<mc::unordered_node_set<int>>("unordered_node_set")(
mg.get_allocator());
#endif

mg.construct<mc::vector<int>>("vector")(mg.get_allocator());

mg.construct<mc::stack<int>>("stack")(mg.get_allocator());
Expand Down
28 changes: 28 additions & 0 deletions include/metall/container/unordered_flat_map.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2023 Lawrence Livermore National Security, LLC and other Metall
// Project Developers. See the top-level COPYRIGHT file for details.
//
// SPDX-License-Identifier: (Apache-2.0 OR MIT)

#ifndef METALL_CONTAINER_UNORDERED_FLAT_MAP_HPP
#define METALL_CONTAINER_UNORDERED_FLAT_MAP_HPP

#include <functional>

static_assert(BOOST_VERSION >= 108100, "Unsupported Boost version");
#include <boost/unordered/unordered_flat_map.hpp>

#include <metall/metall.hpp>

namespace metall::container {

/// \brief An unordered_flat_map container that uses Metall as its default
/// allocator.
template <class Key, class T, class Hash = std::hash<Key>,
class KeyEqual = std::equal_to<Key>,
class Allocator = manager::allocator_type<std::pair<const Key, T>>>
using unordered_flat_map =
boost::unordered_flat_map<Key, T, Hash, KeyEqual, Allocator>;

} // namespace metall::container

#endif // METALL_CONTAINER_UNORDERED_FLAT_MAP_HPP
28 changes: 28 additions & 0 deletions include/metall/container/unordered_flat_set.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2023 Lawrence Livermore National Security, LLC and other Metall
// Project Developers. See the top-level COPYRIGHT file for details.
//
// SPDX-License-Identifier: (Apache-2.0 OR MIT)

#ifndef METALL_CONTAINER_UNORDERED_FLAT_SET_HPP
#define METALL_CONTAINER_UNORDERED_FLAT_SET_HPP

#include <functional>

static_assert(BOOST_VERSION >= 108100, "Unsupported Boost version");
#include <boost/unordered/unordered_flat_set.hpp>

#include <metall/metall.hpp>

namespace metall::container {

/// \brief An unordered_flat_set container that uses Metall as its default
/// allocator.
template <class Key, class Hash = std::hash<Key>,
class KeyEqual = std::equal_to<Key>,
class Allocator = manager::allocator_type<Key>>
using unordered_flat_set =
boost::unordered_flat_set<Key, Hash, KeyEqual, Allocator>;

} // namespace metall::container

#endif // METALL_CONTAINER_UNORDERED_FLAT_SET_HPP
28 changes: 28 additions & 0 deletions include/metall/container/unordered_node_map.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2023 Lawrence Livermore National Security, LLC and other Metall
// Project Developers. See the top-level COPYRIGHT file for details.
//
// SPDX-License-Identifier: (Apache-2.0 OR MIT)

#ifndef METALL_CONTAINER_UNORDERED_NODE_MAP_HPP
#define METALL_CONTAINER_UNORDERED_NODE_MAP_HPP

#include <functional>

static_assert(BOOST_VERSION >= 108200, "Unsupported Boost version");
#include <boost/unordered/unordered_node_map.hpp>

#include <metall/metall.hpp>

namespace metall::container {

/// \brief An unordered_node_map container that uses Metall as its default
/// allocator.
template <class Key, class T, class Hash = std::hash<Key>,
class KeyEqual = std::equal_to<Key>,
class Allocator = manager::allocator_type<std::pair<const Key, T>>>
using unordered_node_map =
boost::unordered_node_map<Key, T, Hash, KeyEqual, Allocator>;

} // namespace metall::container

#endif // METALL_CONTAINER_UNORDERED_NODE_MAP_HPP
28 changes: 28 additions & 0 deletions include/metall/container/unordered_node_set.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2023 Lawrence Livermore National Security, LLC and other Metall
// Project Developers. See the top-level COPYRIGHT file for details.
//
// SPDX-License-Identifier: (Apache-2.0 OR MIT)

#ifndef METALL_CONTAINER_UNORDERED_NODE_SET_HPP
#define METALL_CONTAINER_UNORDERED_NODE_SET_HPP

#include <functional>

static_assert(BOOST_VERSION >= 108200, "Unsupported Boost version");
#include <boost/unordered/unordered_node_set.hpp>

#include <metall/metall.hpp>

namespace metall::container {

/// \brief An unordered_node_set container that uses Metall as its default
/// allocator.
template <class Key, class Hash = std::hash<Key>,
class KeyEqual = std::equal_to<Key>,
class Allocator = manager::allocator_type<Key>>
using unordered_node_set =
boost::unordered_node_set<Key, Hash, KeyEqual, Allocator>;

} // namespace metall::container

#endif // METALL_CONTAINER_UNORDERED_NODE_SET_HPP

0 comments on commit 63adaf1

Please sign in to comment.