A sequence of nodes.
More...
#include <nodeseq.h>
A sequence of nodes.
Definition at line 19 of file nodeseq.h.
◆ ~nodeseq_t()
nodeseq_t::~nodeseq_t |
( |
void |
| ) |
|
|
inline |
destructor
Definition at line 32 of file nodeseq.h.
void clean(void)
clean up: delete all nodes, reset globals
◆ add()
add node p; take as parent the node holding ball a. the deme of p is changed to match that of a
Definition at line 179 of file nodeseq.h.
name_t deme(void) const
view deme
ball_t * green_ball(void) const
pointer to my green ball
name_t deme(void) const
view deme
void swap(ball_t *a, ball_t *b)
swap balls a and b, wherever they lie
◆ bytesize()
size_t nodeseq_t::bytesize |
( |
void |
| ) |
const |
|
inline |
size of serialized binary form
Definition at line 40 of file nodeseq.h.
41 size_t s =
sizeof(size_t);
42 for (
node_it i = begin(); i != end(); i++)
43 s += (*i)->bytesize();
std::list< node_t * >::const_iterator node_it
◆ clean()
void nodeseq_t::clean |
( |
void |
| ) |
|
|
inlineprivate |
clean up: delete all nodes, reset globals
Definition at line 24 of file nodeseq.h.
25 for (
node_it i = begin(); i != end(); i++)
delete *i;
◆ colored()
Get all balls of a color.
Definition at line 129 of file nodeseq.h.
131 for (
node_it i = begin(); i != end(); i++) {
132 for (
ball_it j = (*i)->begin(); j != (*i)->end(); j++) {
133 if ((*j)->is(col)) p->insert(*j);
A pocket is a set of balls.
std::set< ball_t *, ball_order >::const_iterator ball_it
◆ comb()
void nodeseq_t::comb |
( |
void |
| ) |
|
|
inline |
pass through the sequence, dropping superfluous nodes i.e., those holding just one ball that is green.
Definition at line 210 of file nodeseq.h.
211 for (
node_rev_it i = crbegin(); i != crend(); i++) {
212 if ((*i)->size() == 1 && (*i)->holds(
green)) {
213 swap((*i)->last_ball(),(*i)->green_ball());
218 if ((*j)->dead_root()) {
void destroy_node(node_t *p)
remove a dead root node
std::list< node_t * >::const_reverse_iterator node_rev_it
std::list< node_t * >::iterator node_nit
◆ compare()
Order relation among nodes. Nodes should be ordered by time, then by unique name.
Definition at line 97 of file nodeseq.h.
◆ dawn()
slate_t nodeseq_t::dawn |
( |
void |
| ) |
const |
|
inlineprivate |
Earliest time in the sequence.
Definition at line 118 of file nodeseq.h.
119 return (empty()) ? R_NaReal : front()->slate;
◆ describe()
std::string nodeseq_t::describe |
( |
void |
| ) |
const |
|
inline |
human-readable info
Definition at line 264 of file nodeseq.h.
266 for (
node_it p = begin(); p != end(); p++) {
267 o += (*p)->describe();
◆ destroy_node()
void nodeseq_t::destroy_node |
( |
node_t * |
p | ) |
|
|
inline |
remove a dead root node
Definition at line 203 of file nodeseq.h.
bool dead_root(void) const
◆ drop()
void nodeseq_t::drop |
( |
ball_t * |
a | ) |
|
|
inline |
drop the black ball 'a' and the node if either (1) the node becomes thereby a dead root, or (2) the node's pocket becomes thereby empty.
Definition at line 187 of file nodeseq.h.
bool is(color_t c) const
is a given ball of the given color?
node_t * holder(void) const
in whose pocket do I lie?
Encodes a genealogical node.
◆ dusk()
slate_t nodeseq_t::dusk |
( |
void |
| ) |
const |
|
inlineprivate |
Latest time in the sequence.
Definition at line 122 of file nodeseq.h.
123 return (empty()) ? R_NaReal : back()->slate;
◆ length()
size_t nodeseq_t::length |
( |
void |
| ) |
const |
|
inline |
Number of nodes in the sequence.
Definition at line 150 of file nodeseq.h.
152 for (
node_it i = begin(); i != end(); i++) count++;
◆ newick()
std::string nodeseq_t::newick |
( |
slate_t |
t | ) |
const |
|
inline |
put genealogy at time t
into Newick format.
Definition at line 292 of file nodeseq.h.
295 for (
node_it i = begin(); i != end(); i++) {
296 if ((*i)->is_root()) {
297 o += (*i)->newick(t,te) +
";";
slate_t dawn(void) const
Earliest time in the sequence.
◆ ntime()
size_t nodeseq_t::ntime |
( |
slate_t |
t | ) |
const |
|
inline |
Number of distinct timepoints.
Definition at line 139 of file nodeseq.h.
141 for (
node_it i = begin(); i != end(); i++) {
142 if (t < (*i)->slate) {
◆ operator+=()
merge two node sequences
Definition at line 105 of file nodeseq.h.
static bool compare(node_t *p, node_t *q)
◆ position()
node_t* nodeseq_t::position |
( |
int |
n | ) |
|
|
inline |
traverse to nth node, retrieve pointer
Definition at line 156 of file nodeseq.h.
159 while (i <
n && k != cend()) {
◆ repair_owners()
void nodeseq_t::repair_owners |
( |
std::unordered_map< name_t, ball_t * > & |
names | ) |
|
|
inlineprivate |
Needed in deserialization. This function repairs the links green balls and their names.
Definition at line 82 of file nodeseq.h.
83 std::unordered_map<name_t,ball_t*>::const_iterator
n;
84 for (
node_it i = begin(); i != end(); i++) {
86 n = names.find(p->
uniq);
87 assert(
n != names.end());
Balls function as pointers.
◆ sort()
void nodeseq_t::sort |
( |
void |
| ) |
|
|
inline |
order nodes in order of increasing time
Definition at line 111 of file nodeseq.h.
112 std::list<node_t*>::sort(
compare);
◆ structure()
SEXP nodeseq_t::structure |
( |
void |
| ) |
const |
|
inline |
R list description.
Definition at line 281 of file nodeseq.h.
283 PROTECT(Nodes = NEW_LIST(size()));
285 for (
node_it i = begin(); i != end(); i++) {
286 SET_ELEMENT(Nodes,k++,(*i)->structure());
◆ swap()
swap balls a and b, wherever they lie
Definition at line 169 of file nodeseq.h.
173 p->erase(a); q->insert(a); a->
holder() = q;
174 q->erase(b); p->insert(b); b->
holder() = p;
◆ trace_lineage()
trace back a single lineage. this results in the deme slot for all green balls along the lineage of 'b' begin replaced by the lineage of 'b'.
Definition at line 231 of file nodeseq.h.
name_t lineage(void) const
view lineage
node_t * parent(void) const
static const name_t null_lineage
◆ trace_lineages()
void nodeseq_t::trace_lineages |
( |
void |
| ) |
|
|
inline |
trace back all sample lineages. this results in the deme slots of all green balls being replaced by the unique names of the lineages they trace.
Definition at line 244 of file nodeseq.h.
249 for (
node_it i = begin(); i != end(); i++) {
251 for (
ball_it j = p->begin(); j != p->end(); j++) {
void trace_lineage(ball_t *b, name_t u)
◆ yaml()
virtual std::string nodeseq_t::yaml |
( |
std::string |
tab = "" | ) |
const |
|
inlinevirtual |
human- & machine-readable info
Reimplemented in genealogy_t.
Definition at line 272 of file nodeseq.h.
274 std::string t = tab +
" ";
275 for (
node_it p = begin(); p != end(); p++) {
276 o += tab +
"- " + (*p)->yaml(t);
◆ operator>> [1/2]
binary serialization
Definition at line 47 of file nodeseq.h.
48 size_t nnode = G.size();
49 memcpy(o,&nnode,
sizeof(
size_t)); o +=
sizeof(size_t);
50 for (
node_it i = G.begin(); i != G.end(); i++) {
◆ operator>> [2/2]
binary deserialization
Definition at line 56 of file nodeseq.h.
58 std::unordered_map<name_t,node_t*> node_names;
59 std::unordered_map<name_t,ball_t*> ball_names;
61 memcpy(&nnode,o,
sizeof(
size_t)); o +=
sizeof(size_t);
62 node_names.reserve(nnode);
63 ball_names.reserve(nnode);
64 for (
size_t i = 0; i < nnode; i++) {
68 node_names.insert({p->
uniq,p});
70 for (
node_it i = G.begin(); i != G.end(); i++) {
void repair_owners(std::unordered_map< name_t, ball_t * > &names)
void trace_lineages(void)
The documentation for this class was generated from the following file: