6 #include <initializer_list> 12 namespace wavepackets {
14 namespace shape_enum {
34 template<
class Input1,
class Input2,
class Output,
class Compare>
35 Output
strict_union(Input1 begin1, Input1 end1, Input2 begin2, Input2 end2, Output sink, Compare less)
40 while (it1 != end1 && it2 != end2) {
48 else if ( less(*it1, *it2) ) {
62 sink = std::copy(it1, end1, sink);
63 sink = std::copy(it2, end2, sink);
68 template<
class MultiIndex>
81 std::less<MultiIndex> less;
82 return less(lhs.
value, value);
89 template<
class MultiIndex>
90 std::vector<MultiIndex>
strict_union(std::vector<
typename std::vector<MultiIndex>::const_iterator > begin,
91 std::vector<
typename std::vector<MultiIndex>::const_iterator > end)
93 assert( begin.size() == end.size() );
98 std::size_t minsize = 0;
99 for (std::size_t i = 0; i < begin.size(); i++) {
100 minsize = std::max(minsize, static_cast<std::size_t>(end[i] - begin[i]));
103 std::vector<MultiIndex> superset;
104 std::vector< HeapEntry > heap;
107 for (std::size_t i = 0; i < begin.size(); i++) {
108 if (begin[i] != end[i]) {
109 heap.push_back( HeapEntry{*(begin[i]), i} );
110 std::push_heap(heap.begin(), heap.end());
114 std::make_heap(heap.begin(), heap.end());
117 while (!heap.empty()) {
118 HeapEntry entry = heap.front();
119 std::pop_heap(heap.begin(), heap.end()); heap.pop_back();
121 if (superset.empty() || entry.value != superset.back()) {
122 std::less<MultiIndex> less;
125 assert( superset.empty() || less(superset.back(), entry.value) );
126 superset.push_back(entry.value);
129 if ( begin[entry.source] != end[entry.source] ) {
130 heap.push_back( HeapEntry{*(begin[entry.source]), entry.source} );
131 std::push_heap(heap.begin(), heap.end());
132 (begin[entry.source])++;
139 template<dim_t D,
class MultiIndex>
142 std::vector< typename std::vector<MultiIndex>::const_iterator > begin(slices.size());
143 std::vector< typename std::vector<MultiIndex>::const_iterator > end(slices.size());
145 for (std::size_t i = 0; i < slices.size(); i++) {
146 begin[i] = slices[i]->cbegin();
147 end[i] = slices[i]->cend();
150 std::vector<MultiIndex> superset = strict_union<MultiIndex>(begin, end);
152 return {std::move(superset), union_offset};
155 template<dim_t D,
class MultiIndex>
161 for (
auto _enum : enums) {
162 n_slices = std::max(n_slices, _enum->n_slices());
163 for (
dim_t d = 0; d < D; d++) {
164 limits[d] = std::max((
int)limits[d], _enum->limit(d));
169 std::size_t offset = 0;
170 std::vector< ShapeSlice<D,MultiIndex> > superset(n_slices);
171 for (
int islice = 0; islice < n_slices; islice++) {
172 std::vector< const ShapeSlice<D, MultiIndex>* > slices;
174 auto slice = &enums[
source]->slice(islice);
175 if (slice->size() != 0) {
176 slices.push_back(slice);
179 superset[islice] = strict_union<D,MultiIndex>(slices, offset);
180 offset += superset[islice].size();
183 return {std::move(superset), offset, limits};
191 template<dim_t D,
class MultiIndex, std::
size_t N>
194 std::vector< const ShapeEnum<D, MultiIndex>* > enum_vec(enum_list.cbegin(), enum_list.cend());
195 return strict_union<D,MultiIndex>(enum_vec);
202 template<dim_t D,
class MultiIndex, std::
size_t N>
205 std::vector< const ShapeEnum<D, MultiIndex>* > enum_vec(enum_list.cbegin(), enum_list.cend());
206 return strict_union<D,MultiIndex>(enum_vec);
213 template<dim_t D,
class MultiIndex>
216 std::vector< const ShapeEnum<D, MultiIndex>* > enum_vec(enum_list);
217 return strict_union<D,MultiIndex>(enum_vec);
Definition: coefficients_file_parser.cpp:10
std::size_t source
Definition: shape_enum_union.hpp:73
MultiIndex value
Definition: shape_enum_union.hpp:72
Output strict_union(Input1 begin1, Input1 end1, Input2 begin2, Input2 end2, Output sink, Compare less)
Creates union of two shape slices.
Definition: shape_enum_union.hpp:35
A shape enumeration is a complete, ordered list of all lattice nodes that are part of the basis shape...
Definition: shape_enum.hpp:353
bool operator<(const _strict_union__heap_entry &lhs) const
Definition: shape_enum_union.hpp:75
The -th slice of a shape enumeration contains all multi-indices that satisfy .
Definition: shape_enum.hpp:18
Definition: shape_enum_union.hpp:69
int dim_t
Definition: types.hpp:16