All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
splay_cycle.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2013 Piotr Wygocki
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
15 #ifndef PAAL_SPLAY_CYCLE_HPP
16 #define PAAL_SPLAY_CYCLE_HPP
17 
21 
22 namespace paal {
23 namespace data_structures {
24 
30 template <typename T>
31 class splay_cycle {
32  using SIter = typename splay_tree<T>::iterator;
33 public:
35 
36  splay_cycle() = default;
37 
45  template <typename Iter>
46  splay_cycle(Iter begin, Iter end)
47  : m_splay_tree(begin, end), m_size(m_splay_tree.size()) {}
48 
54  VIter vbegin() const {
55  return VIter(m_splay_tree.begin(), m_splay_tree.begin(),
56  m_splay_tree.end());
57  }
58 
66  VIter vbegin(const T &t) const {
67  std::size_t i = m_splay_tree.get_idx(t);
68  assert(i != std::size_t(-1));
69  return VIter(m_splay_tree.splay(i), m_splay_tree.begin(), m_splay_tree.end());
70  }
71 
77  VIter vend() const {
78  auto e = m_splay_tree.end();
79  return VIter(e, e, e);
80  }
81 
88  void flip(const T &begin, const T &end) {
89  if (begin == end) {
90  return;
91  }
92  std::size_t b = m_splay_tree.get_idx(begin);
93  assert(b != std::size_t(-1));
94  std::size_t e = m_splay_tree.get_idx(end);
95  assert(e != std::size_t(-1));
96  if (b < e) {
97  m_splay_tree.reverse(b, e);
98  } else {
99  m_splay_tree.reverse(e + 1, b - 1);
100  m_splay_tree.reverse(0, m_size - 1);
101  }
102  }
103 
104  private:
105  splay_tree<T> m_splay_tree;
106  const std::size_t m_size;
107 };
108 
109 }
110 }
111 #endif // PAAL_SPLAY_CYCLE_HPP
VIter vbegin(const T &t) const
vertices begin (from t)
Definition: splay_cycle.hpp:66
splay_cycle(Iter begin, Iter end)
constructor from range
Definition: splay_cycle.hpp:46
For given collection (begin -&gt; end) and start iterator pointing to an element inside collection (begi...
Computes size of TypesVector.
VIter vbegin() const
vertices begin
Definition: splay_cycle.hpp:54
void flip(const T &begin, const T &end)
flips range from begin to end
Definition: splay_cycle.hpp:88
Cycle based on splay tree.
Definition: splay_cycle.hpp:31
VIter vend() const
vertices end
Definition: splay_cycle.hpp:77