template<typename TResult = uint64_t>
struct bdm::experimental::Counter< TResult >
Provides functions to count the number of agents for which the given condition is true.
The following code example demonstrates how to count all agents with diameter < 5
.
auto diam_lt_5 = [](Agent* agent) {
return agent->GetDiameter() < 5;
};
Counter<> counter(diam_lt_5);
rm->ForEachAgentParallel(counter);
auto result = counter.GetResult();
The counting result can be post processed. Let's assume we want to divide the counting result by two:
auto diam_lt_5 = [](Agent* agent) {
return agent->GetDiameter() < 5;
};
auto post_process = [](uint64_t result) { return result / 2; };
Counter<> counter(diam_lt_5, post_process);
rm->ForEachAgentParallel(counter);
auto result = counter.GetResult();
The benefit in comparison with bdm::experimental::Count
is that multiple counters can be combined and processed in one sweep over all agents.
- See also
- bdm::experimental::Reducer`
Definition at line 235 of file reduce.h.