SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
Alg.h
Go to the documentation of this file.
1 /*******************************************************************************************[Alg.h]
2 Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
3 Copyright (c) 2007-2010, Niklas Sorensson
4 
5 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6 associated documentation files (the "Software"), to deal in the Software without restriction,
7 including without limitation the rights to use, copy, modify, merge, publish, distribute,
8 sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in all copies or
12 substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
15 NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
18 OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 **************************************************************************************************/
20 
21 #ifndef Minisat_Alg_h
22 #define Minisat_Alg_h
23 
24 #include "Vec.h"
25 
26 namespace Minisat
27 {
28  //=================================================================================================
29  // Useful functions on vector-like types:
30 
31  //=================================================================================================
32  // Removing and searching for elements:
33  //
34 
35  template<class V, class T>
36  static inline void remove( V& ts, const T& t )
37  {
38  int j = 0;
39  for( ; j < ts.size() && ts[j] != t; j++ );
40  assert( j < ts.size() );
41  for( ; j < ts.size() - 1; j++ )
42  ts[j] = ts[j + 1];
43  ts.pop();
44  }
45 
46  template<class V, class T>
47  static inline bool find( V& ts, const T& t )
48  {
49  int j = 0;
50  for( ; j < ts.size() && ts[j] != t; j++ );
51  return j < ts.size();
52  }
53 
54  //=================================================================================================
55  // Copying vectors with support for nested vector types:
56  //
57 
58  // Base case:
59  template<class T>
60  static inline void copy( const T& from, T& to )
61  {
62  to = from;
63  }
64 
65  // Recursive case:
66  template<class T>
67  static inline void copy( const vec<T>& from, vec<T>& to, bool append = false )
68  {
69  if( !append )
70  to.clear();
71  for( int i = 0; i < from.size(); i++ )
72  {
73  to.push();
74  copy( from[i], to.last() );
75  }
76  }
77 
78  template<class T>
79  static inline void append( const vec<T>& from, vec<T>& to )
80  {
81  copy( from, to, true );
82  }
83 
84  //=================================================================================================
85 }
86 
87 #endif
int size(void) const
Definition: Vec.h:118
const T & last(void) const
Definition: Vec.h:178
void clear(bool dealloc=false)
Definition: Vec.h:273
void push(void)
Definition: Vec.h:147
Definition: Alg.h:27
static bool find(V &ts, const T &t)
Definition: Alg.h:47
static void append(const vec< T > &from, vec< T > &to)
Definition: Alg.h:79
static void copy(const T &from, T &to)
Definition: Alg.h:60
static void remove(V &ts, const T &t)
Definition: Alg.h:36