Simulation Domain¶
Header: fiction/technology/sidb/simulation/domain.hpp
-
template<typename Key, typename ...MappedTypes>
class domain¶ The
domainis designed to represent a generic simulation domain where keys are associated with values stored as tuples. It uses alocked_parallel_flat_hash_mapto ensure thread-safe access to the stored data. All methods of this class are thread-safe.- Template Parameters:
Key – The type of the key used to identify entries in the domain.
MappedTypes – Value types stored in the tuple.
Public Functions
-
inline void add_value(const Key &key, const std::tuple<MappedTypes...> &value)¶
Adds a value to the operational domain. This function is thread-safe and uses the
try_emplacemethod.- Parameters:
key – The key to associate with the value.
value – The value to add, which must be a tuple.
-
inline std::size_t size() const¶
Counts the number of key-value pairs in the operational domain.
- Returns:
The size of the operational domain.
-
inline bool empty() const noexcept¶
Checks whether the operational domain is empty.
- Returns:
trueif the operational domain is empty,falseotherwise.
-
template<typename Fn>
inline void for_each(Fn &&fn) const¶ Applies a callable to all key-value pairs in the container. For thread-safety, this function operates on a copy of the underlying map created at the time of the function call.
- Template Parameters:
Fn – Functor type.
- Parameters:
fn – Functor to apply to each key-value pair.
-
inline std::optional<std::tuple<MappedTypes...>> contains(const Key &key) const¶
Checks whether a specified key exists in the given map and retrieves its associated value if present. This function utilizes the
if_containsmethod of the map to ensure thread-safe access.- Parameters:
key – The key to search for in the map.
- Returns:
The value associated with the key if it exists,
std::nulloptotherwise.