vecVec.h 20.5 KB
Newer Older
Alan Mishchenko committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/**CFile****************************************************************

  FileName    [vecVec.h]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Resizable arrays.]

  Synopsis    [Resizable vector of resizable vectors.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - June 20, 2005.]

  Revision    [$Id: vecVec.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]

***********************************************************************/
 
21 22
#ifndef ABC__misc__vec__vecVec_h
#define ABC__misc__vec__vecVec_h
Alan Mishchenko committed
23

24

Alan Mishchenko committed
25 26 27 28 29 30
////////////////////////////////////////////////////////////////////////
///                          INCLUDES                                ///
////////////////////////////////////////////////////////////////////////

#include <stdio.h>

31 32 33
ABC_NAMESPACE_HEADER_START


Alan Mishchenko committed
34 35 36 37 38 39 40 41 42 43 44
////////////////////////////////////////////////////////////////////////
///                         PARAMETERS                               ///
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
///                         BASIC TYPES                              ///
////////////////////////////////////////////////////////////////////////

typedef struct Vec_Vec_t_       Vec_Vec_t;
struct Vec_Vec_t_ 
{
Alan Mishchenko committed
45 46 47
    int              nCap;
    int              nSize;
    void **          pArray;
Alan Mishchenko committed
48 49 50
};

////////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
51
///                      MACRO DEFINITIONS                           ///
Alan Mishchenko committed
52 53 54 55
////////////////////////////////////////////////////////////////////////

// iterators through levels 
#define Vec_VecForEachLevel( vGlob, vVec, i )                                                 \
56
    for ( i = 0; (i < Vec_VecSize(vGlob)) && (((vVec) = Vec_VecEntry(vGlob, i)), 1); i++ )
Alan Mishchenko committed
57
#define Vec_VecForEachLevelStart( vGlob, vVec, i, LevelStart )                                \
58
    for ( i = LevelStart; (i < Vec_VecSize(vGlob)) && (((vVec) = Vec_VecEntry(vGlob, i)), 1); i++ )
59
#define Vec_VecForEachLevelStop( vGlob, vVec, i, LevelStop )                                  \
60
    for ( i = 0; (i < LevelStop) && (((vVec) = Vec_VecEntry(vGlob, i)), 1); i++ )
Alan Mishchenko committed
61
#define Vec_VecForEachLevelStartStop( vGlob, vVec, i, LevelStart, LevelStop )                 \
62
    for ( i = LevelStart; (i < LevelStop) && (((vVec) = Vec_VecEntry(vGlob, i)), 1); i++ )
Alan Mishchenko committed
63
#define Vec_VecForEachLevelReverse( vGlob, vVec, i )                                          \
64
    for ( i = Vec_VecSize(vGlob)-1; (i >= 0) && (((vVec) = Vec_VecEntry(vGlob, i)), 1); i-- )
Alan Mishchenko committed
65
#define Vec_VecForEachLevelReverseStartStop( vGlob, vVec, i, LevelStart, LevelStop )          \
66
    for ( i = LevelStart-1; (i >= LevelStop) && (((vVec) = Vec_VecEntry(vGlob, i)), 1); i-- )
67
#define Vec_VecForEachLevelTwo( vGlob1, vGlob2, vVec1, vVec2, i )                                                 \
68
    for ( i = 0; (i < Vec_VecSize(vGlob1)) && (((vVec1) = Vec_VecEntry(vGlob1, i)), 1) && (((vVec2) = Vec_VecEntry(vGlob2, i)), 1); i++ )
69 70 71

// iterators through levels 
#define Vec_VecForEachLevelInt( vGlob, vVec, i )                                              \
72
    for ( i = 0; (i < Vec_VecSize(vGlob)) && (((vVec) = Vec_VecEntryInt(vGlob, i)), 1); i++ )
73
#define Vec_VecForEachLevelIntStart( vGlob, vVec, i, LevelStart )                             \
74
    for ( i = LevelStart; (i < Vec_VecSize(vGlob)) && (((vVec) = Vec_VecEntryInt(vGlob, i)), 1); i++ )
