abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
extraUtilBitMatrix.c File Reference
#include "extra.h"

Go to the source code of this file.

Data Structures

struct  Extra_BitMat_t_
 

Functions

Extra_BitMat_tExtra_BitMatrixStart (int nSize)
 
void Extra_BitMatrixClean (Extra_BitMat_t *p)
 
void Extra_BitMatrixStop (Extra_BitMat_t *p)
 
void Extra_BitMatrixPrint (Extra_BitMat_t *pMat)
 
int Extra_BitMatrixReadSize (Extra_BitMat_t *p)
 
void Extra_BitMatrixInsert1 (Extra_BitMat_t *p, int i, int k)
 
int Extra_BitMatrixLookup1 (Extra_BitMat_t *p, int i, int k)
 
void Extra_BitMatrixDelete1 (Extra_BitMat_t *p, int i, int k)
 
void Extra_BitMatrixInsert2 (Extra_BitMat_t *p, int i, int k)
 
int Extra_BitMatrixLookup2 (Extra_BitMat_t *p, int i, int k)
 
void Extra_BitMatrixDelete2 (Extra_BitMat_t *p, int i, int k)
 
void Extra_BitMatrixOr (Extra_BitMat_t *p, int i, unsigned *pInfo)
 
void Extra_BitMatrixOrTwo (Extra_BitMat_t *p, int i, int j)
 
int Extra_BitMatrixCountOnesUpper (Extra_BitMat_t *p)
 
int Extra_BitMatrixIsDisjoint (Extra_BitMat_t *p1, Extra_BitMat_t *p2)
 
int Extra_BitMatrixIsClique (Extra_BitMat_t *pMat)
 

Function Documentation

void Extra_BitMatrixClean ( Extra_BitMat_t p)

Function*************************************************************

Synopsis [Stops the bit matrix.]

Description []

SideEffects []

SeeAlso []

Definition at line 110 of file extraUtilBitMatrix.c.

111 {
112  memset( p->ppData[0], 0, sizeof(unsigned) * p->nSize * p->nWords );
113 }
char * memset()
int Extra_BitMatrixCountOnesUpper ( Extra_BitMat_t p)

Function*************************************************************

