![]() |
Shamrock 2025.10.0
Astrophysical Code
|
Represents a collection of objects distributed across patches identified by a u64 id. More...
#include <shambase/include/shambase/DistributedData.hpp>
Public Member Functions | |
| std::map< u64, T > & | get_native () |
| Returns the underlying collection. | |
| iterator | add_obj (u64 id, T &&obj) |
| Adds a new object to the collection. | |
| void | erase (u64 id) |
| Removes an object from the collection. | |
| void | for_each (std::function< void(u64, T &)> &&f) |
| Applies a function to each object in the collection. | |
| void | for_each (std::function< void(u64, const T &)> &&f) const |
| Same as for_each but for const objects. | |
| std::vector< u64 > | get_ids () const |
| Returns a vector of all the ids of the objects in the collection. | |
| auto | find (u64 id) |
| Finds an object in the collection. | |
| auto | not_found () |
| Returns an iterator pointing to the end of the collection. | |
| T & | get (u64 id) |
| Returns a reference to an object in the collection. | |
| const T & | get (u64 id) const |
| Const variant of get. | |
| bool | has_key (u64 id) |
| Checks if an object exists in the collection. | |
| u64 | get_element_count () |
| Returns the number of elements in the collection. | |
| bool | is_empty () |
| Returns true if the collection is empty. | |
| template<typename... Tf> | |
| void | print_data (fmt::format_string< Tf... > fmt) const |
| Prints all the objects in the collection to the logger. | |
| template<class Tmap > | |
| DistributedData< Tmap > | map (std::function< Tmap(u64, T &)> map_func) |
| Apply a function to all objects in the collection and return a new collection containing the results. | |
| template<class Tmap > | |
| DistributedData< Tmap > | map (std::function< Tmap(u64, const T &)> map_func) const |
| Same as map but for const objects. | |
| void | reset () |
| Reset the collection to its initial state. | |
Represents a collection of objects distributed across patches identified by a u64 id.
This class provides methods for managing the distributed data collection, including adding, removing, finding, and iterating over elements. It also supports mapping the collection to a new type using a user-defined mapping function.
| T | The type of the object in the collection. |
Definition at line 43 of file DistributedData.hpp.
|
inline |
Adds a new object to the collection.
| id | The id of the patch the object belongs to. |
| obj | The object to add. |
| If | the key already exist. |
Definition at line 67 of file DistributedData.hpp.
Here is the call graph for this function:
|
inline |
Removes an object from the collection.
| id | The id of the patch the object belongs to. |
Definition at line 83 of file DistributedData.hpp.
|
inline |
Finds an object in the collection.
| id | The id of the patch the object belongs to. |
Definition at line 127 of file DistributedData.hpp.
|
inline |
Same as for_each but for const objects.
Definition at line 100 of file DistributedData.hpp.
Here is the call graph for this function:
|
inline |
Applies a function to each object in the collection.
| f | A function taking two arguments: the id of the patch the object belongs to, and a non-const reference to the object itself. |
Definition at line 93 of file DistributedData.hpp.
Here is the call graph for this function:
|
inline |
Returns a reference to an object in the collection.
| id | The id of the patch the object belongs to. |
| If | the object is not found. |
Definition at line 145 of file DistributedData.hpp.
Here is the call graph for this function:
|
inline |
Const variant of get.
Definition at line 162 of file DistributedData.hpp.
Here is the call graph for this function:
|
inline |
Returns the number of elements in the collection.
Definition at line 192 of file DistributedData.hpp.
|
inline |
Returns a vector of all the ids of the objects in the collection.
Definition at line 111 of file DistributedData.hpp.
Here is the call graph for this function:
|
inline |
Returns the underlying collection.
Definition at line 55 of file DistributedData.hpp.
|
inline |
Checks if an object exists in the collection.
| id | The id of the patch the object belongs to. |
Definition at line 185 of file DistributedData.hpp.
|
inline |
Returns true if the collection is empty.
Definition at line 199 of file DistributedData.hpp.
|
inline |
Same as map but for const objects.
Definition at line 263 of file DistributedData.hpp.
Here is the call graph for this function:
|
inline |
Apply a function to all objects in the collection and return a new collection containing the results.
The map() function applies the given function to each object in the collection and stores the result in a new collection. The function is passed the id of the object and a reference to the object as arguments.
Example:
| Tmap | Type of the objects in the returned collection. |
| map_func | The function to apply to each object. |
Definition at line 251 of file DistributedData.hpp.
Here is the call graph for this function:
|
inline |
Returns an iterator pointing to the end of the collection.
Definition at line 134 of file DistributedData.hpp.
|
inline |
Prints all the objects in the collection to the logger.
The format string is passed to fmt::format to format each object, so the syntax is the same as fmt::format. The object is passed as the second argument to fmt::format.
Example:
| Tf | Types of the format string placeholders. |
| fmt | The format string. |
Definition at line 220 of file DistributedData.hpp.
Here is the call graph for this function:
|
inline |
Reset the collection to its initial state.
All objects in the collection are removed.
Definition at line 278 of file DistributedData.hpp.