Skip to content

File postsampling-bones.hpp

File List > epiworld > postsampling-bones.hpp

Go to the documentation of this file

#ifndef EPIWORLD_POSTSAMPLING_BONES_HPP
#define EPIWORLD_POSTSAMPLING_BONES_HPP

#include <cstdint>
#include <cstddef>
#include <functional>
#include <vector>

template<typename TSeq> class Agent;
template<typename TSeq> class Model;

class SampledContactsView {
private:
    const uint32_t * first = nullptr;
    size_t n = 0u;
public:
    SampledContactsView() = default;
    SampledContactsView(const uint32_t * first_, size_t n_) : first(first_), n(n_) {}
    const uint32_t * begin() const { return first; }
    const uint32_t * end() const { return first + n; }
    size_t size() const { return n; }
    bool empty() const { return n == 0u; }
    size_t operator[](size_t i) const { return first[i]; }
};

template<typename TSeq>
using PostSamplingFun = std::function<
    void(Agent<TSeq> *, const SampledContactsView &, Model<TSeq> *)
>;

struct PostSamplingScratch {

    std::vector< uint32_t > pairs;    
    std::vector< uint32_t > grouped;  
    std::vector< uint32_t > touched;  
    std::vector< size_t > starts;     
    std::vector< uint32_t > counts;   

    PostSamplingScratch() = default;
    PostSamplingScratch(const PostSamplingScratch &) {}
    PostSamplingScratch & operator=(const PostSamplingScratch &) { reset(0u); return *this; }

    void clear()
    {
        for (auto id : touched)
            counts[id] = 0u;
        pairs.clear();
        grouped.clear();
        touched.clear();
        starts.clear();
    }

    void reset(size_t n_agents)
    {
        pairs.clear();
        grouped.clear();
        touched.clear();
        starts.clear();
        counts.assign(n_agents, 0u);
    }

};

#endif