80 memcpy(o,A,
sizeof(A)); o +=
sizeof(A);
81 memcpy(o,B,
sizeof(B)); o +=
sizeof(B);
82 return reinterpret_cast<const nodeseq_t&
>(G) >> o;
89 memcpy(A,o,
sizeof(A)); o +=
sizeof(A);
90 memcpy(B,o,
sizeof(B)); o +=
sizeof(B);
92 err(
"in %s: corrupted genealogy serialization.",__func__);
95 return o >>
reinterpret_cast<nodeseq_t&
>(G);
115 err(
"in %s: cannot deserialize a NULL.",__func__);
116 PROTECT(o = AS_RAW(o));
172 int *
ell,
int *sat,
int *etype)
const;
177 void gendat (
double *tout,
int *anc,
int *lin,
178 int *sat,
int *type,
int *
deme,
179 int *index,
int *child)
const;
186 for (
const node_t *p : *
this) {
195 for (
const node_t *p : *
this) {
204 string_t
yaml (string_t tab =
"")
const;
208 string_t
newick (
bool extended =
true)
const;
218 if (size() > maxq+grace) {
219 err(
"maximum genealogy size exceeded!");
220 }
else if (size() > maxq) {
313 while (!blacks->empty()) {
314 ball_t *b = *(blacks->begin());
325 while (!blacks->empty()) {
326 ball_t *a = *(blacks->begin());
385 if ((*j)->is_root() && (*j)->slate >
timezero()) {
407 for (
node_t *p : *
this ) {
424 std::pair<std::vector<slate_t>, std::vector<slate_t>>
cblv (
void)
const;
static const name_t undeme
Balls function as pointers.
name_t deme(void) const
view deme
bool is(color_t c) const
is a given ball of the given color?
size_t & ndeme(void)
number of demes
void time_rescale(slate_t scale, slate_t origin=0)
slate_t time(void) const
view current time.
size_t nsample(void) const
number of samples
~genealogy_t(void)
destructor
SEXP structure(void) const
R list description.
void reuniqify(name_t shift)
shifts names to avoid overlap
void valid(void) const
check the validity of the genealogy.
genealogy_t(SEXP o)
constructor from RAW SEXP (containing binary serialization)
genealogy_t & operator=(const genealogy_t &G)
copy assignment operator
void death(ball_t *a, slate_t t)
death
SEXP lineage_count(void) const
lineage count and saturation
genealogy_t & prune(void)
prune the tree (drop all black balls)
size_t bytesize(void) const
size of serialized binary form
genealogy_t(double t0=R_NaReal, size_t ndeme=0)
string_t yaml(string_t tab="") const
human/machine-readable info
size_t ndeme(void) const
number of demes
genealogy_t & parse_cblv(const double *, const double *, int, double)
parse a CBLV representation in the vectors x and y.
genealogy_t(const genealogy_t &G)
copy constructor
bool check_genealogy_size(size_t grace=0) const
check the size of the genealogy (to prevent memory exhaustion).
slate_t timezero(void) const
get zero time.
ball_t * graft(slate_t t, name_t d)
graft a new lineage into deme d
genealogy_t & parse(const string_t &)
Parse a Newick string and create the indicated genealogy.
void clip_zlb(void)
clip out all zero-length branches
void migrate(ball_t *a, slate_t t, name_t d=0)
movement into deme d
slate_t _time
The current time.
SEXP gendat(void) const
genealogy information in list format
ball_t * birth(node_t *p, name_t d)
birth of second or subsequent sibling into deme d
genealogy_t & operator+=(const genealogy_t &other)
merges two genealogies, adjusting time, t0, and ndeme as needed
size_t _ndeme
The number of demes (excluding the undeme).
slate_t & timezero(void)
view/set zero time.
std::pair< std::vector< slate_t >, std::vector< slate_t > > cblv(void) const
void cap_roots(void)
roots are added at zero time if needed
void sample_death(ball_t *a, slate_t t)
insert a sample node and simultaneously terminate the lineage
genealogy_t(raw_t *o)
constructor from serialized binary form
slate_t & time(void)
view/set current time.
node_t * make_node(name_t d=undeme)
void curtail(slate_t tnew, slate_t troot)
friend raw_t * operator>>(const genealogy_t &G, raw_t *o)
binary serialization
void sample_migrate(ball_t *a, slate_t t, name_t d=0)
insert a sample node and simultaneously migrate the lineage
static const name_t magic
name_t unique(void)
get the next unique name
void sample(ball_t *a, slate_t t)
insert a sample node
slate_t _t0
The initial time.
name_t _unique
The next unique name.
size_t nroot(void) const
number of roots
genealogy_t(genealogy_t &&)=default
move constructor
ball_t * birth(ball_t *a, slate_t t, name_t d)
birth into deme d
genealogy_t & obscure(void)
erase all deme information
node_t * scan_branch_label(string_t::const_iterator b, string_t::const_iterator e, node_t *p, slate_t bl)
string_t newick(bool extended=true) const
put genealogy at current time into Newick format.
genealogy_t & insert_zlb(void)
insert zero-length branches for samples where needed
Encodes a genealogical node.
name_t deme(void) const
view deme
ball_t * green_ball(void) const
pointer to my green ball
void insert(ball_t *a)
insert a ball into the pocket of a node
void sort(void)
order nodes in order of increasing time
void attach(node_t *p, node_t *q)
size_t bytesize(void) const
size of serialized binary form
void swap(ball_t *a, ball_t *b)
swap balls a and b, wherever they lie
pocket_t * colored(color_t col) const
Get all balls of a color.
void add(node_t *p, ball_t *a)
A pocket is a set of balls.
ball_t * last_ball(void) const
retrieve the last ball
bool holds(ball_t *b) const
does this node hold the given ball?
static const size_t MEMORY_MAX
std::list< node_t * >::iterator node_nit