Skip to content

Commit

Permalink
generalize ancestry list template alias (#348)
Browse files Browse the repository at this point in the history
* make the ancestry list integer type a template

* make index type of edge_buffer match the template type name
  • Loading branch information
molpopgen authored Jul 6, 2021
1 parent 52e84fe commit 56aa5e8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 34 deletions.
2 changes: 1 addition & 1 deletion fwdpp/ts/recording/edge_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace fwdpp

template <typename SignedInteger>
using edge_buffer
= nested_forward_lists<birth_data<SignedInteger>, std::int32_t, -1>;
= nested_forward_lists<birth_data<SignedInteger>, SignedInteger, -1>;

// Below are functions for liftover of an edge buffer
// to a table collection
Expand Down
60 changes: 30 additions & 30 deletions fwdpp/ts/simplification/simplification.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ namespace fwdpp
constexpr SignedInteger segment_overlapper<SignedInteger>::null;
#endif

// FIXME: not generic enough!
template <typename SignedInteger>
using ancestry_list
= nested_forward_lists<segment<std::int32_t>, std::int32_t, -1>;
= nested_forward_lists<segment<SignedInteger>, SignedInteger, -1>;

template <typename SignedInteger> struct simplifier_internal_state
/// Holds data needed during tree sequence simplification
Expand All @@ -243,7 +243,7 @@ namespace fwdpp
typename table_type::edge_table temp_edge_buffer;
typename table_type::node_table new_node_table;
typename table_type::site_table new_site_table;
ancestry_list ancestry;
ancestry_list<SignedInteger> ancestry;
segment_overlapper<typename table_type::id_type> overlapper;
// NOTE: the whole idea of mutation map could
// go away? Should benchmark (later) with
Expand Down Expand Up @@ -327,29 +327,29 @@ namespace fwdpp
template <typename SignedInteger>
inline void
add_ancestry(SignedInteger input_id, double left, double right,
SignedInteger node, ancestry_list& ancestry)
SignedInteger node, ancestry_list<SignedInteger>& ancestry)
{
if (ancestry.head(input_id) == ancestry_list::null)
{
ancestry.extend(input_id, left, right, node);
}
if(ancestry.head(input_id) == ancestry_list<SignedInteger>::null)
{
ancestry.extend(input_id, left, right, node);
}
else
{
auto last_idx = ancestry.tail(input_id);
if (last_idx == ancestry_list::null)
{
throw std::runtime_error("ancestry_list data invalid");
}
auto& last = ancestry.fetch(last_idx);
if (last.right == left && last.node == node)
{
last.right = right;
}
else
{
ancestry.extend(input_id, left, right, node);
}
}
{
auto last_idx = ancestry.tail(input_id);
if (last_idx == ancestry_list<SignedInteger>::null)
{
throw std::runtime_error("ancestry_list data invalid");
}
auto& last = ancestry.fetch(last_idx);
if (last.right == left && last.node == node)
{
last.right = right;
}
else
{
ancestry.extend(input_id, left, right, node);
}
}
}

template <typename SignedInteger>
Expand Down Expand Up @@ -454,7 +454,7 @@ namespace fwdpp
// If the two segments overlap, we add the
// minimal overlap to our queue.
auto idx = state.ancestry.head(edge_ptr->child);
while (idx != ancestry_list::null)
while (idx != ancestry_list<SignedInteger>::null)
{
auto& seg = state.ancestry.fetch(idx);
if (seg.right > edge_ptr->left
Expand Down Expand Up @@ -569,12 +569,12 @@ namespace fwdpp
auto seg_idx = state.ancestry.head(n);
for (; map_itr < map_end && map_itr->node == n;)
{
if (seg_idx == ancestry_list::null)
if (seg_idx == ancestry_list<SignedInteger>::null)
{
++map_itr;
break;
}
while (seg_idx != ancestry_list::null
while (seg_idx != ancestry_list<SignedInteger>::null
&& map_itr < map_end && map_itr->node == n)
{
auto& seg = state.ancestry.fetch(seg_idx);
Expand Down Expand Up @@ -652,11 +652,11 @@ namespace fwdpp
template <typename SignedInteger>
inline void
queue_children(SignedInteger child, double left, double right,
ancestry_list& ancestry,
ancestry_list<SignedInteger>& ancestry,
segment_overlapper<SignedInteger>& overlapper)
{
auto idx = ancestry.head(child);
while (idx != ancestry_list::null)
while (idx != ancestry_list<SignedInteger>::null)
{
auto& seg = ancestry.fetch(idx);
if (seg.right > left && right > seg.left)
Expand All @@ -672,7 +672,7 @@ namespace fwdpp
inline void
process_births_from_buffer(SignedInteger n,
edge_buffer<SignedInteger>& buffer,
ancestry_list& ancestry,
ancestry_list<SignedInteger>& ancestry,
segment_overlapper<SignedInteger>& overlapper)
{
static_assert(std::is_integral<SignedInteger>::value,
Expand Down
8 changes: 5 additions & 3 deletions testsuite/tree_sequences/test_ancestry_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
#include <boost/test/unit_test.hpp>
#include <fwdpp/ts/simplification/simplification.hpp>

using ancestry_list = fwdpp::ts::simplification::ancestry_list<std::int32_t>;

namespace
{
std::int64_t
get_list_length(const fwdpp::ts::simplification::ancestry_list& al, std::int32_t i)
get_list_length(const ancestry_list& al, std::int32_t i)
{
int len = 0;
auto f = al.head(i);
Expand All @@ -25,7 +27,7 @@ BOOST_AUTO_TEST_CASE(test_construct_and_fill)
// The data added don't refer to valid
// tree sequences and are just for testing
{
fwdpp::ts::simplification::ancestry_list al;
ancestry_list al;
al.reset(4);
al.extend(0, 0., 1., 3);
al.extend(1, 0., 0.5, 3);
Expand All @@ -37,7 +39,7 @@ BOOST_AUTO_TEST_CASE(test_construct_and_fill)

BOOST_AUTO_TEST_CASE(test_fill_nullify_once_fill)
{
fwdpp::ts::simplification::ancestry_list al;
ancestry_list al;
al.reset(4);
al.extend(0, 0., 1., 3);
al.extend(1, 0., 0.5, 3);
Expand Down

0 comments on commit 56aa5e8

Please sign in to comment.