Class NeighborsView¶
template <typename TSeq>
Non-allocating range over an agent's neighbors. More...
#include <agent-bones.hpp>
Classes¶
| Type | Name |
|---|---|
| class | iterator |
Public Functions¶
| Type | Name |
|---|---|
| NeighborsView () = default |
|
| NeighborsView (const size_t * first, size_t n, std::vector< Agent< TSeq > > * pop) |
|
| Agent< TSeq > * | agent (size_t k) const |
| iterator | begin () const |
| bool | empty () const |
| iterator | end () const |
| size_t | id (size_t k) const |
| const size_t * | ids () const |
| size_t | size () const |
Detailed Description¶
Agent::get_neighbors() builds and returns a std::vector of pointers, which costs a heap allocation on every call and it is called once per susceptible agent per day, in the innermost loop of every state-update function. This view iterates the agent's neighbor ids in place and resolves each one against the model's population as it goes, so the same loop runs without allocating:
The order is the agent's neighbor order, identical to get_neighbors(). The view borrows from the agent and the model, so it must not outlive either, and it is invalidated by anything that changes the agent's ties.
Template parameters:
TSeqSequence type (should matchTSeqacross the model)
Public Functions Documentation¶
function NeighborsView [1/2]¶
function NeighborsView [2/2]¶
inline NeighborsView::NeighborsView (
const size_t * first,
size_t n,
std::vector< Agent < TSeq > > * pop
)
function agent¶
The k-th neighbor.
Exception:
std::out_of_rangeifk >= size().
function begin¶
function empty¶
function end¶
function id¶
Id of the k-th neighbor, without touching the neighbor's Agent.
Exception:
std::out_of_rangeifk >= size().
function ids¶
The ids of the size() neighbors, in order (like std::vector::data(): only valid for indices below size(); nullptr when there are none). For scans that must not touch the neighbors' Agents.
function size¶
The documentation for this class was generated from the following file include/epiworld/agent-bones.hpp