11#ifndef __FOREST_H_INCLUDED__
12#define __FOREST_H_INCLUDED__
16#include <unordered_map>
31template <
typename Position,
typename Tree>
class Forest
37 using data_type = std::unordered_multimap<Position, Tree>;
39 using size_type =
typename data_type::size_type;
44 using position_type = Position;
46 using iterator =
typename data_type::iterator;
48 using const_iterator =
typename data_type::const_iterator;
81 *
this = std::move(otherCopy);
90 m_data = std::move(other.m_data);
98 return m_data.begin();
112 return m_data.begin();
117 const_iterator
end()
const
126 return m_data.cbegin();
133 return m_data.cend();
140 return m_data.size();
145 unsigned int nb_trees(Position
const &position)
const
147 return m_data.count(position);
157 assert(m_data.count(position) > 0 &&
"no trees at position");
158 return m_data.equal_range(position);
168 assert(m_data.count(position) > 0 &&
"no trees at position");
169 return m_data.equal_range(position);
179 return m_data.insert(std::pair<Position, Tree>(position, tree));
186 iterator
insert(Position
const &position,
Tree &&tree)
noexcept
188 return m_data.insert(std::pair<Position, Tree>(position, std::move(tree)));
197 for (
auto const &it : trees)
212 for (
auto &&it : trees)
214 insert(position, std::move(it));
225 return m_data.erase(x);
232 void erase(iterator first, iterator last)
234 m_data.erase(first, last);
243 std::set<Position> s;
244 for (
auto const &it : m_data)
257 std::vector<Tree> trees;
259 for (
auto &it : *
this)
261 trees.push_back(it.second);
Collection of geo-localized coalescing trees.
Definition Forest.hpp:32
const_iterator end() const
returns iterator to the begining
Definition Forest.hpp:117
Forest< Position, Tree > & insert(Position const &position, std::vector< Tree > &&trees) noexcept
insert a vector of trees at a given position
Definition Forest.hpp:210
const_iterator begin() const
returns iterator to the begining
Definition Forest.hpp:110
Forest(const Forest< Position, Tree > &other)
Copy constructor.
Definition Forest.hpp:63
Forest< Position, Tree > & operator=(Forest< Position, Tree > &&other) noexcept
Move assignment operator.
Definition Forest.hpp:88
Forest(Forest< Position, Tree > &&other) noexcept
Move constructor.
Definition Forest.hpp:71
std::vector< Tree > get_all_trees() const
copies all trees in the forest
Definition Forest.hpp:255
unsigned int nb_trees(Position const &position) const
number of trees in the forest at a given position
Definition Forest.hpp:145
Forest< Position, Tree > & insert(Position const &position, std::vector< Tree > const &trees)
insert a vector of trees at a given position
Definition Forest.hpp:195
const_iterator cend() const
returns iterator to the begin
Definition Forest.hpp:131
iterator insert(Position const &position, Tree const &tree)
insert a new tree at a given position
Definition Forest.hpp:177
void erase(iterator first, iterator last)
remove elements from the Forest.
Definition Forest.hpp:232
std::set< Position > positions() const
positions in the forest
Definition Forest.hpp:241
unsigned int nb_trees() const
number of trees in the forest
Definition Forest.hpp:138
iterator begin()
returns iterator to the begin
Definition Forest.hpp:96
size_type erase(Position const &x)
erase a position from the Forest.
Definition Forest.hpp:223
Forest< Position, Tree > & operator=(const Forest< Position, Tree > &other)
Copy assignment operator.
Definition Forest.hpp:78
Forest()
Default constructor.
Definition Forest.hpp:54
iterator insert(Position const &position, Tree &&tree) noexcept
insert a new tree at a given position
Definition Forest.hpp:186
const_iterator cbegin() const
returns iterator to the begin
Definition Forest.hpp:124
std::pair< iterator, iterator > trees_at_same_position(const Position &position)
access to trees in the forest at a given position
Definition Forest.hpp:166
std::pair< const_iterator, const_iterator > trees_at_same_position(const Position &position) const
non-modifying access to trees in the forest at a given position
Definition Forest.hpp:155
iterator end()
returns iterator to the end
Definition Forest.hpp:103
Data structure for representing tree topologies where each node contains a data field.
Definition Tree.hpp:29
Simulation of coalescence-based models of molecular evolution.
Definition coalescence.hpp:21