Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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#pragma once
22
24
25namespace Minisat {
26namespace Internal {
27
28//=================================================================================================
29// Useful functions on vector-like types:
30
31//=================================================================================================
32// Removing and searching for elements:
33//
34
35template<class V, class T>
36static 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++) ts[j] = ts[j+1];
42 ts.pop();
43}
44
45
46template<class V, class T>
47static 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//=================================================================================================
56// Copying vectors with support for nested vector types:
57//
58
59// Base case:
60template<class T>
61static inline void copy(const T& from, T& to)
62{
63 to = from;
64}
65
66// Recursive case:
67template<class T>
68static inline void copy(const vec<T>& from, vec<T>& to, bool append = false)
69{
70 if (!append)
71 to.clear();
72 for (int i = 0; i < from.size(); i++){
73 to.push();
74 copy(from[i], to.last());
75 }
76}
77
78template<class T>
79static inline void append(const vec<T>& from, vec<T>& to){ copy(from, to, true); }
80
81//=================================================================================================
82} // namespace Internal
83} // namespace Minisat
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
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:61
static bool find(V &ts, const T &t)
Definition Alg.h:47
static void remove(V &ts, const T &t)
Definition Alg.h:36