-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedge_buffer.hpp
94 lines (79 loc) · 2.46 KB
/
edge_buffer.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#pragma once
#include <cstdint>
#include <cstdio>
#include <memory>
#include <tskit.h>
#include "tskit_tools.hpp"
using EDGE_BUFFER_INDEX_TYPE = std::int64_t;
static const EDGE_BUFFER_INDEX_TYPE NULL_EDGE_BUFFER_INDEX = -1;
struct BirthData
{
double left, right;
tsk_id_t child;
EDGE_BUFFER_INDEX_TYPE next;
BirthData(double l, double r, tsk_id_t c);
};
struct EdgeBuffer
{
std::vector<EDGE_BUFFER_INDEX_TYPE> first;
std::vector<BirthData> births;
EdgeBuffer(std::size_t num_nodes);
};
using edge_buffer_ptr = std::unique_ptr<EdgeBuffer>;
struct ExistingEdges
{
tsk_id_t parent;
std::size_t start, stop;
ExistingEdges(tsk_id_t p, std::size_t start_, std::size_t stop_);
};
struct temp_edges
// Used for calls to tsk_edge_table_set_columns
// Within tskit, we'd just use an edge table.
{
std::vector<double> left, right;
std::vector<tsk_id_t> parent, child;
temp_edges() : left{}, right{}, parent{}, child{}
{
}
void
clear()
{
left.clear();
right.clear();
parent.clear();
child.clear();
}
void
add_edge(double l, double r, tsk_id_t p, tsk_id_t c)
{
if (r <= l)
{
std::ostringstream o;
o << "bad left/right " << l << ' ' << r;
throw std::invalid_argument(o.str());
}
left.push_back(l);
right.push_back(r);
parent.push_back(p);
child.push_back(c);
}
std::size_t
size() const
{
if (left.size() != right.size() || left.size() != parent.size()
|| left.size() != child.size())
{
throw std::runtime_error("invalid size of temporary edges");
}
return left.size();
}
};
EDGE_BUFFER_INDEX_TYPE get_buffer_end(const edge_buffer_ptr& new_edges, std::size_t i);
EDGE_BUFFER_INDEX_TYPE buffer_new_edge(tsk_id_t parent, double left, double right,
tsk_id_t child, edge_buffer_ptr& new_edges);
EDGE_BUFFER_INDEX_TYPE buffer_new_edge_at(EDGE_BUFFER_INDEX_TYPE loc, double left,
double right, tsk_id_t child,
edge_buffer_ptr& new_edges);
void stitch_together_edges(const std::vector<tsk_id_t>& alive_at_last_simplification,
double max_time, edge_buffer_ptr& new_edges,
temp_edges& edge_liftover, table_collection_ptr& tables);