The ChainCon Software (Release 0.03)
remordered.h
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 ///
3 /// \file
4 ///
5 /// A utility procedure for removing an ordered set from another ordered set.
6 ///
7 /////////////////////////////////////////////////////////////////////////////
8 
9 // Copyright (C) 2009-2016 by Pawel Pilarczyk.
10 //
11 // This file is part of my research software package. This is free software:
12 // you can redistribute it and/or modify it under the terms of the GNU
13 // General Public License as published by the Free Software Foundation,
14 // either version 3 of the License, or (at your option) any later version.
15 //
16 // This software is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this software; see the file "license.txt". If not,
23 // please, see <http://www.gnu.org/licenses/>.
24 
25 // Started on March 24, 2009. Last revision: January 12, 2013.
26 
27 
28 #ifndef _CHAINCON_REMORDERED_H_
29 #define _CHAINCON_REMORDERED_H_
30 
31 
32 // include selected header files from the CHomP library
33 #include "chomp/system/config.h"
34 
35 
36 // --------------------------------------------------
37 // ----------------- remove ordered -----------------
38 // --------------------------------------------------
39 
40 /// From the given set of objects, removes another one in such a way
41 /// that the order of objects in the first one is preserved.
42 /// In order to achieve this, this procedure creates a new vector
43 /// that contains all the elements appearing in K that are not in L.
44 /// This procedure is intended to be applied to hashed sets
45 /// and filtered complexes, or to other containers that provide
46 /// a few basic interface features, as one can see in the code.
47 /// It is thus very inefficient and thus should be used with care.
48 template <class Vector1T, class Vector2T>
49 inline void removeOrdered (Vector1T &K, const Vector2T &L)
50 {
51  // check if there is any element in L that needs to be removed from K
52  int_t sizeL = L. size ();
53  bool disjoint = true;
54  for (int_t i = 0; i < sizeL; ++ i)
55  {
56  if (!K. check (L [i]))
57  continue;
58  disjoint = false;
59  break;
60  }
61  if (disjoint)
62  return;
63 
64  // prepare a new K
65  Vector1T M;
66  int_t sizeK = K. size ();
67  for (int_t i = 0; i < sizeK; ++ i)
68  {
69  if (!L. check (K [i]))
70  M. add (K [i]);
71  }
72  M. swap (K);
73 
74  return;
75 } /* removeOrdered */
76 
77 
78 #endif // _CHAINCON_REMORDERED_H_
79 
void removeOrdered(Vector1T &K, const Vector2T &L)
From the given set of objects, removes another one in such a way that the order of objects in the fir...
Definition: remordered.h:49