75
#define Vec_VecForEachLevelIntStop( vGlob, vVec, i, LevelStop )                               \
76
    for ( i = 0; (i < LevelStop) && (((vVec) = Vec_VecEntryInt(vGlob, i)), 1); i++ )
77
#define Vec_VecForEachLevelIntStartStop( vGlob, vVec, i, LevelStart, LevelStop )              \
78
    for ( i = LevelStart; (i < LevelStop) && (((vVec) = Vec_VecEntryInt(vGlob, i)), 1); i++ )
79
#define Vec_VecForEachLevelIntReverse( vGlob, vVec, i )                                       \
80
    for ( i = Vec_VecSize(vGlob)-1; (i >= 0) && (((vVec) = Vec_VecEntryInt(vGlob, i)), 1); i-- )
81
#define Vec_VecForEachLevelIntReverseStartStop( vGlob, vVec, i, LevelStart, LevelStop )       \
82
    for ( i = LevelStart-1; (i >= LevelStop) && (((vVec) = Vec_VecEntryInt(vGlob, i)), 1); i-- )
83
#define Vec_VecForEachLevelIntTwo( vGlob1, vGlob2, vVec1, vVec2, i )                          \
84
    for ( i = 0; (i < Vec_VecSize(vGlob1)) && (((vVec1) = Vec_VecEntryInt(vGlob1, i)), 1) && (((vVec2) = Vec_VecEntryInt(vGlob2, i)), 1); i++ )
Alan Mishchenko committed
85 86

// iteratores through entries
Alan Mishchenko committed
87
#define Vec_VecForEachEntry( Type, vGlob, pEntry, i, k )                                      \
Alan Mishchenko committed
88
    for ( i = 0; i < Vec_VecSize(vGlob); i++ )                                                \
89
        Vec_PtrForEachEntry( Type, Vec_VecEntry(vGlob, i), pEntry, k ) 
Alan Mishchenko committed
90
#define Vec_VecForEachEntryLevel( Type, vGlob, pEntry, i, Level )                             \
91
        Vec_PtrForEachEntry( Type, Vec_VecEntry(vGlob, Level), pEntry, i ) 
Alan Mishchenko committed
92
#define Vec_VecForEachEntryStart( Type, vGlob, pEntry, i, k, LevelStart )                     \
Alan Mishchenko committed
93
    for ( i = LevelStart; i < Vec_VecSize(vGlob); i++ )                                       \
94
        Vec_PtrForEachEntry( Type, Vec_VecEntry(vGlob, i), pEntry, k ) 
Alan Mishchenko committed
95
#define Vec_VecForEachEntryStartStop( Type, vGlob, pEntry, i, k, LevelStart, LevelStop )      \
96
    for ( i = LevelStart; i < LevelStop; i++ )                                                \
97
        Vec_PtrForEachEntry( Type, Vec_VecEntry(vGlob, i), pEntry, k ) 
Alan Mishchenko committed
98
#define Vec_VecForEachEntryReverse( Type, vGlob, pEntry, i, k )                               \
Alan Mishchenko committed
99
    for ( i = 0; i < Vec_VecSize(vGlob); i++ )                                                \
100
        Vec_PtrForEachEntryReverse( Type, Vec_VecEntry(vGlob, i), pEntry, k ) 
Alan Mishchenko committed
101
#define Vec_VecForEachEntryReverseReverse( Type, vGlob, pEntry, i, k )                        \
Alan Mishchenko committed
102
    for ( i = Vec_VecSize(vGlob) - 1; i >= 0; i-- )                                           \
103
        Vec_PtrForEachEntryReverse( Type, Vec_VecEntry(vGlob, i), pEntry, k ) 
Alan Mishchenko committed
104
#define Vec_VecForEachEntryReverseStart( Type, vGlob, pEntry, i, k, LevelStart )              \
105
    for ( i = LevelStart-1; i >= 0; i-- )                                                     \
106
        Vec_PtrForEachEntry( Type, Vec_VecEntry(vGlob, i), pEntry, k ) 
