Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_UtilityAlgs.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Panzer: A partial differential equation assembly
4 // engine for strongly coupled complex multiphysics systems
5 //
6 // Copyright 2011 NTESS and the Panzer contributors.
7 // SPDX-License-Identifier: BSD-3-Clause
8 // *****************************************************************************
9 // @HEADER
10 
11 #include "Panzer_UtilityAlgs.hpp"
12 
13 namespace panzer{
14 
15 void reorder(std::vector<int> & order,std::function<void(int,int)> swapper)
16 {
17  // each entry has to be sorted
18  for(int i=0;i<static_cast<int>(order.size());i++) {
19 
20  // a, b, c
21  // 2, 0, 1
22 
23  // here we are following a linked list until
24  // the entry is correct
25  while(order[i]!=i) {
26  int nearIndex = order[i]; // 2 : 1
27  int farIndex = order[nearIndex]; // 1 : 0
28 
29  // handle the user defined swap of indices
30  swapper(nearIndex,farIndex); // a, c, b : c, a, b
31 
32  order[order[i]] = nearIndex; //
33  order[i] = farIndex; // 1, 0, 2 : 0, 1, 2
34  }
35  }
36 
37  // at the end of this, order vector will be sorted
38 }
39 
40 } // end namespace panzer
void reorder(std::vector< int > &order, std::function< void(int, int)> swapper)
Using a functor, reorder an array using a order vector.