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