Alan Mishchenko committed
107

108
// iteratores through entries
109
#define Vec_VecForEachEntryInt( vGlob, Entry, i, k )                                          \
110
    for ( i = 0; i < Vec_VecSize(vGlob); i++ )                                                \
111
        Vec_IntForEachEntry( Vec_VecEntryInt(vGlob, i), Entry, k ) 
112
#define Vec_VecForEachEntryIntLevel( vGlob, Entry, i, Level )                                 \
113
        Vec_IntForEachEntry( Vec_VecEntryInt(vGlob, Level), Entry, i ) 
114
#define Vec_VecForEachEntryIntStart( vGlob, Entry, i, k, LevelStart )                         \
115
    for ( i = LevelStart; i < Vec_VecSize(vGlob); i++ )                                       \
116
        Vec_IntForEachEntry( Vec_VecEntryInt(vGlob, i), Entry, k ) 
117
#define Vec_VecForEachEntryIntStartStop( vGlob, Entry, i, k, LevelStart, LevelStop )          \
118
    for ( i = LevelStart; i < LevelStop; i++ )                                                \
119
        Vec_IntForEachEntry( Vec_VecEntryInt(vGlob, i), Entry, k ) 
120
#define Vec_VecForEachEntryIntReverse( vGlob, Entry, i, k )                                   \
121
    for ( i = 0; i < Vec_VecSize(vGlob); i++ )                                                \
122
        Vec_IntForEachEntryReverse( Vec_VecEntryInt(vGlob, i), Entry, k ) 
123
#define Vec_VecForEachEntryIntReverseReverse( vGlob, Entry, i, k )                            \
124
    for ( i = Vec_VecSize(vGlob) - 1; i >= 0; i-- )                                           \
125
        Vec_IntForEachEntryReverse( Vec_VecEntryInt(vGlob, i), Entry, k ) 
126
#define Vec_VecForEachEntryIntReverseStart( vGlob, Entry, i, k, LevelStart )                  \
127
    for ( i = LevelStart-1; i >= 0; i-- )                                                     \
128
        Vec_IntForEachEntry( Vec_VecEntryInt(vGlob, i), Entry, k ) 
129

Alan Mishchenko committed
130
////////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
131
///                     FUNCTION DEFINITIONS                         ///
Alan Mishchenko committed
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
////////////////////////////////////////////////////////////////////////

