File: tree_containers.h

package info (click to toggle)
polymake 4.14-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,888 kB
  • sloc: cpp: 168,933; perl: 43,407; javascript: 31,575; ansic: 3,007; java: 2,654; python: 632; sh: 268; xml: 117; makefile: 61
file content (216 lines) | stat: -rw-r--r-- 7,023 bytes parent folder | download | duplicates (2)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/* Copyright (c) 1997-2024
   Ewgenij Gawrilow, Michael Joswig, and the polymake team
   Technische Universität Berlin, Germany
   https://polymake.org

   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version: http://www.gnu.org/licenses/gpl.txt.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
--------------------------------------------------------------------------------
*/

#pragma once

#include "polymake/internal/modified_containers.h"

namespace pm {

template <typename Top, typename Params=typename Top::manipulator_params,
          bool is_modified=mtagged_list_extract<Params, OperationTag>::is_specified>
class modified_tree_impl
   : public modified_container_impl<Top, Params> {
   using base_t = modified_container_impl<Top, Params>;
public:
   using typename base_t::iterator;
   using typename base_t::const_iterator;
   using typename base_t::reverse_iterator;
   using typename base_t::const_reverse_iterator;
   using tree_type = typename base_t::container::tree_type;
protected:
   iterator finalize(typename tree_type::iterator&& it)
   {
      return iterator(std::move(it), this->manip_top().get_operation());
   }
   const_iterator finalize(typename tree_type::const_iterator&& it) const
   {
      return const_iterator(std::move(it), this->manip_top().get_operation());
   }
   reverse_iterator finalize(typename tree_type::reverse_iterator&& it)
   {
      return reverse_iterator(std::move(it), this->manip_top().get_operation());
   }
   const_reverse_iterator finalize(typename tree_type::const_reverse_iterator&& it) const
   {
      return const_reverse_iterator(std::move(it), this->manip_top().get_operation());
   }
};

template <typename Top, typename Params>
class modified_tree_impl<Top, Params, false>
   : public redirected_container<Top, Params> {
   using base_t = redirected_container<Top, Params>;
public:
   using typename base_t::iterator;
   using typename base_t::const_iterator;
   using typename base_t::reverse_iterator;
   using typename base_t::const_reverse_iterator;
protected:
   iterator finalize(iterator&& it) { return std::move(it); }
   const_iterator finalize(const_iterator&& it) const { return std::move(it); }
   reverse_iterator finalize(reverse_iterator&& it) { return std::move(it); }
   const_reverse_iterator finalize(const_reverse_iterator&& it) const { return std::move(it); }
};

template <typename Top, typename Params=typename Top::manipulator_params>
class modified_tree
   : public modified_tree_impl<Top, Params> {
   using base_t = modified_tree_impl<Top, Params>;
public:
   using typename base_t::iterator;
   using typename base_t::const_iterator;
   using typename base_t::reverse_iterator;
   using typename base_t::const_reverse_iterator;
   using tree_type = typename base_t::container::tree_type;

   template <typename Key>
   iterator find(const Key& k)
   {
      return this->finalize(this->manip_top().get_container().find(k));
   }
   template <typename Key>
   const_iterator find(const Key& k) const
   {
      return this->finalize(this->manip_top().get_container().find(k));
   }
   template <typename Key, typename Comparator>
   iterator find(const Key& k, const Comparator& comparator)
   {
      return this->finalize(this->manip_top().get_container().find(k,comparator));
   }
   template <typename Key, typename Comparator>
   const_iterator find(const Key& k, const Comparator& comparator) const
   {
      return this->finalize(this->manip_top().get_container().find(k,comparator));
   }

   template <typename Key, typename RelOp>
   iterator find_nearest(const Key& k, const RelOp& relop)
   {
      return this->finalize(this->manip_top().get_container().find_nearest(k,relop));
   }
   template <typename Key, typename RelOp>
   const_iterator find_nearest(const Key& k, const RelOp& relop) const
   {
      return this->finalize(this->manip_top().get_container().find_nearest(k,relop));
   }
   template <typename Key, typename RelOp, typename Comparator>
   iterator find_nearest(const Key& k, const RelOp& relop, const Comparator& comparator)
   {
      return this->finalize(this->manip_top().get_container().find_nearest(k,relop,comparator));
   }
   template <typename Key, typename RelOp, typename Comparator>
   const_iterator find_nearest(const Key& k, const RelOp& relop, const Comparator& comparator) const
   {
      return this->finalize(this->manip_top().get_container().find_nearest(k,relop,comparator));
   }

   template <typename Key>
   bool exists(const Key& k) const
   {
      return this->manip_top().get_container().exists(k);
   }

   // synonym for sets
   template <typename Key>
   bool contains(const Key& k) const { return exists(k); }

   // TODO: align the naming with STL as per C++17

   template <typename... Args>
   auto insert(Args&&... args)
   {
      return this->finalize(this->manip_top().get_container().insert(std::forward<Args>(args)...));
   }

   template <typename... Args>
   auto emplace(Args&&... args)
   {
      return this->finalize(this->manip_top().get_container().insert_new(std::forward<Args>(args)...));
   }

   template <typename... Args>
   void erase(Args&&... args)
   {
      this->manip_top().get_container().erase(std::forward<Args>(args)...);
   }

   template <typename Key>
   iterator toggle(const Key& k)
   {
      return this->finalize(this->manip_top().get_container().toggle(k));
   }

   template <typename Key>
   void push_front(const Key& k)
   {
      this->manip_top().get_container().push_front(k);
   }
   template <typename Key, typename Data>
   void push_front(const Key& k, const Data& data)
   {
      this->manip_top().get_container().push_front(k,data);
   }

   template <typename Key>
   void push_back(const Key& k)
   {
      this->manip_top().get_container().push_back(k);
   }
   template <typename Key, typename Data>
   void push_back(const Key& k, const Data& data)
   {
      this->manip_top().get_container().push_back(k,data);
   }
   void pop_front()
   {
      this->manip_top().get_container().pop_front();
   }
   void pop_back()
   {
      this->manip_top().get_container().pop_back();
   }

   bool tree_form() const
   {
      return this->manip_top().get_container().tree_form();
   }
   Int max_size() const
   {
      return this->manip_top().get_container().max_size();
   }
   void clear()
   {
      this->manip_top().get_container().clear();
   }

   const typename tree_type::key_comparator_type&
   get_comparator() const
   {
      return this->manip_top().get_container().get_comparator();
   }
};

} // end namespace pm


// Local Variables:
// mode:C++
// c-basic-offset:3
// indent-tabs-mode:nil
// End: