phylopomp
Phylodynamics for POMPs
Loading...
Searching...
No Matches
inventory_t< NDEME > Class Template Reference

Implementation of the inventory process. More...

#include <inventory.h>

Collaboration diagram for inventory_t< NDEME >:

Public Member Functions

 inventory_t (void)=default
 basic constructor for inventory class
 
 inventory_t (raw_t *o)
 constructor from serialized binary form
 
 inventory_t (const inventory_t &)=default
 copy constructor
 
 inventory_t (inventory_t &&)=delete
 move constructor
 
 inventory_t (const genealogy_t &G)
 constructs an inventory from a genealogy
 
inventory_toperator= (const genealogy_t &G)
 copy an inventory from a genealogy
 
inventory_toperator= (const inventory_t &)=default
 copy assignment operator
 
inventory_toperator= (inventory_t &&)=delete
 move assignment operator
 
 ~inventory_t (void)
 destructor
 
size_t bytesize (void) const
 size of serialized binary form
 
size_t size (void) const
 
size_t size (name_t i) const
 size of deme
 
const pocket_toperator[] (const name_t i) const
 return the i-th deme
 
pocket_toperator[] (const name_t i)
 return the i-th deme
 
void insert (ball_t *b)
 
void erase (ball_t *b)
 
bool empty (void) const
 are all demes empty?
 
ball_trandom_ball (name_t i) const
 choose one random ball from deme i
 
pocket_trandom_balls (name_t i, int n=1) const
 choose a random set of n balls from deme i
 

Private Member Functions

void clean (void)
 memory cleanup
 
void clear (void)
 memory cleanup
 
const pocket_tinven (const name_t i) const
 access the i-th deme
 
pocket_tinven (const name_t i)
 access the i-th deme
 

Private Attributes

pocket_t _inven [ndeme]
 

Static Private Attributes

static const size_t ndeme = NDEME
 

Friends

raw_toperator>> (const inventory_t &I, raw_t *o)
 binary serialization
 
raw_toperator>> (raw_t *o, inventory_t &I)
 binary deserialization
 

Detailed Description

template<size_t NDEME>
class inventory_t< NDEME >

Implementation of the inventory process.

An inventory consists of an array of demes. Each deme is a set of black balls.

Definition at line 18 of file inventory.h.

Constructor & Destructor Documentation

◆ inventory_t() [1/5]

template<size_t NDEME>
inventory_t< NDEME >::inventory_t ( void )
default

basic constructor for inventory class

Here is the caller graph for this function:

◆ inventory_t() [2/5]

template<size_t NDEME>
inventory_t< NDEME >::inventory_t ( raw_t * o)
inline

constructor from serialized binary form

Definition at line 31 of file inventory.h.

31 {
32 o >> *this;
33 };
Implementation of the inventory process.
Definition inventory.h:18

◆ inventory_t() [3/5]

template<size_t NDEME>
inventory_t< NDEME >::inventory_t ( const inventory_t< NDEME > & )
default

copy constructor

Here is the call graph for this function:

◆ inventory_t() [4/5]

template<size_t NDEME>
inventory_t< NDEME >::inventory_t ( inventory_t< NDEME > && )
delete

move constructor

Here is the call graph for this function:

◆ inventory_t() [5/5]

template<size_t NDEME>
inventory_t< NDEME >::inventory_t ( const genealogy_t & G)
inline

constructs an inventory from a genealogy

Definition at line 39 of file inventory.h.

39 {
40 assert(G.ndeme()==ndeme);
41 clean();
42 for (node_t *p : G) {
43 for (ball_t *b : *p) {
44 insert(b); // 'insert' checks color
45 }
46 }
47 };
void insert(ball_t *b)
Definition inventory.h:148
void clean(void)
memory cleanup
Definition inventory.h:71
static const size_t ndeme
Definition inventory.h:22
Here is the call graph for this function:

◆ ~inventory_t()

template<size_t NDEME>
inventory_t< NDEME >::~inventory_t ( void )
inline

