Simulation Domain

Header: fiction/technology/sidb/simulation/domain.hpp

template<typename Key, typename ...MappedTypes>
class domain

The domain is designed to represent a generic simulation domain where keys are associated with values stored as tuples. It uses a locked_parallel_flat_hash_map to 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 domain()

Constructs a new domain instance.

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_emplace method.

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:

true if the operational domain is empty, false otherwise.

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_contains method 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::nullopt otherwise.