ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
xsatHeap.h
Go to the documentation of this file.
1
21#ifndef ABC__sat__xSAT__xsatHeap_h
22#define ABC__sat__xSAT__xsatHeap_h
23
25#include "misc/vec/vecInt.h"
26
28
39
51static inline int xSAT_HeapSize( xSAT_Heap_t * h )
52{
53 return Vec_IntSize( h->vHeap );
54}
55
67static inline int xSAT_HeapInHeap( xSAT_Heap_t * h, int Var )
68{
69 return ( Var < Vec_IntSize( h->vIndices ) ) && ( Vec_IntEntry( h->vIndices, Var ) >= 0 );
70}
71
72static inline int Left ( int i ) { return 2 * i + 1; }
73static inline int Right ( int i ) { return ( i + 1 ) * 2; }
74static inline int Parent( int i ) { return ( i - 1 ) >> 1; }
75static inline int Compare( xSAT_Heap_t * p, int x, int y )
76{
77 return ( unsigned )Vec_IntEntry( p->vActivity, x ) > ( unsigned )Vec_IntEntry( p->vActivity, y );
78}
79
91static inline void xSAT_HeapPercolateUp( xSAT_Heap_t * h, int i )
92{
93 int x = Vec_IntEntry( h->vHeap, i );
94 int p = Parent( i );
95
96 while ( i != 0 && Compare( h, x, Vec_IntEntry( h->vHeap, p ) ) )
97 {
98 Vec_IntWriteEntry( h->vHeap, i, Vec_IntEntry( h->vHeap, p ) );
99 Vec_IntWriteEntry( h->vIndices, Vec_IntEntry( h->vHeap, p ), i );
100 i = p;
101 p = Parent(p);
102 }
103 Vec_IntWriteEntry( h->vHeap, i, x );
104 Vec_IntWriteEntry( h->vIndices, x, i );
105}
106
118static inline void xSAT_HeapPercolateDown( xSAT_Heap_t * h, int i )
119{
120 int x = Vec_IntEntry( h->vHeap, i );
121
122 while ( Left( i ) < Vec_IntSize( h->vHeap ) )
123 {
124 int child = Right( i ) < Vec_IntSize( h->vHeap ) &&
125 Compare( h, Vec_IntEntry( h->vHeap, Right( i ) ), Vec_IntEntry( h->vHeap, Left( i ) ) ) ?
126 Right( i ) : Left( i );
127
128 if ( !Compare( h, Vec_IntEntry( h->vHeap, child ), x ) )
129 break;
130
131 Vec_IntWriteEntry( h->vHeap, i, Vec_IntEntry( h->vHeap, child ) );
132 Vec_IntWriteEntry( h->vIndices, Vec_IntEntry( h->vHeap, i ), i );
133 i = child;
134 }
135 Vec_IntWriteEntry( h->vHeap, i, x );
136 Vec_IntWriteEntry( h->vIndices, x, i );
137}
138
142
154static inline xSAT_Heap_t * xSAT_HeapAlloc( Vec_Int_t * vActivity )
155{
157 p->vActivity = vActivity;
158 p->vIndices = Vec_IntAlloc( 0 );
159 p->vHeap = Vec_IntAlloc( 0 );
160
161 return p;
162}
163
175static inline void xSAT_HeapFree( xSAT_Heap_t * p )
176{
177 Vec_IntFree( p->vIndices );
178 Vec_IntFree( p->vHeap );
179 ABC_FREE( p );
180}
181
193static inline void xSAT_HeapIncrease( xSAT_Heap_t * h, int e )
194{
195 assert( xSAT_HeapInHeap( h, e ) );
196 xSAT_HeapPercolateDown( h, Vec_IntEntry( h->vIndices, e ) );
197}
198
210static inline void xSAT_HeapDecrease( xSAT_Heap_t * p, int e )
211{
212 assert( xSAT_HeapInHeap( p, e ) );
213 xSAT_HeapPercolateUp( p , Vec_IntEntry( p->vIndices, e ) );
214}
215
227static inline void xSAT_HeapInsert( xSAT_Heap_t * p, int n )
228{
229 Vec_IntFillExtra( p->vIndices, n + 1, -1);
230 assert( !xSAT_HeapInHeap( p, n ) );
231
232 Vec_IntWriteEntry( p->vIndices, n, Vec_IntSize( p->vHeap ) );
233 Vec_IntPush( p->vHeap, n );
234 xSAT_HeapPercolateUp( p, Vec_IntEntry( p->vIndices, n ) );
235}
236
248static inline void xSAT_HeapUpdate( xSAT_Heap_t * p, int i )
249{
250 if ( !xSAT_HeapInHeap( p, i ) )
251 xSAT_HeapInsert( p, i );
252 else
253 {
254 xSAT_HeapPercolateUp( p, Vec_IntEntry( p->vIndices, i ) );
255 xSAT_HeapPercolateDown( p, Vec_IntEntry( p->vIndices, i ) );
256 }
257}
258
270static inline void xSAT_HeapBuild( xSAT_Heap_t * p, Vec_Int_t * Vars )
271{
272 int i, Var;
273
274 Vec_IntForEachEntry( p->vHeap, Var, i )
275 Vec_IntWriteEntry( p->vIndices, Var, -1 );
276 Vec_IntClear( p->vHeap );
277
278 Vec_IntForEachEntry( Vars, Var, i )
279 {
280 Vec_IntWriteEntry( p->vIndices, Var, i );
281 Vec_IntPush( p->vHeap, Var );
282 }
283
284 for ( ( i = Vec_IntSize( p->vHeap ) / 2 - 1 ); i >= 0; i-- )
285 xSAT_HeapPercolateDown( p, i );
286}
287
299static inline void xSAT_HeapClear( xSAT_Heap_t * p )
300{
301 Vec_IntFill( p->vIndices, Vec_IntSize( p->vIndices ), -1 );
302 Vec_IntClear( p->vHeap );
303}
304
316static inline int xSAT_HeapRemoveMin( xSAT_Heap_t * p )
317{
318 int x = Vec_IntEntry( p->vHeap, 0 );
319 Vec_IntWriteEntry( p->vHeap, 0, Vec_IntEntryLast( p->vHeap ) );
320 Vec_IntWriteEntry( p->vIndices, Vec_IntEntry( p->vHeap, 0), 0 );
321 Vec_IntWriteEntry( p->vIndices, x, -1 );
322 Vec_IntPop( p->vHeap );
323 if ( Vec_IntSize( p->vHeap ) > 1 )
324 xSAT_HeapPercolateDown( p, 0 );
325 return x;
326}
327
329
330#endif
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_HEADER_END
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Cube * p
Definition exorList.c:222
int Var
Definition exorList.c:228
Vec_Int_t * vActivity
Definition xsatHeap.h:35
Vec_Int_t * vIndices
Definition xsatHeap.h:36
Vec_Int_t * vHeap
Definition xsatHeap.h:37
#define assert(ex)
Definition util_old.h:213
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
typedefABC_NAMESPACE_HEADER_START struct xSAT_Heap_t_ xSAT_Heap_t
STRUCTURE DEFINITIONS ///.
Definition xsatHeap.h:32