ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
satVec.h
Go to the documentation of this file.
1/**************************************************************************************************
2MiniSat -- Copyright (c) 2005, Niklas Sorensson
3http://www.cs.chalmers.se/Cs/Research/FormalMethods/MiniSat/
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// 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
26
28
29
30// vector of 32-bit intergers (added for 64-bit portability)
31struct veci_t {
32 int cap;
33 int size;
34 int* ptr;
35};
36typedef struct veci_t veci;
37
38static 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
44static inline void veci_delete (veci* v) { ABC_FREE(v->ptr); }
45static inline int* veci_begin (veci* v) { return v->ptr; }
46static inline int veci_size (veci* v) { return v->size; }
47static 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 !!
52static inline int veci_pop (veci* v) { assert(v->size); return v->ptr[--v->size]; }
53static 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}
68static 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
80struct vecp_t {
81 int cap;
82 int size;
83 void** ptr;
84};
85typedef struct vecp_t vecp;
86
87static 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
93static inline void vecp_delete (vecp* v) { ABC_FREE(v->ptr); }
94static inline void** vecp_begin (vecp* v) { return v->ptr; }
95static inline int vecp_size (vecp* v) { return v->size; }
96static inline void vecp_resize (vecp* v, int k) { assert(k <= v->size); v->size = k; } // only safe to shrink !!
97static 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}
106static 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
130typedef int lit;
131typedef int cla;
132
133// Explicitly make it signed so promotion-to-int behavior doesn't vary
134// across platforms that define signedness of char differently.
135typedef signed char lbool;
136
137static const int var_Undef = -1;
138static const lit lit_Undef = -2;
139
140static const lbool l_Undef = 0;
141static const lbool l_True = 1;
142static const lbool l_False = -1;
143
144static inline lit toLit (int v) { return v + v; }
145static inline lit toLitCond(int v, int c) { return v + v + (c != 0); }
146static inline lit lit_neg (lit l) { return l ^ 1; }
147static inline int lit_var (lit l) { return l >> 1; }
148static inline int lit_sign (lit l) { return l & 1; }
149static inline int lit_print(lit l) { return lit_sign(l)? -lit_var(l)-1 : lit_var(l)+1; }
150static inline lit lit_read (int s) { return s > 0 ? toLit(s-1) : lit_neg(toLit(-s-1)); }
151static inline int lit_check(lit l, int n) { return l >= 0 && lit_var(l) < n; }
152
159typedef struct stats_t stats_t;
160
162
163#endif
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_REALLOC(type, obj, num)
Definition abc_global.h:268
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_HEADER_END
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
#define l_True
Definition bmcBmcS.c:35
#define l_Undef
Definition bmcBmcS.c:34
#define l_False
Definition bmcBmcS.c:36
#define var_Undef
Definition SolverTypes.h:45
int lit
Definition satVec.h:130
int cla
Definition satVec.h:131
struct veci_t veci
Definition satVec.h:36
signed char lbool
Definition satVec.h:135
struct vecp_t vecp
Definition satVec.h:85
ABC_INT64_T decisions
Definition satVec.h:156
ABC_INT64_T learnts_literals
Definition satVec.h:157
ABC_INT64_T conflicts
Definition satVec.h:156
ABC_INT64_T tot_literals
Definition satVec.h:157
unsigned clauses
Definition satVec.h:155
unsigned starts
Definition satVec.h:155
ABC_INT64_T inspects
Definition satVec.h:156
ABC_INT64_T clauses_literals
Definition satVec.h:157
unsigned learnts
Definition satVec.h:155
ABC_INT64_T propagations
Definition satVec.h:156
int size
Definition satVec.h:33
int * ptr
Definition satVec.h:34
int cap
Definition satVec.h:32
int cap
Definition satVec.h:81
void ** ptr
Definition satVec.h:83
int size
Definition satVec.h:82
#define assert(ex)
Definition util_old.h:213