15 #ifndef PAAL_COLLECTION_STARTS_FROM_LAST_CHANGE_HPP
16 #define PAAL_COLLECTION_STARTS_FROM_LAST_CHANGE_HPP
18 #include <boost/range/join.hpp>
20 #include <unordered_map>
23 namespace data_structures {
33 template <
typename Iterator,
35 std::hash<typename std::iterator_traits<Iterator>::value_type>>
37 typedef typename std::iterator_traits<Iterator>::value_type Element;
38 typedef std::unordered_map<Element, Iterator, hash> ElemToIter;
39 typedef std::pair<Iterator, Iterator> Range;
40 typedef boost::joined_range<Range, Range> JoinedRange;
41 typedef typename boost::range_iterator<JoinedRange>::type JoinedIterator;
44 typedef JoinedIterator ResultIterator;
55 : m_begin(begin), m_end(end), m_new_begin(m_begin) {
56 assert(m_begin != m_end);
57 for (
auto i = m_begin; i != m_end; ++i) {
58 bool b = m_elem_to_iter.emplace(*i, i).second;
70 auto i = m_elem_to_iter.find(el);
71 assert(i != m_elem_to_iter.end());
72 m_new_begin = i->second;
80 JoinedIterator
begin() {
return std::begin(get_range()); }
87 JoinedIterator
end() {
return std::end(get_range()); }
95 JoinedRange get_range() {
96 Range r1 = std::make_pair(m_new_begin, m_end);
97 Range r2 = std::make_pair(m_begin, m_new_begin);
98 return boost::join(r1, r2);
103 Iterator m_new_begin;
104 ElemToIter m_elem_to_iter;
109 #endif // PAAL_COLLECTION_STARTS_FROM_LAST_CHANGE_HPP
this collection stores some range and expose set_last_change function each time begin and end is call...
void set_last_change(const Element &el)
one can set the place of the last change (future start position of the range)
collection_starts_from_last_change(Iterator begin, Iterator end)
constructor
JoinedIterator begin()
begin