abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
satVec.h
Go to the documentation of this file.
1 /**************************************************************************************************
2 MiniSat -- Copyright (c) 2005, Niklas Sorensson
3 http://www.cs.chalmers.se/Cs/Research/FormalMethods/MiniSat/
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 // Modified to compile with MS Visual Studio 6.0 by Alan Mishchenko
21 
22 #ifndef ABC__sat__bsat__satVec_h
23 #define ABC__sat__bsat__satVec_h
24 
25 #include "misc/util/abc_global.h"
26 
28 
29 
30 // vector of 32-bit intergers (added for 64-bit portability)
31 struct veci_t {
32  int cap;
33  int size;
34  int* ptr;
35 };
36 typedef struct veci_t veci;
37 
38 static inline void veci_new (veci* v) {
39  v->cap = 4;
40  v->size = 0;
41  v->ptr = (int*)ABC_ALLOC( char, sizeof(int)*v->cap);
42 }
43 
44 static inline void veci_delete (veci* v) { ABC_FREE(v->ptr); }
45 static inline int* veci_begin (veci* v) { return v->ptr; }
46 static inline int veci_size (veci* v) { return v->size; }
47 static inline void veci_resize (veci* v, int k) {
48  assert(k <= v->size);
49 // memset( veci_begin(v) + k, -1, sizeof(int) * (veci_size(v) - k) );
50  v->size = k;
51 } // only safe to shrink !!
52 static inline int veci_pop (veci* v) { assert(v->size); return v->ptr[--v->size]; }
53 static inline void veci_push (veci* v, int e)
54 {
55  if (v->size == v->cap) {
56 // int newsize = v->cap * 2;//+1;
57  int newsize = (v->cap < 4) ? v->cap * 2 : (v->cap / 2) * 3;
58  v->ptr = ABC_REALLOC( int, v->ptr, newsize );
59  if ( v->ptr == NULL )
60  {
61  printf( "Failed to realloc memory from %.1f MB to %.1f MB.\n",
62  1.0 * v->cap / (1<<20), 1.0 * newsize / (1<<20) );
63  fflush( stdout );
64  }
65  v->cap = newsize; }
66  v->ptr[v->size++] = e;
67 }
68 static inline void veci_remove(veci* v, int e)
69 {
70  int * ws = (int*)veci_begin(v);
71  int j = 0;
72  for (; ws[j] != e ; j++);
73  assert(j < veci_size(v));
74  for (; j < veci_size(v)-1; j++) ws[j] = ws[j+1];
75  veci_resize(v,veci_size(v)-1);
76 }
77 
78 
79 // vector of 32- or 64-bit pointers
80 struct vecp_t {
81  int cap;
82  int size;
83  void** ptr;
84 };
85 typedef struct vecp_t vecp;
86 
87 static inline void vecp_new (vecp* v) {
88  v->size = 0;
89  v->cap = 4;
90  v->ptr = (void**)ABC_ALLOC( char, sizeof(void*)*v->cap);
91 }
92 
93 static inline void vecp_delete (vecp* v) { ABC_FREE(v->ptr); }
94 static inline void** vecp_begin (vecp* v) { return v->ptr; }
95 static inline int vecp_size (vecp* v) { return v->size; }
96 static inline void vecp_resize (vecp* v, int k) { assert(k <= v->size); v->size = k; } // only safe to shrink !!
97 static inline void vecp_push (vecp* v, void* e)
98 {
99  if (v->size == v->cap) {
100 // int newsize = v->cap * 2;//+1;
101  int newsize = (v->cap < 4) ? v->cap * 2 : (v->cap / 2) * 3;
102  v->ptr = ABC_REALLOC( void*, v->ptr, newsize );
103  v->cap = newsize; }
104  v->ptr[v->size++] = e;
105 }
106 static inline void vecp_remove(vecp* v, void* e)
107 {
108  void** ws = vecp_begin(v);
109  int j = 0;
110  for (; ws[j] != e ; j++);
111  assert(j < vecp_size(v));
112  for (; j < vecp_size(v)-1; j++) ws[j] = ws[j+1];
113  vecp_resize(v,vecp_size(v)-1);
114 }
115 
116 
117 
118 //=================================================================================================
119 // Simple types:
120 
121 #ifndef __cplusplus
122 #ifndef false
123 # define false 0
124 #endif
125 #ifndef true
126 # define true 1
127 #endif
128 #endif
129 
130 typedef int lit;
131 typedef int cla;
132 
133 typedef char lbool;
134 
135 static const int var_Undef = -1;
136 static const lit lit_Undef = -2;
137 
138 static const lbool l_Undef = 0;
139 static const lbool l_True = 1;
140 static const lbool l_False = -1;
141 
142 static inline lit toLit (int v) { return v + v; }
143 static inline lit toLitCond(int v, int c) { return v + v + (c != 0); }
144 static inline lit lit_neg (lit l) { return l ^ 1; }
145 static inline int lit_var (lit l) { return l >> 1; }
146 static inline int lit_sign (lit l) { return l & 1; }
147 static inline int lit_print(lit l) { return lit_sign(l)? -lit_var(l)-1 : lit_var(l)+1; }
148 static inline lit lit_read (int s) { return s > 0 ? toLit(s-1) : lit_neg(toLit(-s-1)); }
149 static inline int lit_check(lit l, int n) { return l >= 0 && lit_var(l) < n; }
150 
151 struct stats_t
152 {
153  unsigned starts, clauses, learnts;
156 };
157 typedef struct stats_t stats_t;
158 
160 
161 #endif
static int lit_check(lit l, int n)
Definition: satVec.h:149
static const lbool l_False
Definition: satVec.h:140
ABC_INT64_T clauses_literals
Definition: satVec.h:155
char lbool
Definition: satVec.h:133
int * ptr
Definition: satVec.h:34
ABC_INT64_T tot_literals
Definition: satVec.h:155
static const int var_Undef
Definition: satVec.h:135
#define ABC_REALLOC(type, obj, num)
Definition: abc_global.h:233
static int lit_var(lit l)
Definition: satVec.h:145
static void veci_push(veci *v, int e)
Definition: satVec.h:53
static void veci_delete(veci *v)
Definition: satVec.h:44
Definition: satVec.h:31
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static void veci_resize(veci *v, int k)
Definition: satVec.h:47
ABC_INT64_T decisions
Definition: satVec.h:154
static void vecp_remove(vecp *v, void *e)
Definition: satVec.h:106
int cla
Definition: satVec.h:131
int lit
Definition: satVec.h:130
ABC_INT64_T learnts_literals
Definition: satVec.h:155
static lit lit_neg(lit l)
Definition: satVec.h:144
static void veci_new(veci *v)
Definition: satVec.h:38
static lit lit_read(int s)
Definition: satVec.h:148
static lit toLit(int v)
Definition: satVec.h:142
static void vecp_push(vecp *v, void *e)
Definition: satVec.h:97
int cap
Definition: satVec.h:81
static lit toLitCond(int v, int c)
Definition: satVec.h:143
static void vecp_delete(vecp *v)
Definition: satVec.h:93
static int veci_pop(veci *v)
Definition: satVec.h:52
static void veci_remove(veci *v, int e)
Definition: satVec.h:68
static int size
Definition: cuddSign.c:86
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
Definition: abc_global.h:105
#define ABC_NAMESPACE_HEADER_END
Definition: abc_global.h:106
static const lit lit_Undef
Definition: satVec.h:136
ABC_INT64_T inspects
Definition: satVec.h:154
int cap
Definition: satVec.h:32
unsigned learnts
Definition: satVec.h:153
ABC_INT64_T conflicts
Definition: satVec.h:154
int size
Definition: satVec.h:82
static int lit_sign(lit l)
Definition: satVec.h:146
unsigned clauses
Definition: satVec.h:153
#define ABC_FREE(obj)
Definition: abc_global.h:232
void ** ptr
Definition: satVec.h:83
static void vecp_resize(vecp *v, int k)
Definition: satVec.h:96
static const lbool l_True
Definition: satVec.h:139
ABC_INT64_T propagations
Definition: satVec.h:154
int size
Definition: satVec.h:33
#define assert(ex)
Definition: util_old.h:213
Definition: satVec.h:80
static const lbool l_Undef
Definition: satVec.h:138
unsigned starts
Definition: satVec.h:153
static int * veci_begin(veci *v)
Definition: satVec.h:45
static int veci_size(veci *v)
Definition: satVec.h:46
static void vecp_new(vecp *v)
Definition: satVec.h:87
static int vecp_size(vecp *v)
Definition: satVec.h:95
static void ** vecp_begin(vecp *v)
Definition: satVec.h:94
static int lit_print(lit l)
Definition: satVec.h:147