Synopsis [Counts the number of 1's in the upper rectangle.]

Description []

SideEffects []

SeeAlso []

Definition at line 349 of file extraUtilBitMatrix.c.

350 {
351  int i, k, nTotal = 0;
352  for ( i = 0; i < p->nSize; i++ )
353  for ( k = i + 1; k < p->nSize; k++ )
354  nTotal += ( (p->ppData[i][k>>5] & (1 << (k&31))) > 0 );
355  return nTotal;
356 }
int nTotal
DECLARATIONS ///.
Definition: cutTruth.c:37
void Extra_BitMatrixDelete1 ( Extra_BitMat_t p,
int  i,
int  k 
)

Function*************************************************************

Synopsis [Inserts the element into the upper part.]

Description []

SideEffects []

SeeAlso []

Definition at line 230 of file extraUtilBitMatrix.c.

231 {
232  p->nDeletes++;
233  if ( i < k )
234  p->ppData[i][k>>p->nBitShift] &= ~(1<<(k & p->uMask));
235  else
236  p->ppData[k][i>>p->nBitShift] &= ~(1<<(i & p->uMask));
237 }
void Extra_BitMatrixDelete2 ( Extra_BitMat_t p,
int  i,
int  k 
)

Function*************************************************************

Synopsis [Inserts the element into the upper part.]

Description []

SideEffects []

SeeAlso []

Definition at line 292 of file extraUtilBitMatrix.c.

293 {
294  p->nDeletes++;
295  if ( i > k )
296  p->ppData[i][k>>p->nBitShift] &= ~(1<<(k & p->uMask));
297  else
298  p->ppData[k][i>>p->nBitShift] &= ~(1<<(i & p->uMask));
299 }
void Extra_BitMatrixInsert1 ( Extra_BitMat_t p,
int  i,
int  k 
)

Function*************************************************************

Synopsis [Inserts the element into the upper part.]

Description []

SideEffects []

SeeAlso []

Definition at line 190 of file extraUtilBitMatrix.c.

191 {
192  p->nInserts++;
193  if ( i < k )
194  p->ppData[i][k>>p->nBitShift] |= (1<<(k & p->uMask));
195  else
196  p->ppData[k][i>>p->nBitShift] |= (1<<(i & p->uMask));
197 }
void Extra_BitMatrixInsert2 ( Extra_BitMat_t p,
int  i,
int  k 
)

Function*************************************************************

Synopsis [Inserts the element into the upper part.]

Description []

SideEffects []

SeeAlso []

Definition at line 252 of file extraUtilBitMatrix.c.

253 {
254  p->nInserts++;
255  if ( i > k )
256  p->ppData[i][k>>p->nBitShift] |= (1<<(k & p->uMask));
257  else
258  p->ppData[k][i>>p->nBitShift] |= (1<<(i & p->uMask));
259 }
int Extra_BitMatrixIsClique ( Extra_BitMat_t pMat)

Function*************************************************************

Synopsis [Returns 1 if the matrix is a set of cliques.]

Description [For example pairwise symmetry info should satisfy this property.]

SideEffects []

SeeAlso []

Definition at line 391 of file extraUtilBitMatrix.c.

392 {
393  int v, u, i;
394  for ( v = 0; v < pMat->nSize; v++ )
395  for ( u = v+1; u < pMat->nSize; u++ )
396  {
397  if ( !Extra_BitMatrixLookup1( pMat, v, u ) )
398  continue;
399  // v and u are symmetric
400  for ( i = 0; i < pMat->nSize; i++ )
401  {
402  if ( i == v || i == u )
403  continue;
404  // i is neither v nor u
405  // the symmetry status of i is the same w.r.t. to v and u
406  if ( Extra_BitMatrixLookup1( pMat, i, v ) != Extra_BitMatrixLookup1( pMat, i, u ) )
407  return 0;
408  }
409  }
410  return 1;
411 }
int Extra_BitMatrixLookup1(Extra_BitMat_t *p, int i, int k)
int Extra_BitMatrixIsDisjoint ( Extra_BitMat_t p1,
Extra_BitMat_t p2 
)

Function*************************************************************

Synopsis [Returns 1 if the matrices have no entries in common.]

Description []

SideEffects []

SeeAlso []

Definition at line 369 of file extraUtilBitMatrix.c.

370 {
371  int i, w;
372  assert( p1->nSize == p2->nSize );
373  for ( i = 0; i < p1->nSize; i++ )
374  for ( w = 0; w < p1->nWords; w++ )
375  if ( p1->ppData[i][w] & p2->ppData[i][w] )
376  return 0;
377  return 1;
378 }
#define assert(ex)
Definition: util_old.h:213
int Extra_BitMatrixLookup1 ( Extra_BitMat_t p,
int  i,
int  k 
)

Function*************************************************************

Synopsis [Inserts the element into the upper part.]

Description []

SideEffects []

SeeAlso []

Definition at line 210 of file extraUtilBitMatrix.c.

211 {
212  p->nLookups++;
213  if ( i < k )
214  return ((p->ppData[i][k>>p->nBitShift] & (1<<(k & p->uMask))) > 0);
215  else
216  return ((p->ppData[k][i>>p->nBitShift] & (1<<(i & p->uMask))) > 0);
217 }
int Extra_BitMatrixLookup2 ( Extra_BitMat_t p,
int  i,
int  k 
)

Function*************************************************************

Synopsis [Inserts the element into the upper part.]

Description []

SideEffects []

SeeAlso []

Definition at line 272 of file extraUtilBitMatrix.c.

273 {
274  p->nLookups++;
275  if ( i > k )
276  return ((p->ppData[i][k>>p->nBitShift] & (1<<(k & p->uMask))) > 0);
277  else
278  return ((p->ppData[k][i>>p->nBitShift] & (1<<(i & p->uMask))) > 0);
279 }
void Extra_BitMatrixOr ( Extra_BitMat_t p,
int  i,
unsigned *  pInfo 
)

Function*************************************************************

Synopsis [Inserts the element into the upper part.]

Description []

SideEffects []

SeeAlso []

Definition at line 313 of file extraUtilBitMatrix.c.

314 {
315  int w;
316  for ( w = 0; w < p->nWords; w++ )
317  p->ppData[i][w] |= pInfo[w];
318 }
void Extra_BitMatrixOrTwo ( Extra_BitMat_t p,
int  i,
int  j 
)

Function*************************************************************

Synopsis [Inserts the element into the upper part.]

Description []

SideEffects []

SeeAlso []

Definition at line 331 of file extraUtilBitMatrix.c.

332 {
333  int w;
334  for ( w = 0; w < p->nWords; w++ )
335  p->ppData[i][w] = p->ppData[j][w] = (p->ppData[i][w] | p->ppData[j][w]);
336 }
void Extra_BitMatrixPrint ( Extra_BitMat_t pMat)

Function*************************************************************

Synopsis [Prints the bit-matrix.]

Description []

SideEffects []

SeeAlso []

Definition at line 144 of file extraUtilBitMatrix.c.

145 {
146  int i, k, nVars;
147  printf( "\n" );
148  nVars = Extra_BitMatrixReadSize( pMat );
149  for ( i = 0; i < nVars; i++ )
150  {
151  for ( k = 0; k <= i; k++ )
152  printf( " " );
153  for ( k = i+1; k < nVars; k++ )
154  if ( Extra_BitMatrixLookup1( pMat, i, k ) )
155  printf( "1" );
156  else
157  printf( "." );
158  printf( "\n" );
159  }
160 }
int Extra_BitMatrixReadSize(Extra_BitMat_t *p)
int Extra_BitMatrixLookup1(Extra_BitMat_t *p, int i, int k)
int Extra_BitMatrixReadSize ( Extra_BitMat_t p)

Function*************************************************************

Synopsis [Reads the matrix size.]

Description []

SideEffects []

SeeAlso []

Definition at line 174 of file extraUtilBitMatrix.c.

175 {
176  return p->nSize;
177 }
Extra_BitMat_t* Extra_BitMatrixStart ( int  nSize)

AutomaticStart AutomaticEnd Function*************************************************************

Synopsis [Starts the bit matrix.]

Description []

SideEffects []

SeeAlso []

Definition at line 81 of file extraUtilBitMatrix.c.

82 {
83  Extra_BitMat_t * p;
84  int i;
85  p = ABC_ALLOC( Extra_BitMat_t, 1 );
86  memset( p, 0, sizeof(Extra_BitMat_t) );
87  p->nSize = nSize;
88  p->nBitShift = (sizeof(unsigned) == 4) ? 5: 6;
89  p->uMask = (sizeof(unsigned) == 4) ? 31: 63;
90  p->nWords = nSize / (8 * sizeof(unsigned)) + ((nSize % (8 * sizeof(unsigned))) > 0);
91  p->ppData = ABC_ALLOC( unsigned *, nSize );
92  p->ppData[0] = ABC_ALLOC( unsigned, nSize * p->nWords );
93  memset( p->ppData[0], 0, sizeof(unsigned) * nSize * p->nWords );
94  for ( i = 1; i < nSize; i++ )
95  p->ppData[i] = p->ppData[i-1] + p->nWords;
96  return p;
97 }
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
void Extra_BitMatrixStop ( Extra_BitMat_t p)

Function*************************************************************

Synopsis [Stops the bit matrix.]

Description []

SideEffects []

SeeAlso []

Definition at line 126 of file extraUtilBitMatrix.c.

127 {
128  ABC_FREE( p->ppData[0] );
129  ABC_FREE( p->ppData );
130  ABC_FREE( p );
131 }
#define ABC_FREE(obj)
Definition: abc_global.h:232