Interface Documentation
Version: invalid
reorder.hh
Go to the documentation of this file.
1 /*
2  @@@@@@@@ @@ @@@@@@ @@@@@@@@ @@
3  /@@///// /@@ @@////@@ @@////// /@@
4  /@@ /@@ @@@@@ @@ // /@@ /@@
5  /@@@@@@@ /@@ @@///@@/@@ /@@@@@@@@@/@@
6  /@@//// /@@/@@@@@@@/@@ ////////@@/@@
7  /@@ /@@/@@//// //@@ @@ /@@/@@
8  /@@ @@@//@@@@@@ //@@@@@@ @@@@@@@@ /@@
9  // /// ////// ////// //////// //
10 
11  Copyright (c) 2016, Los Alamos National Security, LLC
12  All rights reserved.
13  */
14 #pragma once
15 
18 #include <iterator>
19 #include <utility>
20 
21 namespace flecsi {
22 namespace util {
23 
31 template<typename order_iterator, typename value_iterator>
32 void
33 reorder(const order_iterator order_begin,
34  const order_iterator order_end,
35  const value_iterator v) {
36  using index_t = typename std::iterator_traits<order_iterator>::value_type;
37  using diff_t = typename std::iterator_traits<order_iterator>::difference_type;
38 
39  auto remaining = order_end - 1 - order_begin;
40  for(index_t s = index_t(), d; remaining > 0; ++s) {
41  for(d = order_begin[diff_t(s)]; d > s; d = order_begin[diff_t(d)])
42  ;
43  if(d == s) {
44  --remaining;
45  auto temp = v[diff_t(s)];
46  while(d = order_begin[diff_t(d)], d != s) {
47  std::swap(temp, v[diff_t(d)]);
48  --remaining;
49  }
50  v[diff_t(s)] = temp;
51  }
52  }
53 }
54 
62 template<typename order_iterator, typename value_iterator>
63 void
64 reorder_destructive(const order_iterator order_begin,
65  const order_iterator order_end,
66  const value_iterator v) {
67  using index_t = typename std::iterator_traits<order_iterator>::value_type;
68  using diff_t = typename std::iterator_traits<order_iterator>::difference_type;
69 
70  auto remaining = order_end - 1 - order_begin;
71  for(auto s = index_t(); remaining > 0; ++s) {
72  auto d = order_begin[diff_t(s)];
73  if(d == index_t(-1))
74  continue;
75  --remaining;
76  auto temp = v[diff_t(s)];
77  for(index_t d2; d != s; d = d2) {
78  std::swap(temp, v[diff_t(d)]);
79  std::swap(order_begin[diff_t(d)], d2 = index_t(-1));
80  --remaining;
81  }
82  v[diff_t(s)] = temp;
83  }
84 }
85 
86 } // namespace util
87 } // namespace flecsi
void reorder(const order_iterator order_begin, const order_iterator order_end, const value_iterator v)
Reorders an array in place.
Definition: reorder.hh:33
void reorder_destructive(const order_iterator order_begin, const order_iterator order_end, const value_iterator v)
Reorders an array in place.
Definition: reorder.hh:64
Definition: control.hh:31