/**Function*************************************************************

  Synopsis    [Allocates a vector with the given capacity.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline Vec_Vec_t * Vec_VecAlloc( int nCap )
{
    Vec_Vec_t * p;
Alan Mishchenko committed
148
    p = ABC_ALLOC( Vec_Vec_t, 1 );
Alan Mishchenko committed
149 150 151 152
    if ( nCap > 0 && nCap < 8 )
        nCap = 8;
    p->nSize  = 0;
    p->nCap   = nCap;
Alan Mishchenko committed
153
    p->pArray = p->nCap? ABC_ALLOC( void *, p->nCap ) : NULL;
Alan Mishchenko committed
154 155 156 157 158
    return p;
}

/**Function*************************************************************

Alan Mishchenko committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
  Synopsis    [Allocates a vector with the given capacity.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline Vec_Vec_t * Vec_VecStart( int nSize )
{
    Vec_Vec_t * p;
    int i;
    p = Vec_VecAlloc( nSize );
    for ( i = 0; i < nSize; i++ )
        p->pArray[i] = Vec_PtrAlloc( 0 );
    p->nSize = nSize;
    return p;
}

/**Function*************************************************************

Alan Mishchenko committed
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
  Synopsis    [Allocates a vector with the given capacity.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline void Vec_VecExpand( Vec_Vec_t * p, int Level )
{
    int i;
    if ( p->nSize >= Level + 1 )
        return;
    Vec_PtrGrow( (Vec_Ptr_t *)p, Level + 1 );
    for ( i = p->nSize; i <= Level; i++ )
        p->pArray[i] = Vec_PtrAlloc( 0 );
    p->nSize = Level + 1;
}
200 201 202 203 204 205 206 207 208 209 210 211 212
static inline void Vec_VecExpandInt( Vec_Vec_t * p, int Level )
{
    int i;
    if ( p->nSize >= Level + 1 )
        return;
    Vec_IntGrow( (Vec_Int_t *)p, Level + 1 );
    for ( i = p->nSize; i <= Level; i++ )
        p->pArray[i] = Vec_PtrAlloc( 0 );
    p->nSize = Level + 1;
}

/**Function*************************************************************

Alan Mishchenko committed
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline int Vec_VecSize( Vec_Vec_t * p )
{
    return p->nSize;
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
static inline int Vec_VecCap( Vec_Vec_t * p )
{
    return p->nCap;
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
254 255
static inline int Vec_VecLevelSize( Vec_Vec_t * p, int i )
{
Alan Mishchenko committed
256
    assert( i >= 0 && i < p->nSize );
257 258 259 260 261 262 263 264 265 266 267 268 269 270
    return Vec_PtrSize( (Vec_Ptr_t *)p->pArray[i] );
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
271
static inline Vec_Ptr_t * Vec_VecEntry( Vec_Vec_t * p, int i )
Alan Mishchenko committed
272 273
{
    assert( i >= 0 && i < p->nSize );
274
    return (Vec_Ptr_t *)p->pArray[i];
Alan Mishchenko committed
275
}
276 277 278
static inline Vec_Int_t * Vec_VecEntryInt( Vec_Vec_t * p, int i )
{
    assert( i >= 0 && i < p->nSize );
279
    return (Vec_Int_t *)p->pArray[i];
280 281 282 283 284 285 286 287 288 289 290 291 292
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
293
static inline double Vec_VecMemory( Vec_Vec_t * p )
294
{
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
    int i;
    double Mem;
    if ( p == NULL )  return 0.0;
    Mem = Vec_PtrMemory( (Vec_Ptr_t *)p );
    for ( i = 0; i < p->nSize; i++ )
        if ( Vec_VecEntry(p, i) )
            Mem += Vec_PtrMemory( Vec_VecEntry(p, i) );
    return Mem;
}
static inline double Vec_VecMemoryInt( Vec_Vec_t * p )
{
    int i;
    double Mem;
    if ( p == NULL )  return 0.0;
    Mem = Vec_PtrMemory( (Vec_Ptr_t *)p );
    for ( i = 0; i < p->nSize; i++ )
        if ( Vec_VecEntry(p, i) )
            Mem += Vec_IntMemory( Vec_VecEntryInt(p, i) );
    return Mem;
314 315 316 317 318 319 320 321 322 323 324 325 326
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
327 328 329 330
static inline void * Vec_VecEntryEntry( Vec_Vec_t * p, int i, int k )
{
    return Vec_PtrEntry( Vec_VecEntry(p, i), k );
}
331 332 333 334 335 336 337
static inline int Vec_VecEntryEntryInt( Vec_Vec_t * p, int i, int k )
{
    return Vec_IntEntry( Vec_VecEntryInt(p, i), k );
}

/**Function*************************************************************

Alan Mishchenko committed
338 339 340 341 342 343 344 345 346 347 348 349 350 351
  Synopsis    [Frees the vector.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline void Vec_VecFree( Vec_Vec_t * p )
{
    Vec_Ptr_t * vVec;
    int i;
    Vec_VecForEachLevel( p, vVec, i )
352
        if ( vVec ) Vec_PtrFree( vVec );
Alan Mishchenko committed
353 354
    Vec_PtrFree( (Vec_Ptr_t *)p );
}
355 356 357 358 359 360 361 362
static inline void Vec_VecErase( Vec_Vec_t * p )
{
    Vec_Ptr_t * vVec;
    int i;
    Vec_VecForEachLevel( p, vVec, i )
        if ( vVec ) Vec_PtrFree( vVec );
    Vec_PtrErase( (Vec_Ptr_t *)p );
}
Alan Mishchenko committed
363 364 365

/**Function*************************************************************

366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline void Vec_VecFreeP( Vec_Vec_t ** p )
{
    if ( *p == NULL )
        return;
    Vec_VecFree( *p );
    *p = NULL;
}

/**Function*************************************************************

Alan Mishchenko committed
385 386 387 388 389 390 391 392 393
  Synopsis    [Frees the vector.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
394
static inline Vec_Vec_t * Vec_VecDup( Vec_Vec_t * p )
Alan Mishchenko committed
395 396 397 398 399 400 401 402 403 404
{
    Vec_Ptr_t * vNew, * vVec;
    int i;
    vNew = Vec_PtrAlloc( Vec_VecSize(p) );
    Vec_VecForEachLevel( p, vVec, i )
        Vec_PtrPush( vNew, Vec_PtrDup(vVec) );
    return (Vec_Vec_t *)vNew;
}
static inline Vec_Vec_t * Vec_VecDupInt( Vec_Vec_t * p )
{
405 406
    Vec_Ptr_t * vNew;
    Vec_Int_t * vVec;
Alan Mishchenko committed
407 408
    int i;
    vNew = Vec_PtrAlloc( Vec_VecSize(p) );
409 410
    Vec_VecForEachLevelInt( p, vVec, i )
        Vec_PtrPush( vNew, Vec_IntDup(vVec) );
Alan Mishchenko committed
411 412 413 414 415
    return (Vec_Vec_t *)vNew;
}

/**Function*************************************************************

Alan Mishchenko committed
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473
  Synopsis    [Frees the vector of vectors.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline int Vec_VecSizeSize( Vec_Vec_t * p )
{
    Vec_Ptr_t * vVec;
    int i, Counter = 0;
    Vec_VecForEachLevel( p, vVec, i )
        Counter += vVec->nSize;
    return Counter;
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline void Vec_VecClear( Vec_Vec_t * p )
{
    Vec_Ptr_t * vVec;
    int i;
    Vec_VecForEachLevel( p, vVec, i )
        Vec_PtrClear( vVec );
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline void Vec_VecPush( Vec_Vec_t * p, int Level, void * Entry )
{
    if ( p->nSize < Level + 1 )
    {
        int i;
        Vec_PtrGrow( (Vec_Ptr_t *)p, Level + 1 );
        for ( i = p->nSize; i < Level + 1; i++ )
            p->pArray[i] = Vec_PtrAlloc( 0 );
        p->nSize = Level + 1;
    }
474
    Vec_PtrPush( Vec_VecEntry(p, Level), Entry );
Alan Mishchenko committed
475
}
476 477 478 479 480 481 482
static inline void Vec_VecPushInt( Vec_Vec_t * p, int Level, int Entry )
{
    if ( p->nSize < Level + 1 )
    {
        int i;
        Vec_PtrGrow( (Vec_Ptr_t *)p, Level + 1 );
        for ( i = p->nSize; i < Level + 1; i++ )
483
            p->pArray[i] = Vec_IntAlloc( 0 );
484 485
        p->nSize = Level + 1;
    }
486
    Vec_IntPush( Vec_VecEntryInt(p, Level), Entry );
487 488 489 490 491 492 493 494 495 496 497 498 499
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
500 501 502 503 504
static inline void Vec_VecPushUnique( Vec_Vec_t * p, int Level, void * Entry )
{
    if ( p->nSize < Level + 1 )
        Vec_VecPush( p, Level, Entry );
    else
505
        Vec_PtrPushUnique( Vec_VecEntry(p, Level), Entry );
Alan Mishchenko committed
506
}
507 508 509 510 511
static inline void Vec_VecPushUniqueInt( Vec_Vec_t * p, int Level, int Entry )
{
    if ( p->nSize < Level + 1 )
        Vec_VecPushInt( p, Level, Entry );
    else
512
        Vec_IntPushUnique( Vec_VecEntryInt(p, Level), Entry );
513 514 515 516
}

/**Function*************************************************************

Alan Mishchenko committed
517 518 519 520 521 522 523 524 525
  Synopsis    [Comparison procedure for two arrays.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
526
static int Vec_VecSortCompare1( Vec_Ptr_t ** pp1, Vec_Ptr_t ** pp2 )
Alan Mishchenko committed
527 528 529 530 531 532 533
{
    if ( Vec_PtrSize(*pp1) < Vec_PtrSize(*pp2) )
        return -1;
    if ( Vec_PtrSize(*pp1) > Vec_PtrSize(*pp2) ) 
        return 1;
    return 0; 
}
Alan Mishchenko committed
534
static int Vec_VecSortCompare2( Vec_Ptr_t ** pp1, Vec_Ptr_t ** pp2 )
Alan Mishchenko committed
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
{
    if ( Vec_PtrSize(*pp1) > Vec_PtrSize(*pp2) )
        return -1;
    if ( Vec_PtrSize(*pp1) < Vec_PtrSize(*pp2) ) 
        return 1;
    return 0; 
}

/**Function*************************************************************

  Synopsis    [Sorting the entries by their integer value.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline void Vec_VecSort( Vec_Vec_t * p, int fReverse )
{
    if ( fReverse ) 
557
        qsort( (void *)p->pArray, (size_t)p->nSize, sizeof(void *), 
Alan Mishchenko committed
558 559
                (int (*)(const void *, const void *)) Vec_VecSortCompare2 );
    else
560
        qsort( (void *)p->pArray, (size_t)p->nSize, sizeof(void *), 
Alan Mishchenko committed
561
                (int (*)(const void *, const void *)) Vec_VecSortCompare1 );
Alan Mishchenko committed
562 563
}

564 565
/**Function*************************************************************

566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
  Synopsis    [Comparison procedure for two integers.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
static int Vec_VecSortCompare3( Vec_Int_t ** pp1, Vec_Int_t ** pp2 )
{
    if ( Vec_IntEntry(*pp1,0) < Vec_IntEntry(*pp2,0) )
        return -1;
    if ( Vec_IntEntry(*pp1,0) > Vec_IntEntry(*pp2,0) ) 
        return 1;
    return 0; 
}
static int Vec_VecSortCompare4( Vec_Int_t ** pp1, Vec_Int_t ** pp2 )
{
    if ( Vec_IntEntry(*pp1,0) > Vec_IntEntry(*pp2,0) )
        return -1;
    if ( Vec_IntEntry(*pp1,0) < Vec_IntEntry(*pp2,0) ) 
        return 1;
    return 0; 
}

/**Function*************************************************************

  Synopsis    [Sorting the entries by their integer value.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline void Vec_VecSortByFirstInt( Vec_Vec_t * p, int fReverse )
{
    if ( fReverse ) 
606
        qsort( (void *)p->pArray, (size_t)p->nSize, sizeof(void *), 
607 608
                (int (*)(const void *, const void *)) Vec_VecSortCompare4 );
    else
609
        qsort( (void *)p->pArray, (size_t)p->nSize, sizeof(void *), 
610 611 612 613 614
                (int (*)(const void *, const void *)) Vec_VecSortCompare3 );
}

/**Function*************************************************************

615 616 617 618 619 620 621 622 623
  Synopsis    []

  Description []
  
  SideEffects []

  SeeAlso     []

***********************************************************************/
624
static inline void Vec_VecPrintInt( Vec_Vec_t * p, int fSkipSingles )
625 626 627 628
{
    int i, k, Entry;
    Vec_VecForEachEntryInt( p, Entry, i, k )
    {
Alan Mishchenko committed
629
        if ( fSkipSingles && Vec_VecLevelSize(p, i) == 1 )
630
            break;
631
        if ( k == 0 )
632 633 634 635
            printf( " %4d : {", i );
        printf( " %d", Entry );
        if ( k == Vec_VecLevelSize(p, i) - 1 )
            printf( " }\n" );
636 637
    }
}
638 639 640

ABC_NAMESPACE_HEADER_END

Alan Mishchenko committed
641 642
#endif

Alan Mishchenko committed
643 644 645 646
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////