21#ifndef ABC__sat__xSAT__xsatHeap_h
22#define ABC__sat__xSAT__xsatHeap_h
53 return Vec_IntSize( h->vHeap );
69 return (
Var < Vec_IntSize( h->vIndices ) ) && ( Vec_IntEntry( h->vIndices,
Var ) >= 0 );
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 )
77 return (
unsigned )Vec_IntEntry(
p->vActivity, x ) > ( unsigned )Vec_IntEntry(
p->vActivity, y );
91static inline void xSAT_HeapPercolateUp(
xSAT_Heap_t * h,
int i )
93 int x = Vec_IntEntry( h->vHeap, i );
96 while ( i != 0 && Compare( h, x, Vec_IntEntry( h->vHeap,
p ) ) )
98 Vec_IntWriteEntry( h->vHeap, i, Vec_IntEntry( h->vHeap,
p ) );
99 Vec_IntWriteEntry( h->vIndices, Vec_IntEntry( h->vHeap,
p ), i );
103 Vec_IntWriteEntry( h->vHeap, i, x );
104 Vec_IntWriteEntry( h->vIndices, x, i );
118static inline void xSAT_HeapPercolateDown(
xSAT_Heap_t * h,
int i )
120 int x = Vec_IntEntry( h->vHeap, i );
122 while ( Left( i ) < Vec_IntSize( h->vHeap ) )
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 );
128 if ( !Compare( h, Vec_IntEntry( h->vHeap, child ), x ) )
131 Vec_IntWriteEntry( h->vHeap, i, Vec_IntEntry( h->vHeap, child ) );
132 Vec_IntWriteEntry( h->vIndices, Vec_IntEntry( h->vHeap, i ), i );
135 Vec_IntWriteEntry( h->vHeap, i, x );
136 Vec_IntWriteEntry( h->vIndices, x, i );
157 p->vActivity = vActivity;
158 p->vIndices = Vec_IntAlloc( 0 );
159 p->vHeap = Vec_IntAlloc( 0 );
177 Vec_IntFree(
p->vIndices );
178 Vec_IntFree(
p->vHeap );
193static inline void xSAT_HeapIncrease(
xSAT_Heap_t * h,
int e )
195 assert( xSAT_HeapInHeap( h, e ) );
196 xSAT_HeapPercolateDown( h, Vec_IntEntry( h->vIndices, e ) );
210static inline void xSAT_HeapDecrease(
xSAT_Heap_t *
p,
int e )
212 assert( xSAT_HeapInHeap(
p, e ) );
213 xSAT_HeapPercolateUp(
p , Vec_IntEntry(
p->vIndices, e ) );
227static inline void xSAT_HeapInsert(
xSAT_Heap_t *
p,
int n )
229 Vec_IntFillExtra(
p->vIndices, n + 1, -1);
230 assert( !xSAT_HeapInHeap(
p, n ) );
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 ) );
248static inline void xSAT_HeapUpdate(
xSAT_Heap_t *
p,
int i )
250 if ( !xSAT_HeapInHeap(
p, i ) )
251 xSAT_HeapInsert(
p, i );
254 xSAT_HeapPercolateUp(
p, Vec_IntEntry(
p->vIndices, i ) );
255 xSAT_HeapPercolateDown(
p, Vec_IntEntry(
p->vIndices, i ) );
275 Vec_IntWriteEntry(
p->vIndices,
Var, -1 );
276 Vec_IntClear(
p->vHeap );
280 Vec_IntWriteEntry(
p->vIndices,
Var, i );
281 Vec_IntPush(
p->vHeap,
Var );
284 for ( ( i = Vec_IntSize(
p->vHeap ) / 2 - 1 ); i >= 0; i-- )
285 xSAT_HeapPercolateDown(
p, i );
301 Vec_IntFill(
p->vIndices, Vec_IntSize(
p->vIndices ), -1 );
302 Vec_IntClear(
p->vHeap );
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 );
#define ABC_ALLOC(type, num)
#define ABC_NAMESPACE_HEADER_END
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
typedefABC_NAMESPACE_HEADER_START struct xSAT_Heap_t_ xSAT_Heap_t
STRUCTURE DEFINITIONS ///.