8#include <unordered_map>
12typedef typename std::list<node_t*>::const_iterator
node_it;
13typedef typename std::list<node_t*>::iterator
node_nit;
14typedef typename std::list<node_t*>::const_reverse_iterator
node_rev_it;
23 for (
node_t *p : *
this)
delete p;
39 size_t s =
sizeof(size_t);
46 size_t nnode = G.size();
47 memcpy(o,&nnode,
sizeof(
size_t)); o +=
sizeof(size_t);
56 std::unordered_map<name_t,node_t*> node_names;
57 std::unordered_map<name_t,ball_t*> ball_names;
59 memcpy(&nnode,o,
sizeof(
size_t)); o +=
sizeof(size_t);
60 node_names.reserve(nnode);
61 ball_names.reserve(nnode);
62 for (
size_t i = 0; i < nnode; i++) {
66 node_names.insert({p->
uniq,p});
69 q->repair_owners(node_names,&ball_names);
81 std::unordered_map<name_t,ball_t*>::const_iterator
n;
83 n = names.find(p->
uniq);
84 assert(
n != names.end());
104 std::list<node_t*>::sort(
compare);
111 return (empty()) ? R_NaReal : front()->slate;
115 return (empty()) ? R_NaReal : back()->slate;
125 if (b->is(col)) p->insert(b);
149 while (i <
n && k != cend()) {
161 p->erase(b); q->
insert(b);
168 p->erase(a); q->
insert(a);
169 q->erase(b); p->
insert(b);
217 if ((*j)->dead_root()) {
258 for (
node_t *p : *
this ) {
260 if (b->color==
blue) {
271 string_t
yaml (string_t tab =
"")
const;
275 string_t
newick (
slate_t t,
bool showdeme,
bool extended)
const;
Balls function as pointers.
name_t deme(void) const
view deme
node_t * holder(void) const
in whose pocket do I lie?
bool is(color_t c) const
is a given ball of the given color?
Encodes a genealogical node.
node_t * parent(void) const
name_t lineage(void) const
view lineage
size_t bytesize(void) const
size of binary serialization
bool dead_root(void) const
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 weed(void)
drop all dead roots
slate_t dawn(void) const
Earliest time in the sequence.
void clean(void)
clean up: delete all nodes, reset globals
void trace_lineage(ball_t *b, name_t u)
size_t ntime(slate_t t) const
Number of distinct timepoints.
void sort(void)
order nodes in order of increasing time
friend raw_t * operator>>(const nodeseq_t &G, raw_t *o)
binary serialization
void destroy_node(node_t *p)
remove a dead root node
void attach(node_t *p, node_t *q)
SEXP structure(void) const
R list description.
size_t bytesize(void) const
size of serialized binary form
string_t yaml(string_t tab="") const
human/machine-readable info
void repair_owners(std::unordered_map< name_t, ball_t * > &names)
static bool compare(node_t *p, node_t *q)
void swap(ball_t *a, ball_t *b)
swap balls a and b, wherever they lie
size_t length(void) const
Number of nodes in the sequence.
void move(ball_t *b, node_t *p, node_t *q)
move ball b from p to q
pocket_t * colored(color_t col) const
Get all balls of a color.
void trace_lineages(void)
slate_t dusk(void) const
Latest time in the sequence.
node_t * position(int n)
traverse to nth node, retrieve pointer
~nodeseq_t(void)
destructor
void add(node_t *p, ball_t *a)
string_t newick(slate_t t, bool showdeme, bool extended) const
put genealogy at time t into Newick format.
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 name_t null_lineage
std::list< node_t * >::const_reverse_iterator node_rev_it
std::list< node_t * >::const_iterator node_it
std::list< node_t * >::iterator node_nit