Skip to content

Class NeighborsView

template <typename TSeq>

ClassList > NeighborsView

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)
iterator begin () const
bool empty () const
iterator end () 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:

for (auto * neighbor : p->neighbors_view(*m))
    ...

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:

  • TSeq Sequence type (should match TSeq across the model)

Public Functions Documentation

function NeighborsView [1/2]

NeighborsView::NeighborsView () = default

function NeighborsView [2/2]

inline NeighborsView::NeighborsView (
    const  size_t * first,
    size_t n,
    std::vector< Agent < TSeq > > * pop
) 

function begin

inline iterator NeighborsView::begin () const

function empty

inline bool NeighborsView::empty () const

function end

inline iterator NeighborsView::end () const

function size

inline size_t NeighborsView::size () const


The documentation for this class was generated from the following file include/epiworld/agent-bones.hpp