destructor

Definition at line 64 of file inventory.h.

64 {
65 clean();
66 };
Here is the call graph for this function:

Member Function Documentation

◆ bytesize()

template<size_t NDEME>
size_t inventory_t< NDEME >::bytesize ( void ) const
inline

size of serialized binary form

Definition at line 84 of file inventory.h.

84 {
85 size_t s = 0;
86 for (size_t i = 0; i < ndeme; i++)
87 s += _inven[i].bytesize();
88 return s;
89 };
size_t bytesize(void) const
size of serialized binary form
Definition inventory.h:84
pocket_t _inven[ndeme]
Definition inventory.h:23
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clean()

template<size_t NDEME>
void inventory_t< NDEME >::clean ( void )
inlineprivate

memory cleanup

Definition at line 71 of file inventory.h.

71 {
72 clear();
73 };
void clear(void)
memory cleanup
Definition inventory.h:75
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear()

template<size_t NDEME>
void inventory_t< NDEME >::clear ( void )
inlineprivate

memory cleanup

Definition at line 75 of file inventory.h.

75 {
76 for (size_t i = 0; i < ndeme; i++)
77 _inven[i].clear();
78 };
Here is the call graph for this function:
Here is the caller graph for this function:

◆ empty()

template<size_t NDEME>
bool inventory_t< NDEME >::empty ( void ) const
inline

are all demes empty?

Definition at line 163 of file inventory.h.

163 {
164 bool q = true;
165 for (name_t i = 0; i < ndeme; i++) {
166 q = q && _inven[i].empty();
167 }
168 return q;
169 };

◆ erase()

template<size_t NDEME>
void inventory_t< NDEME >::erase ( ball_t * b)
inline

remove a black ball from its deme. this checks the color of the ball. if it is not black, nothing is done.

Definition at line 156 of file inventory.h.

156 {
157 if (b->is(black)) {
158 assert(!inven(b->deme()).empty());
159 inven(b->deme()).erase(b);
160 }
161 };
const pocket_t & inven(const name_t i) const
access the i-th deme
Definition inventory.h:133
Here is the call graph for this function:

◆ insert()

template<size_t NDEME>
void inventory_t< NDEME >::insert ( ball_t * b)
inline

add a black ball to a deme. this checks the color of the ball. if it is not black, nothing is done.

Definition at line 148 of file inventory.h.

148 {
149 if (b->is(black)) {
150 inven(b->deme()).insert(b);
151 }
152 };
Here is the call graph for this function:
Here is the caller graph for this function:

◆ inven() [1/2]

template<size_t NDEME>
pocket_t & inventory_t< NDEME >::inven ( const name_t i)
inlineprivate

access the i-th deme

Definition at line 138 of file inventory.h.

138 {
139 assert(i > 0);
140 return _inven[i-1];
141 };

◆ inven() [2/2]

template<size_t NDEME>
const pocket_t & inventory_t< NDEME >::inven ( const name_t i) const
inlineprivate

access the i-th deme

Definition at line 133 of file inventory.h.

133 {
134 assert(i > 0);
135 return _inven[i-1];
136 };
Here is the caller graph for this function:

◆ operator=() [1/3]

template<size_t NDEME>
inventory_t & inventory_t< NDEME >::operator= ( const genealogy_t & G)
inline

copy an inventory from a genealogy

Definition at line 49 of file inventory.h.

49 {
50 assert(G.ndeme()==ndeme);
51 clean();
52 for (node_t *p : G) {
53 for (ball_t *b : *p) {
54 insert(b); // 'insert' checks color
55 }
56 }
57 return *this;
58 };
Here is the call graph for this function:

◆ operator=() [2/3]

template<size_t NDEME>
inventory_t & inventory_t< NDEME >::operator= ( const inventory_t< NDEME > & )
default

copy assignment operator

Here is the call graph for this function:

◆ operator=() [3/3]

template<size_t NDEME>
inventory_t & inventory_t< NDEME >::operator= ( inventory_t< NDEME > && )
delete

move assignment operator

Here is the call graph for this function:

◆ operator[]() [1/2]

template<size_t NDEME>
pocket_t & inventory_t< NDEME >::operator[] ( const name_t i)
inline

return the i-th deme

Definition at line 126 of file inventory.h.

126 {
127 return inven(i);
128 };
Here is the call graph for this function:

◆ operator[]() [2/2]

template<size_t NDEME>
const pocket_t & inventory_t< NDEME >::operator[] ( const name_t i) const
inline

return the i-th deme

Definition at line 122 of file inventory.h.

122 {
123 return inven(i);
124 };
Here is the call graph for this function:

◆ random_ball()

template<size_t NDEME>
ball_t * inventory_t< NDEME >::random_ball ( name_t i) const
inline

choose one random ball from deme i

Definition at line 171 of file inventory.h.

171 {
172 name_t n = inven(i).size();
173 assert(n > 0);
175 ball_it k = inven(i).begin();
176 while (draw-- > 0) k++;
177 return *k;
178 };
static int random_integer(int n)
Definition internal.h:57
Here is the call graph for this function:
Here is the caller graph for this function:

◆ random_balls()

template<size_t NDEME>
pocket_t * inventory_t< NDEME >::random_balls ( name_t i,
int n = 1 ) const
inline

choose a random set of n balls from deme i

Definition at line 180 of file inventory.h.

180 {
181 pocket_t *p = new pocket_t();
182 if (n == 1) {
183 ball_t *b = random_ball(i);
184 p->insert(b);
185 } else if (n > 1) {
186 int N = inven(i).size();
187 assert(N > 0);
188 assert(n <= N);
189 ball_it j = inven(i).begin();
190 int k = 0, m = 0;
191 while (m < n && k < N) {
192 int u = random_integer(N-k);
193 if (u < n-m) {
194 p->insert(*j);
195 m++;
196 }
197 k++; j++;
198 }
199 } else {
200 assert(0); // #nocov
201 }
202 return p;
203 };
ball_t * random_ball(name_t i) const
choose one random ball from deme i
Definition inventory.h:171
Here is the call graph for this function:

◆ size() [1/2]

template<size_t NDEME>
size_t inventory_t< NDEME >::size ( name_t i) const
inline

size of deme

Definition at line 118 of file inventory.h.

118 {
119 return inven(i).size();
120 };
Here is the call graph for this function:

◆ size() [2/2]

template<size_t NDEME>
size_t inventory_t< NDEME >::size ( void ) const
inline

Total number of balls in an inventory. i.e., the sum of the sizes of all demes

Definition at line 110 of file inventory.h.

110 {
111 size_t n = 0;
112 for (name_t i = 0; i < ndeme; i++) {
113 n += size(i);
114 }
115 return n;
116 };
size_t size(void) const
Definition inventory.h:110
Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ operator>> [1/2]

template<size_t NDEME>
raw_t * operator>> ( const inventory_t< NDEME > & I,
raw_t * o )
friend

binary serialization

Definition at line 91 of file inventory.h.

91 {
92 for (size_t i = 0; i < ndeme; i++) {
93 o = (I._inven[i] >> o);
94 }
95 return o;
96 };

◆ operator>> [2/2]

template<size_t NDEME>
raw_t * operator>> ( raw_t * o,
inventory_t< NDEME > & I )
friend

binary deserialization

Definition at line 98 of file inventory.h.

98 {
99 I.clean();
100 for (size_t i = 0; i < ndeme; i++) {
101 o = (o >> I._inven[i]);
102 }
103 return o;
104 };

Field Documentation

◆ _inven

template<size_t NDEME>
pocket_t inventory_t< NDEME >::_inven[ndeme]
private

Definition at line 23 of file inventory.h.

◆ ndeme

template<size_t NDEME>
const size_t inventory_t< NDEME >::ndeme = NDEME
staticprivate

Definition at line 22 of file inventory.h.


The documentation for this class was generated from the following file: