2005-07-29 17:01:00 +02:00
|
|
|
/**CFile****************************************************************
|
|
|
|
|
|
|
|
|
|
FileName [vecInt.h]
|
|
|
|
|
|
|
|
|
|
SystemName [ABC: Logic synthesis and verification system.]
|
|
|
|
|
|
|
|
|
|
PackageName [Resizable arrays.]
|
|
|
|
|
|
|
|
|
|
Synopsis [Resizable arrays of integers.]
|
|
|
|
|
|
|
|
|
|
Author [Alan Mishchenko]
|
|
|
|
|
|
|
|
|
|
Affiliation [UC Berkeley]
|
|
|
|
|
|
|
|
|
|
Date [Ver. 1.0. Started - June 20, 2005.]
|
|
|
|
|
|
|
|
|
|
Revision [$Id: vecInt.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
2012-01-21 13:30:10 +01:00
|
|
|
#ifndef ABC__misc__vec__vecInt_h
|
|
|
|
|
#define ABC__misc__vec__vecInt_h
|
2005-07-29 17:01:00 +02:00
|
|
|
|
2010-11-01 09:35:04 +01:00
|
|
|
|
2005-07-29 17:01:00 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
/// INCLUDES ///
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2007-01-10 17:01:00 +01:00
|
|
|
#include <stdio.h>
|
2005-07-29 17:01:00 +02:00
|
|
|
|
2010-11-01 09:35:04 +01:00
|
|
|
ABC_NAMESPACE_HEADER_START
|
|
|
|
|
|
|
|
|
|
|
2005-07-29 17:01:00 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
/// PARAMETERS ///
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
/// BASIC TYPES ///
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
typedef struct Vec_Int_t_ Vec_Int_t;
|
|
|
|
|
struct Vec_Int_t_
|
|
|
|
|
{
|
|
|
|
|
int nCap;
|
2005-08-27 17:01:00 +02:00
|
|
|
int nSize;
|
2005-07-29 17:01:00 +02:00
|
|
|
int * pArray;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2008-01-31 05:01:00 +01:00
|
|
|
/// MACRO DEFINITIONS ///
|
2005-07-29 17:01:00 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2005-08-07 17:01:00 +02:00
|
|
|
#define Vec_IntForEachEntry( vVec, Entry, i ) \
|
|
|
|
|
for ( i = 0; (i < Vec_IntSize(vVec)) && (((Entry) = Vec_IntEntry(vVec, i)), 1); i++ )
|
2005-08-22 17:01:00 +02:00
|
|
|
#define Vec_IntForEachEntryStart( vVec, Entry, i, Start ) \
|
|
|
|
|
for ( i = Start; (i < Vec_IntSize(vVec)) && (((Entry) = Vec_IntEntry(vVec, i)), 1); i++ )
|
2012-03-21 23:27:47 +01:00
|
|
|
#define Vec_IntForEachEntryStop( vVec, Entry, i, Stop ) \
|
2009-02-15 17:01:00 +01:00
|
|
|
for ( i = 0; (i < Stop) && (((Entry) = Vec_IntEntry(vVec, i)), 1); i++ )
|
2008-01-31 05:01:00 +01:00
|
|
|
#define Vec_IntForEachEntryStartStop( vVec, Entry, i, Start, Stop ) \
|
|
|
|
|
for ( i = Start; (i < Stop) && (((Entry) = Vec_IntEntry(vVec, i)), 1); i++ )
|
|
|
|
|
#define Vec_IntForEachEntryReverse( vVec, pEntry, i ) \
|
|
|
|
|
for ( i = Vec_IntSize(vVec) - 1; (i >= 0) && (((pEntry) = Vec_IntEntry(vVec, i)), 1); i-- )
|
2012-03-21 23:27:47 +01:00
|
|
|
#define Vec_IntForEachEntryTwo( vVec1, vVec2, Entry1, Entry2, i ) \
|
2011-04-10 21:55:57 +02:00
|
|
|
for ( i = 0; (i < Vec_IntSize(vVec1)) && (((Entry1) = Vec_IntEntry(vVec1, i)), 1) && (((Entry2) = Vec_IntEntry(vVec2, i)), 1); i++ )
|
2012-03-21 23:27:47 +01:00
|
|
|
#define Vec_IntForEachEntryDouble( vVec, Entry1, Entry2, i ) \
|
2011-10-27 19:10:10 +02:00
|
|
|
for ( i = 0; (i+1 < Vec_IntSize(vVec)) && (((Entry1) = Vec_IntEntry(vVec, i)), 1) && (((Entry2) = Vec_IntEntry(vVec, i+1)), 1); i += 2 )
|
2012-03-21 23:27:47 +01:00
|
|
|
#define Vec_IntForEachEntryThisNext( vVec, This, Next, i ) \
|
|
|
|
|
for ( i = 0, (This) = (Next) = (Vec_IntSize(vVec) ? Vec_IntEntry(vVec, 0) : -1); (i+1 < Vec_IntSize(vVec)) && (((Next) = Vec_IntEntry(vVec, i+1)), 1); i += 2, (This) = (Next) )
|
2005-08-07 17:01:00 +02:00
|
|
|
|
2005-07-29 17:01:00 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
2008-01-31 05:01:00 +01:00
|
|
|
/// FUNCTION DEFINITIONS ///
|
2005-07-29 17:01:00 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Allocates a vector with the given capacity.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline Vec_Int_t * Vec_IntAlloc( int nCap )
|
|
|
|
|
{
|
|
|
|
|
Vec_Int_t * p;
|
2009-02-15 17:01:00 +01:00
|
|
|
p = ABC_ALLOC( Vec_Int_t, 1 );
|
2005-07-29 17:01:00 +02:00
|
|
|
if ( nCap > 0 && nCap < 16 )
|
|
|
|
|
nCap = 16;
|
|
|
|
|
p->nSize = 0;
|
|
|
|
|
p->nCap = nCap;
|
2009-02-15 17:01:00 +01:00
|
|
|
p->pArray = p->nCap? ABC_ALLOC( int, p->nCap ) : NULL;
|
2005-07-29 17:01:00 +02:00
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
2005-09-04 17:01:00 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Allocates a vector with the given size and cleans it.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline Vec_Int_t * Vec_IntStart( int nSize )
|
|
|
|
|
{
|
|
|
|
|
Vec_Int_t * p;
|
|
|
|
|
p = Vec_IntAlloc( nSize );
|
|
|
|
|
p->nSize = nSize;
|
|
|
|
|
memset( p->pArray, 0, sizeof(int) * nSize );
|
|
|
|
|
return p;
|
|
|
|
|
}
|
2010-11-01 09:35:04 +01:00
|
|
|
static inline Vec_Int_t * Vec_IntStartFull( int nSize )
|
|
|
|
|
{
|
|
|
|
|
Vec_Int_t * p;
|
|
|
|
|
p = Vec_IntAlloc( nSize );
|
|
|
|
|
p->nSize = nSize;
|
|
|
|
|
memset( p->pArray, 0xff, sizeof(int) * nSize );
|
|
|
|
|
return p;
|
|
|
|
|
}
|
2013-03-09 21:19:11 +01:00
|
|
|
static inline Vec_Int_t * Vec_IntStartRange( int First, int Range )
|
|
|
|
|
{
|
|
|
|
|
Vec_Int_t * p;
|
|
|
|
|
int i;
|
|
|
|
|
p = Vec_IntAlloc( Range );
|
|
|
|
|
p->nSize = Range;
|
|
|
|
|
for ( i = 0; i < Range; i++ )
|
|
|
|
|
p->pArray[i] = First + i;
|
|
|
|
|
return p;
|
|
|
|
|
}
|
2010-11-01 09:35:04 +01:00
|
|
|
|
2008-01-31 05:01:00 +01:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Allocates a vector with the given size and cleans it.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline Vec_Int_t * Vec_IntStartNatural( int nSize )
|
|
|
|
|
{
|
|
|
|
|
Vec_Int_t * p;
|
|
|
|
|
int i;
|
|
|
|
|
p = Vec_IntAlloc( nSize );
|
|
|
|
|
p->nSize = nSize;
|
|
|
|
|
for ( i = 0; i < nSize; i++ )
|
|
|
|
|
p->pArray[i] = i;
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-29 17:01:00 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Creates the vector from an integer array of the given size.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline Vec_Int_t * Vec_IntAllocArray( int * pArray, int nSize )
|
|
|
|
|
{
|
|
|
|
|
Vec_Int_t * p;
|
2009-02-15 17:01:00 +01:00
|
|
|
p = ABC_ALLOC( Vec_Int_t, 1 );
|
2005-07-29 17:01:00 +02:00
|
|
|
p->nSize = nSize;
|
|
|
|
|
p->nCap = nSize;
|
|
|
|
|
p->pArray = pArray;
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Creates the vector from an integer array of the given size.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline Vec_Int_t * Vec_IntAllocArrayCopy( int * pArray, int nSize )
|
|
|
|
|
{
|
|
|
|
|
Vec_Int_t * p;
|
2009-02-15 17:01:00 +01:00
|
|
|
p = ABC_ALLOC( Vec_Int_t, 1 );
|
2005-07-29 17:01:00 +02:00
|
|
|
p->nSize = nSize;
|
|
|
|
|
p->nCap = nSize;
|
2009-02-15 17:01:00 +01:00
|
|
|
p->pArray = ABC_ALLOC( int, nSize );
|
2005-07-29 17:01:00 +02:00
|
|
|
memcpy( p->pArray, pArray, sizeof(int) * nSize );
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Duplicates the integer array.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline Vec_Int_t * Vec_IntDup( Vec_Int_t * pVec )
|
|
|
|
|
{
|
|
|
|
|
Vec_Int_t * p;
|
2009-02-15 17:01:00 +01:00
|
|
|
p = ABC_ALLOC( Vec_Int_t, 1 );
|
2005-07-29 17:01:00 +02:00
|
|
|
p->nSize = pVec->nSize;
|
2008-01-31 05:01:00 +01:00
|
|
|
p->nCap = pVec->nSize;
|
2009-02-15 17:01:00 +01:00
|
|
|
p->pArray = p->nCap? ABC_ALLOC( int, p->nCap ) : NULL;
|
2005-07-29 17:01:00 +02:00
|
|
|
memcpy( p->pArray, pVec->pArray, sizeof(int) * pVec->nSize );
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Transfers the array into another vector.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline Vec_Int_t * Vec_IntDupArray( Vec_Int_t * pVec )
|
|
|
|
|
{
|
|
|
|
|
Vec_Int_t * p;
|
2009-02-15 17:01:00 +01:00
|
|
|
p = ABC_ALLOC( Vec_Int_t, 1 );
|
2005-07-29 17:01:00 +02:00
|
|
|
p->nSize = pVec->nSize;
|
|
|
|
|
p->nCap = pVec->nCap;
|
|
|
|
|
p->pArray = pVec->pArray;
|
|
|
|
|
pVec->nSize = 0;
|
|
|
|
|
pVec->nCap = 0;
|
|
|
|
|
pVec->pArray = NULL;
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-01 01:33:22 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
2013-05-13 04:09:28 +02:00
|
|
|
static inline void Vec_IntZero( Vec_Int_t * p )
|
|
|
|
|
{
|
|
|
|
|
p->pArray = NULL;
|
|
|
|
|
p->nSize = 0;
|
|
|
|
|
p->nCap = 0;
|
|
|
|
|
}
|
2012-04-01 01:33:22 +02:00
|
|
|
static inline void Vec_IntErase( Vec_Int_t * p )
|
|
|
|
|
{
|
2012-04-20 19:12:29 +02:00
|
|
|
ABC_FREE( p->pArray );
|
2012-04-01 01:33:22 +02:00
|
|
|
p->nSize = 0;
|
|
|
|
|
p->nCap = 0;
|
|
|
|
|
}
|
2005-07-29 17:01:00 +02:00
|
|
|
static inline void Vec_IntFree( Vec_Int_t * p )
|
|
|
|
|
{
|
2009-02-15 17:01:00 +01:00
|
|
|
ABC_FREE( p->pArray );
|
|
|
|
|
ABC_FREE( p );
|
2005-07-29 17:01:00 +02:00
|
|
|
}
|
|
|
|
|
|
2010-11-01 09:35:04 +01:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline void Vec_IntFreeP( Vec_Int_t ** p )
|
|
|
|
|
{
|
|
|
|
|
if ( *p == NULL )
|
|
|
|
|
return;
|
|
|
|
|
ABC_FREE( (*p)->pArray );
|
|
|
|
|
ABC_FREE( (*p) );
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-29 17:01:00 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int * Vec_IntReleaseArray( Vec_Int_t * p )
|
|
|
|
|
{
|
|
|
|
|
int * pArray = p->pArray;
|
|
|
|
|
p->nCap = 0;
|
|
|
|
|
p->nSize = 0;
|
|
|
|
|
p->pArray = NULL;
|
|
|
|
|
return pArray;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int * Vec_IntArray( Vec_Int_t * p )
|
|
|
|
|
{
|
|
|
|
|
return p->pArray;
|
|
|
|
|
}
|
2013-05-05 18:04:14 +02:00
|
|
|
static inline int ** Vec_IntArrayP( Vec_Int_t * p )
|
|
|
|
|
{
|
|
|
|
|
return &p->pArray;
|
|
|
|
|
}
|
2005-07-29 17:01:00 +02:00
|
|
|
|
2011-12-01 07:14:32 +01:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int * Vec_IntLimit( Vec_Int_t * p )
|
|
|
|
|
{
|
|
|
|
|
return p->pArray + p->nSize;
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-29 17:01:00 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int Vec_IntSize( Vec_Int_t * p )
|
|
|
|
|
{
|
|
|
|
|
return p->nSize;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-15 07:15:49 +01:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int Vec_IntCap( Vec_Int_t * p )
|
|
|
|
|
{
|
|
|
|
|
return p->nCap;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-29 21:34:32 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline double Vec_IntMemory( Vec_Int_t * p )
|
|
|
|
|
{
|
|
|
|
|
return !p ? 0.0 : 1.0 * sizeof(int) * p->nCap + sizeof(Vec_Int_t) ;
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-29 17:01:00 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int Vec_IntEntry( Vec_Int_t * p, int i )
|
|
|
|
|
{
|
|
|
|
|
assert( i >= 0 && i < p->nSize );
|
|
|
|
|
return p->pArray[i];
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-23 08:05:13 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int * Vec_IntEntryP( Vec_Int_t * p, int i )
|
|
|
|
|
{
|
|
|
|
|
assert( i >= 0 && i < p->nSize );
|
|
|
|
|
return p->pArray + i;
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-29 17:01:00 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline void Vec_IntWriteEntry( Vec_Int_t * p, int i, int Entry )
|
|
|
|
|
{
|
|
|
|
|
assert( i >= 0 && i < p->nSize );
|
|
|
|
|
p->pArray[i] = Entry;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-31 05:01:00 +01:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
2010-11-01 09:35:04 +01:00
|
|
|
static inline int Vec_IntAddToEntry( Vec_Int_t * p, int i, int Addition )
|
2008-01-31 05:01:00 +01:00
|
|
|
{
|
|
|
|
|
assert( i >= 0 && i < p->nSize );
|
2010-11-01 09:35:04 +01:00
|
|
|
return p->pArray[i] += Addition;
|
2008-01-31 05:01:00 +01:00
|
|
|
}
|
|
|
|
|
|
2013-09-30 20:43:17 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline void Vec_IntUpdateEntry( Vec_Int_t * p, int i, int Value )
|
|
|
|
|
{
|
|
|
|
|
if ( Vec_IntEntry( p, i ) < Value )
|
|
|
|
|
Vec_IntWriteEntry( p, i, Value );
|
2014-06-11 06:31:10 +02:00
|
|
|
}
|
|
|
|
|
static inline void Vec_IntDowndateEntry( Vec_Int_t * p, int i, int Value )
|
|
|
|
|
{
|
|
|
|
|
if ( Vec_IntEntry( p, i ) > Value )
|
|
|
|
|
Vec_IntWriteEntry( p, i, Value );
|
2013-09-30 20:43:17 +02:00
|
|
|
}
|
|
|
|
|
|
2005-07-29 17:01:00 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int Vec_IntEntryLast( Vec_Int_t * p )
|
|
|
|
|
{
|
2008-01-31 05:01:00 +01:00
|
|
|
assert( p->nSize > 0 );
|
2005-07-29 17:01:00 +02:00
|
|
|
return p->pArray[p->nSize-1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Resizes the vector to the given capacity.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline void Vec_IntGrow( Vec_Int_t * p, int nCapMin )
|
|
|
|
|
{
|
|
|
|
|
if ( p->nCap >= nCapMin )
|
|
|
|
|
return;
|
2009-02-15 17:01:00 +01:00
|
|
|
p->pArray = ABC_REALLOC( int, p->pArray, nCapMin );
|
2008-01-31 05:01:00 +01:00
|
|
|
assert( p->pArray );
|
2005-07-29 17:01:00 +02:00
|
|
|
p->nCap = nCapMin;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-15 07:15:49 +01:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Resizes the vector to the given capacity.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline void Vec_IntGrowResize( Vec_Int_t * p, int nCapMin )
|
|
|
|
|
{
|
|
|
|
|
p->nSize = nCapMin;
|
|
|
|
|
if ( p->nCap >= nCapMin )
|
|
|
|
|
return;
|
|
|
|
|
p->pArray = ABC_REALLOC( int, p->pArray, nCapMin );
|
|
|
|
|
assert( p->pArray );
|
|
|
|
|
p->nCap = nCapMin;
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-29 17:01:00 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Fills the vector with given number of entries.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
2008-10-13 17:01:00 +02:00
|
|
|
static inline void Vec_IntFill( Vec_Int_t * p, int nSize, int Fill )
|
2005-07-29 17:01:00 +02:00
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
Vec_IntGrow( p, nSize );
|
2005-08-27 17:01:00 +02:00
|
|
|
for ( i = 0; i < nSize; i++ )
|
2008-10-13 17:01:00 +02:00
|
|
|
p->pArray[i] = Fill;
|
2005-07-29 17:01:00 +02:00
|
|
|
p->nSize = nSize;
|
2005-08-27 17:01:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Fills the vector with given number of entries.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
2008-10-13 17:01:00 +02:00
|
|
|
static inline void Vec_IntFillExtra( Vec_Int_t * p, int nSize, int Fill )
|
2005-08-27 17:01:00 +02:00
|
|
|
{
|
|
|
|
|
int i;
|
2010-11-01 09:35:04 +01:00
|
|
|
if ( nSize <= p->nSize )
|
2005-08-27 17:01:00 +02:00
|
|
|
return;
|
2010-11-01 09:35:04 +01:00
|
|
|
if ( nSize > 2 * p->nCap )
|
|
|
|
|
Vec_IntGrow( p, nSize );
|
|
|
|
|
else if ( nSize > p->nCap )
|
|
|
|
|
Vec_IntGrow( p, 2 * p->nCap );
|
2005-08-27 17:01:00 +02:00
|
|
|
for ( i = p->nSize; i < nSize; i++ )
|
2008-10-13 17:01:00 +02:00
|
|
|
p->pArray[i] = Fill;
|
2005-08-27 17:01:00 +02:00
|
|
|
p->nSize = nSize;
|
2005-07-29 17:01:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
2008-10-13 17:01:00 +02:00
|
|
|
Synopsis [Returns the entry even if the place not exist.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int Vec_IntGetEntry( Vec_Int_t * p, int i )
|
|
|
|
|
{
|
|
|
|
|
Vec_IntFillExtra( p, i + 1, 0 );
|
|
|
|
|
return Vec_IntEntry( p, i );
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-01 09:35:04 +01:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Returns the entry even if the place not exist.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int * Vec_IntGetEntryP( Vec_Int_t * p, int i )
|
|
|
|
|
{
|
|
|
|
|
Vec_IntFillExtra( p, i + 1, 0 );
|
|
|
|
|
return Vec_IntEntryP( p, i );
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-13 17:01:00 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Inserts the entry even if the place does not exist.]
|
2005-07-29 17:01:00 +02:00
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
2008-09-22 17:01:00 +02:00
|
|
|
|
|
|
|
|
***********************************************************************/
|
2008-10-13 17:01:00 +02:00
|
|
|
static inline void Vec_IntSetEntry( Vec_Int_t * p, int i, int Entry )
|
2008-09-22 17:01:00 +02:00
|
|
|
{
|
2008-10-13 17:01:00 +02:00
|
|
|
Vec_IntFillExtra( p, i + 1, 0 );
|
2008-09-22 17:01:00 +02:00
|
|
|
Vec_IntWriteEntry( p, i, Entry );
|
|
|
|
|
}
|
2013-02-25 23:49:59 +01:00
|
|
|
static inline void Vec_IntSetEntryFull( Vec_Int_t * p, int i, int Entry )
|
|
|
|
|
{
|
|
|
|
|
Vec_IntFillExtra( p, i + 1, -1 );
|
|
|
|
|
Vec_IntWriteEntry( p, i, Entry );
|
|
|
|
|
}
|
2008-09-22 17:01:00 +02:00
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
2005-07-29 17:01:00 +02:00
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline void Vec_IntShrink( Vec_Int_t * p, int nSizeNew )
|
|
|
|
|
{
|
|
|
|
|
assert( p->nSize >= nSizeNew );
|
|
|
|
|
p->nSize = nSizeNew;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline void Vec_IntClear( Vec_Int_t * p )
|
|
|
|
|
{
|
|
|
|
|
p->nSize = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline void Vec_IntPush( Vec_Int_t * p, int Entry )
|
|
|
|
|
{
|
|
|
|
|
if ( p->nSize == p->nCap )
|
|
|
|
|
{
|
|
|
|
|
if ( p->nCap < 16 )
|
|
|
|
|
Vec_IntGrow( p, 16 );
|
|
|
|
|
else
|
|
|
|
|
Vec_IntGrow( p, 2 * p->nCap );
|
|
|
|
|
}
|
|
|
|
|
p->pArray[p->nSize++] = Entry;
|
|
|
|
|
}
|
2014-03-23 00:24:44 +01:00
|
|
|
static inline void Vec_IntPushArray( Vec_Int_t * p, int * pEntries, int nEntries )
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
for ( i = 0; i < nEntries; i++ )
|
|
|
|
|
Vec_IntPush( p, pEntries[i] );
|
|
|
|
|
}
|
2005-07-29 17:01:00 +02:00
|
|
|
|
2005-11-26 17:01:00 +01:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
2008-01-31 05:01:00 +01:00
|
|
|
***********************************************************************/
|
|
|
|
|
static inline void Vec_IntPushFirst( Vec_Int_t * p, int Entry )
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
if ( p->nSize == p->nCap )
|
|
|
|
|
{
|
|
|
|
|
if ( p->nCap < 16 )
|
|
|
|
|
Vec_IntGrow( p, 16 );
|
|
|
|
|
else
|
|
|
|
|
Vec_IntGrow( p, 2 * p->nCap );
|
|
|
|
|
}
|
|
|
|
|
p->nSize++;
|
|
|
|
|
for ( i = p->nSize - 1; i >= 1; i-- )
|
|
|
|
|
p->pArray[i] = p->pArray[i-1];
|
|
|
|
|
p->pArray[0] = Entry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Inserts the entry while preserving the increasing order.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
2005-07-29 17:01:00 +02:00
|
|
|
***********************************************************************/
|
|
|
|
|
static inline void Vec_IntPushOrder( Vec_Int_t * p, int Entry )
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
if ( p->nSize == p->nCap )
|
|
|
|
|
{
|
|
|
|
|
if ( p->nCap < 16 )
|
|
|
|
|
Vec_IntGrow( p, 16 );
|
|
|
|
|
else
|
|
|
|
|
Vec_IntGrow( p, 2 * p->nCap );
|
|
|
|
|
}
|
|
|
|
|
p->nSize++;
|
|
|
|
|
for ( i = p->nSize-2; i >= 0; i-- )
|
|
|
|
|
if ( p->pArray[i] > Entry )
|
|
|
|
|
p->pArray[i+1] = p->pArray[i];
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
p->pArray[i+1] = Entry;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-15 21:04:05 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Inserts the entry while preserving the increasing order.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline void Vec_IntPushOrderReverse( Vec_Int_t * p, int Entry )
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
if ( p->nSize == p->nCap )
|
|
|
|
|
{
|
|
|
|
|
if ( p->nCap < 16 )
|
|
|
|
|
Vec_IntGrow( p, 16 );
|
|
|
|
|
else
|
|
|
|
|
Vec_IntGrow( p, 2 * p->nCap );
|
|
|
|
|
}
|
|
|
|
|
p->nSize++;
|
|
|
|
|
for ( i = p->nSize-2; i >= 0; i-- )
|
|
|
|
|
if ( p->pArray[i] < Entry )
|
|
|
|
|
p->pArray[i+1] = p->pArray[i];
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
p->pArray[i+1] = Entry;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-31 05:01:00 +01:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Inserts the entry while preserving the increasing order.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int Vec_IntPushUniqueOrder( Vec_Int_t * p, int Entry )
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
for ( i = 0; i < p->nSize; i++ )
|
|
|
|
|
if ( p->pArray[i] == Entry )
|
|
|
|
|
return 1;
|
|
|
|
|
Vec_IntPushOrder( p, Entry );
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2005-09-04 17:01:00 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int Vec_IntPushUnique( Vec_Int_t * p, int Entry )
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
for ( i = 0; i < p->nSize; i++ )
|
|
|
|
|
if ( p->pArray[i] == Entry )
|
|
|
|
|
return 1;
|
|
|
|
|
Vec_IntPush( p, Entry );
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-31 05:01:00 +01:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Returns the pointer to the next nWords entries in the vector.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline unsigned * Vec_IntFetch( Vec_Int_t * p, int nWords )
|
|
|
|
|
{
|
|
|
|
|
if ( nWords == 0 )
|
|
|
|
|
return NULL;
|
|
|
|
|
assert( nWords > 0 );
|
|
|
|
|
p->nSize += nWords;
|
|
|
|
|
if ( p->nSize > p->nCap )
|
|
|
|
|
{
|
|
|
|
|
// Vec_IntGrow( p, 2 * p->nSize );
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
return ((unsigned *)p->pArray) + p->nSize - nWords;
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-29 17:01:00 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Returns the last entry and removes it from the list.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int Vec_IntPop( Vec_Int_t * p )
|
|
|
|
|
{
|
|
|
|
|
assert( p->nSize > 0 );
|
|
|
|
|
return p->pArray[--p->nSize];
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-31 05:01:00 +01:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Find entry.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int Vec_IntFind( Vec_Int_t * p, int Entry )
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
for ( i = 0; i < p->nSize; i++ )
|
|
|
|
|
if ( p->pArray[i] == Entry )
|
|
|
|
|
return i;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2005-08-09 17:01:00 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
2008-01-31 05:01:00 +01:00
|
|
|
static inline int Vec_IntRemove( Vec_Int_t * p, int Entry )
|
2005-08-09 17:01:00 +02:00
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
for ( i = 0; i < p->nSize; i++ )
|
|
|
|
|
if ( p->pArray[i] == Entry )
|
|
|
|
|
break;
|
2008-01-31 05:01:00 +01:00
|
|
|
if ( i == p->nSize )
|
|
|
|
|
return 0;
|
2005-08-09 17:01:00 +02:00
|
|
|
assert( i < p->nSize );
|
|
|
|
|
for ( i++; i < p->nSize; i++ )
|
|
|
|
|
p->pArray[i-1] = p->pArray[i];
|
|
|
|
|
p->nSize--;
|
2008-01-31 05:01:00 +01:00
|
|
|
return 1;
|
2005-08-09 17:01:00 +02:00
|
|
|
}
|
2013-05-05 10:54:11 +02:00
|
|
|
static inline int Vec_IntRemove1( Vec_Int_t * p, int Entry )
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
for ( i = 1; i < p->nSize; i++ )
|
|
|
|
|
if ( p->pArray[i] == Entry )
|
|
|
|
|
break;
|
|
|
|
|
if ( i >= p->nSize )
|
|
|
|
|
return 0;
|
|
|
|
|
assert( i < p->nSize );
|
|
|
|
|
for ( i++; i < p->nSize; i++ )
|
|
|
|
|
p->pArray[i-1] = p->pArray[i];
|
|
|
|
|
p->nSize--;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2005-08-09 17:01:00 +02:00
|
|
|
|
2013-04-28 10:25:29 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline void Vec_IntDrop( Vec_Int_t * p, int i )
|
|
|
|
|
{
|
|
|
|
|
int k;
|
|
|
|
|
assert( i >= 0 && i < Vec_IntSize(p) );
|
|
|
|
|
p->nSize--;
|
|
|
|
|
for ( k = i; k < p->nSize; k++ )
|
|
|
|
|
p->pArray[k] = p->pArray[k+1];
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-01 09:35:04 +01:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Interts entry at the index iHere. Shifts other entries.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline void Vec_IntInsert( Vec_Int_t * p, int iHere, int Entry )
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
assert( iHere >= 0 && iHere < p->nSize );
|
|
|
|
|
Vec_IntPush( p, 0 );
|
|
|
|
|
for ( i = p->nSize - 1; i > iHere; i-- )
|
|
|
|
|
p->pArray[i] = p->pArray[i-1];
|
|
|
|
|
p->pArray[i] = Entry;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-21 17:01:00 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Find entry.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int Vec_IntFindMax( Vec_Int_t * p )
|
|
|
|
|
{
|
|
|
|
|
int i, Best;
|
|
|
|
|
if ( p->nSize == 0 )
|
|
|
|
|
return 0;
|
|
|
|
|
Best = p->pArray[0];
|
|
|
|
|
for ( i = 1; i < p->nSize; i++ )
|
|
|
|
|
if ( Best < p->pArray[i] )
|
|
|
|
|
Best = p->pArray[i];
|
|
|
|
|
return Best;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Find entry.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int Vec_IntFindMin( Vec_Int_t * p )
|
|
|
|
|
{
|
|
|
|
|
int i, Best;
|
|
|
|
|
if ( p->nSize == 0 )
|
|
|
|
|
return 0;
|
|
|
|
|
Best = p->pArray[0];
|
|
|
|
|
for ( i = 1; i < p->nSize; i++ )
|
|
|
|
|
if ( Best > p->pArray[i] )
|
|
|
|
|
Best = p->pArray[i];
|
|
|
|
|
return Best;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-10 16:01:00 +01:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Reverses the order of entries.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline void Vec_IntReverseOrder( Vec_Int_t * p )
|
|
|
|
|
{
|
|
|
|
|
int i, Temp;
|
|
|
|
|
for ( i = 0; i < p->nSize/2; i++ )
|
|
|
|
|
{
|
|
|
|
|
Temp = p->pArray[i];
|
|
|
|
|
p->pArray[i] = p->pArray[p->nSize-1-i];
|
|
|
|
|
p->pArray[p->nSize-1-i] = Temp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-23 08:05:13 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
2010-11-01 09:35:04 +01:00
|
|
|
static inline Vec_Int_t * Vec_IntInvert( Vec_Int_t * p, int Fill )
|
2015-06-23 08:05:13 +02:00
|
|
|
{
|
|
|
|
|
int Entry, i;
|
2010-11-01 09:35:04 +01:00
|
|
|
Vec_Int_t * vRes = Vec_IntAlloc( 0 );
|
2012-01-31 08:11:38 +01:00
|
|
|
if ( Vec_IntSize(p) == 0 )
|
|
|
|
|
return vRes;
|
2010-11-01 09:35:04 +01:00
|
|
|
Vec_IntFill( vRes, Vec_IntFindMax(p) + 1, Fill );
|
2015-06-23 08:05:13 +02:00
|
|
|
Vec_IntForEachEntry( p, Entry, i )
|
2010-11-01 09:35:04 +01:00
|
|
|
if ( Entry != Fill )
|
|
|
|
|
Vec_IntWriteEntry( vRes, Entry, i );
|
2015-06-23 08:05:13 +02:00
|
|
|
return vRes;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-29 05:21:01 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline Vec_Int_t * Vec_IntCondense( Vec_Int_t * p, int Fill )
|
|
|
|
|
{
|
|
|
|
|
int Entry, i;
|
|
|
|
|
Vec_Int_t * vRes = Vec_IntAlloc( Vec_IntSize(p) );
|
|
|
|
|
Vec_IntForEachEntry( p, Entry, i )
|
|
|
|
|
if ( Entry != Fill )
|
|
|
|
|
Vec_IntPush( vRes, Entry );
|
|
|
|
|
return vRes;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-01 09:35:04 +01:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int Vec_IntSum( Vec_Int_t * p )
|
|
|
|
|
{
|
|
|
|
|
int i, Counter = 0;
|
|
|
|
|
for ( i = 0; i < p->nSize; i++ )
|
|
|
|
|
Counter += p->pArray[i];
|
|
|
|
|
return Counter;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-31 15:20:10 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
2011-09-22 18:37:44 +02:00
|
|
|
static inline int Vec_IntCountEntry( Vec_Int_t * p, int Entry )
|
2011-07-31 15:20:10 +02:00
|
|
|
{
|
|
|
|
|
int i, Counter = 0;
|
|
|
|
|
for ( i = 0; i < p->nSize; i++ )
|
2011-09-22 18:37:44 +02:00
|
|
|
Counter += (p->pArray[i] == Entry);
|
2011-07-31 15:20:10 +02:00
|
|
|
return Counter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int Vec_IntCountPositive( Vec_Int_t * p )
|
|
|
|
|
{
|
|
|
|
|
int i, Counter = 0;
|
|
|
|
|
for ( i = 0; i < p->nSize; i++ )
|
|
|
|
|
Counter += (p->pArray[i] > 0);
|
|
|
|
|
return Counter;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-30 20:05:54 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Checks if two vectors are equal.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int Vec_IntEqual( Vec_Int_t * p1, Vec_Int_t * p2 )
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
if ( p1->nSize != p2->nSize )
|
|
|
|
|
return 0;
|
|
|
|
|
for ( i = 0; i < p1->nSize; i++ )
|
|
|
|
|
if ( p1->pArray[i] != p2->pArray[i] )
|
|
|
|
|
return 0;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-01 09:35:04 +01:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Counts the number of common entries.]
|
|
|
|
|
|
|
|
|
|
Description [Assumes that the entries are non-negative integers that
|
|
|
|
|
are not very large, so inversion of the array can be performed.]
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int Vec_IntCountCommon( Vec_Int_t * p1, Vec_Int_t * p2 )
|
|
|
|
|
{
|
|
|
|
|
Vec_Int_t * vTemp;
|
|
|
|
|
int Entry, i, Counter = 0;
|
|
|
|
|
if ( Vec_IntSize(p1) < Vec_IntSize(p2) )
|
|
|
|
|
vTemp = p1, p1 = p2, p2 = vTemp;
|
|
|
|
|
assert( Vec_IntSize(p1) >= Vec_IntSize(p2) );
|
|
|
|
|
vTemp = Vec_IntInvert( p2, -1 );
|
|
|
|
|
Vec_IntFillExtra( vTemp, Vec_IntFindMax(p1) + 1, -1 );
|
|
|
|
|
Vec_IntForEachEntry( p1, Entry, i )
|
|
|
|
|
if ( Vec_IntEntry(vTemp, Entry) >= 0 )
|
|
|
|
|
Counter++;
|
|
|
|
|
Vec_IntFree( vTemp );
|
|
|
|
|
return Counter;
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-29 17:01:00 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Comparison procedure for two integers.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
2008-07-02 17:01:00 +02:00
|
|
|
static int Vec_IntSortCompare1( int * pp1, int * pp2 )
|
2005-07-29 17:01:00 +02:00
|
|
|
{
|
|
|
|
|
// for some reason commenting out lines (as shown) led to crashing of the release version
|
|
|
|
|
if ( *pp1 < *pp2 )
|
|
|
|
|
return -1;
|
|
|
|
|
if ( *pp1 > *pp2 ) //
|
|
|
|
|
return 1;
|
|
|
|
|
return 0; //
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Comparison procedure for two integers.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
2008-07-02 17:01:00 +02:00
|
|
|
static int Vec_IntSortCompare2( int * pp1, int * pp2 )
|
2005-07-29 17:01:00 +02:00
|
|
|
{
|
|
|
|
|
// for some reason commenting out lines (as shown) led to crashing of the release version
|
|
|
|
|
if ( *pp1 > *pp2 )
|
|
|
|
|
return -1;
|
|
|
|
|
if ( *pp1 < *pp2 ) //
|
|
|
|
|
return 1;
|
|
|
|
|
return 0; //
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Sorting the entries by their integer value.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline void Vec_IntSort( Vec_Int_t * p, int fReverse )
|
|
|
|
|
{
|
|
|
|
|
if ( fReverse )
|
|
|
|
|
qsort( (void *)p->pArray, p->nSize, sizeof(int),
|
|
|
|
|
(int (*)(const void *, const void *)) Vec_IntSortCompare2 );
|
|
|
|
|
else
|
|
|
|
|
qsort( (void *)p->pArray, p->nSize, sizeof(int),
|
|
|
|
|
(int (*)(const void *, const void *)) Vec_IntSortCompare1 );
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-01 09:35:04 +01:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Leaves only unique entries.]
|
|
|
|
|
|
2012-08-10 02:53:38 +02:00
|
|
|
Description [Returns the number of duplicated entried found.]
|
2010-11-01 09:35:04 +01:00
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
2012-08-10 02:53:38 +02:00
|
|
|
static inline int Vec_IntUniqify( Vec_Int_t * p )
|
2010-11-01 09:35:04 +01:00
|
|
|
{
|
2012-08-10 02:53:38 +02:00
|
|
|
int i, k, RetValue;
|
2010-11-01 09:35:04 +01:00
|
|
|
if ( p->nSize < 2 )
|
2012-08-10 02:53:38 +02:00
|
|
|
return 0;
|
2010-11-01 09:35:04 +01:00
|
|
|
Vec_IntSort( p, 0 );
|
|
|
|
|
for ( i = k = 1; i < p->nSize; i++ )
|
|
|
|
|
if ( p->pArray[i] != p->pArray[i-1] )
|
|
|
|
|
p->pArray[k++] = p->pArray[i];
|
2012-08-10 02:53:38 +02:00
|
|
|
RetValue = p->nSize - k;
|
2010-11-01 09:35:04 +01:00
|
|
|
p->nSize = k;
|
2012-08-10 02:53:38 +02:00
|
|
|
return RetValue;
|
2010-11-01 09:35:04 +01:00
|
|
|
}
|
2013-04-28 00:23:12 +02:00
|
|
|
static inline int Vec_IntCountDuplicates( Vec_Int_t * p )
|
|
|
|
|
{
|
|
|
|
|
int RetValue;
|
|
|
|
|
Vec_Int_t * pDup = Vec_IntDup( p );
|
|
|
|
|
Vec_IntUniqify( pDup );
|
|
|
|
|
RetValue = Vec_IntSize(p) - Vec_IntSize(pDup);
|
|
|
|
|
Vec_IntFree( pDup );
|
|
|
|
|
return RetValue;
|
|
|
|
|
}
|
|
|
|
|
static inline int Vec_IntCheckUniqueSmall( Vec_Int_t * p )
|
|
|
|
|
{
|
|
|
|
|
int i, k;
|
|
|
|
|
for ( i = 0; i < p->nSize; i++ )
|
|
|
|
|
for ( k = i+1; k < p->nSize; k++ )
|
|
|
|
|
if ( p->pArray[i] == p->pArray[k] )
|
|
|
|
|
return 0;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2014-03-23 00:24:44 +01:00
|
|
|
static inline int Vec_IntCountUnique( Vec_Int_t * p )
|
|
|
|
|
{
|
|
|
|
|
int i, Count = 0, Max = Vec_IntFindMax(p);
|
|
|
|
|
unsigned char * pPres = ABC_CALLOC( unsigned char, Max+1 );
|
|
|
|
|
for ( i = 0; i < p->nSize; i++ )
|
|
|
|
|
if ( pPres[p->pArray[i]] == 0 )
|
|
|
|
|
pPres[p->pArray[i]] = 1, Count++;
|
|
|
|
|
ABC_FREE( pPres );
|
|
|
|
|
return Count;
|
|
|
|
|
}
|
2005-08-18 17:01:00 +02:00
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Comparison procedure for two integers.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
2012-02-25 01:18:38 +01:00
|
|
|
static inline int Vec_IntSortCompareUnsigned( unsigned * pp1, unsigned * pp2 )
|
2005-08-18 17:01:00 +02:00
|
|
|
{
|
|
|
|
|
if ( *pp1 < *pp2 )
|
|
|
|
|
return -1;
|
|
|
|
|
if ( *pp1 > *pp2 )
|
|
|
|
|
return 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Sorting the entries by their integer value.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline void Vec_IntSortUnsigned( Vec_Int_t * p )
|
|
|
|
|
{
|
|
|
|
|
qsort( (void *)p->pArray, p->nSize, sizeof(int),
|
|
|
|
|
(int (*)(const void *, const void *)) Vec_IntSortCompareUnsigned );
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-31 05:01:00 +01:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Returns the number of common entries.]
|
|
|
|
|
|
|
|
|
|
Description [Assumes that the vectors are sorted in the increasing order.]
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int Vec_IntTwoCountCommon( Vec_Int_t * vArr1, Vec_Int_t * vArr2 )
|
|
|
|
|
{
|
|
|
|
|
int * pBeg1 = vArr1->pArray;
|
|
|
|
|
int * pBeg2 = vArr2->pArray;
|
|
|
|
|
int * pEnd1 = vArr1->pArray + vArr1->nSize;
|
|
|
|
|
int * pEnd2 = vArr2->pArray + vArr2->nSize;
|
|
|
|
|
int Counter = 0;
|
|
|
|
|
while ( pBeg1 < pEnd1 && pBeg2 < pEnd2 )
|
|
|
|
|
{
|
|
|
|
|
if ( *pBeg1 == *pBeg2 )
|
|
|
|
|
pBeg1++, pBeg2++, Counter++;
|
|
|
|
|
else if ( *pBeg1 < *pBeg2 )
|
|
|
|
|
pBeg1++;
|
|
|
|
|
else
|
|
|
|
|
pBeg2++;
|
|
|
|
|
}
|
|
|
|
|
return Counter;
|
|
|
|
|
}
|
2013-05-05 10:54:11 +02:00
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Collects common entries.]
|
|
|
|
|
|
|
|
|
|
Description [Assumes that the vectors are sorted in the increasing order.]
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
2013-05-04 00:45:50 +02:00
|
|
|
static inline int Vec_IntTwoFindCommon( Vec_Int_t * vArr1, Vec_Int_t * vArr2, Vec_Int_t * vArr )
|
|
|
|
|
{
|
|
|
|
|
int * pBeg1 = vArr1->pArray;
|
|
|
|
|
int * pBeg2 = vArr2->pArray;
|
|
|
|
|
int * pEnd1 = vArr1->pArray + vArr1->nSize;
|
|
|
|
|
int * pEnd2 = vArr2->pArray + vArr2->nSize;
|
|
|
|
|
Vec_IntClear( vArr );
|
|
|
|
|
while ( pBeg1 < pEnd1 && pBeg2 < pEnd2 )
|
|
|
|
|
{
|
|
|
|
|
if ( *pBeg1 == *pBeg2 )
|
|
|
|
|
Vec_IntPush( vArr, *pBeg1 ), pBeg1++, pBeg2++;
|
|
|
|
|
else if ( *pBeg1 < *pBeg2 )
|
|
|
|
|
pBeg1++;
|
|
|
|
|
else
|
|
|
|
|
pBeg2++;
|
|
|
|
|
}
|
|
|
|
|
return Vec_IntSize(vArr);
|
|
|
|
|
}
|
2008-01-31 05:01:00 +01:00
|
|
|
|
2013-05-05 10:54:11 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Collects and removes common entries]
|
|
|
|
|
|
|
|
|
|
Description [Assumes that the vectors are sorted in the increasing order.]
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int Vec_IntTwoRemoveCommon( Vec_Int_t * vArr1, Vec_Int_t * vArr2, Vec_Int_t * vArr )
|
|
|
|
|
{
|
|
|
|
|
int * pBeg1 = vArr1->pArray;
|
|
|
|
|
int * pBeg2 = vArr2->pArray;
|
|
|
|
|
int * pEnd1 = vArr1->pArray + vArr1->nSize;
|
|
|
|
|
int * pEnd2 = vArr2->pArray + vArr2->nSize;
|
|
|
|
|
int * pBeg1New = vArr1->pArray;
|
|
|
|
|
int * pBeg2New = vArr2->pArray;
|
|
|
|
|
Vec_IntClear( vArr );
|
|
|
|
|
while ( pBeg1 < pEnd1 && pBeg2 < pEnd2 )
|
|
|
|
|
{
|
|
|
|
|
if ( *pBeg1 == *pBeg2 )
|
|
|
|
|
Vec_IntPush( vArr, *pBeg1 ), pBeg1++, pBeg2++;
|
|
|
|
|
else if ( *pBeg1 < *pBeg2 )
|
|
|
|
|
*pBeg1New++ = *pBeg1++;
|
|
|
|
|
else
|
|
|
|
|
*pBeg2New++ = *pBeg2++;
|
|
|
|
|
}
|
|
|
|
|
while ( pBeg1 < pEnd1 )
|
|
|
|
|
*pBeg1New++ = *pBeg1++;
|
|
|
|
|
while ( pBeg2 < pEnd2 )
|
|
|
|
|
*pBeg2New++ = *pBeg2++;
|
|
|
|
|
Vec_IntShrink( vArr1, pBeg1New - vArr1->pArray );
|
|
|
|
|
Vec_IntShrink( vArr2, pBeg2New - vArr2->pArray );
|
|
|
|
|
return Vec_IntSize(vArr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Removes entries of the second one from the first one.]
|
|
|
|
|
|
|
|
|
|
Description [Assumes that the vectors are sorted in the increasing order.]
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int Vec_IntTwoRemove( Vec_Int_t * vArr1, Vec_Int_t * vArr2 )
|
|
|
|
|
{
|
|
|
|
|
int * pBeg1 = vArr1->pArray;
|
|
|
|
|
int * pBeg2 = vArr2->pArray;
|
|
|
|
|
int * pEnd1 = vArr1->pArray + vArr1->nSize;
|
|
|
|
|
int * pEnd2 = vArr2->pArray + vArr2->nSize;
|
|
|
|
|
int * pBeg1New = vArr1->pArray;
|
|
|
|
|
while ( pBeg1 < pEnd1 && pBeg2 < pEnd2 )
|
|
|
|
|
{
|
|
|
|
|
if ( *pBeg1 == *pBeg2 )
|
|
|
|
|
pBeg1++, pBeg2++;
|
|
|
|
|
else if ( *pBeg1 < *pBeg2 )
|
|
|
|
|
*pBeg1New++ = *pBeg1++;
|
|
|
|
|
else
|
|
|
|
|
pBeg2++;
|
|
|
|
|
}
|
|
|
|
|
while ( pBeg1 < pEnd1 )
|
|
|
|
|
*pBeg1New++ = *pBeg1++;
|
|
|
|
|
Vec_IntShrink( vArr1, pBeg1New - vArr1->pArray );
|
|
|
|
|
return Vec_IntSize(vArr1);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-31 05:01:00 +01:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Returns the result of merging the two vectors.]
|
|
|
|
|
|
|
|
|
|
Description [Assumes that the vectors are sorted in the increasing order.]
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
2013-10-07 00:57:17 +02:00
|
|
|
static inline void Vec_IntTwoMerge2Int( Vec_Int_t * vArr1, Vec_Int_t * vArr2, Vec_Int_t * vArr )
|
2008-01-31 05:01:00 +01:00
|
|
|
{
|
|
|
|
|
int * pBeg = vArr->pArray;
|
|
|
|
|
int * pBeg1 = vArr1->pArray;
|
|
|
|
|
int * pBeg2 = vArr2->pArray;
|
|
|
|
|
int * pEnd1 = vArr1->pArray + vArr1->nSize;
|
|
|
|
|
int * pEnd2 = vArr2->pArray + vArr2->nSize;
|
|
|
|
|
while ( pBeg1 < pEnd1 && pBeg2 < pEnd2 )
|
|
|
|
|
{
|
|
|
|
|
if ( *pBeg1 == *pBeg2 )
|
|
|
|
|
*pBeg++ = *pBeg1++, pBeg2++;
|
|
|
|
|
else if ( *pBeg1 < *pBeg2 )
|
|
|
|
|
*pBeg++ = *pBeg1++;
|
|
|
|
|
else
|
|
|
|
|
*pBeg++ = *pBeg2++;
|
|
|
|
|
}
|
|
|
|
|
while ( pBeg1 < pEnd1 )
|
|
|
|
|
*pBeg++ = *pBeg1++;
|
|
|
|
|
while ( pBeg2 < pEnd2 )
|
|
|
|
|
*pBeg++ = *pBeg2++;
|
|
|
|
|
vArr->nSize = pBeg - vArr->pArray;
|
|
|
|
|
assert( vArr->nSize <= vArr->nCap );
|
|
|
|
|
assert( vArr->nSize >= vArr1->nSize );
|
|
|
|
|
assert( vArr->nSize >= vArr2->nSize );
|
2013-10-07 00:57:17 +02:00
|
|
|
}
|
|
|
|
|
static inline Vec_Int_t * Vec_IntTwoMerge( Vec_Int_t * vArr1, Vec_Int_t * vArr2 )
|
|
|
|
|
{
|
|
|
|
|
Vec_Int_t * vArr = Vec_IntAlloc( vArr1->nSize + vArr2->nSize );
|
|
|
|
|
Vec_IntTwoMerge2Int( vArr1, vArr2, vArr );
|
2008-01-31 05:01:00 +01:00
|
|
|
return vArr;
|
|
|
|
|
}
|
2013-10-07 00:57:17 +02:00
|
|
|
static inline void Vec_IntTwoMerge2( Vec_Int_t * vArr1, Vec_Int_t * vArr2, Vec_Int_t * vArr )
|
|
|
|
|
{
|
|
|
|
|
Vec_IntGrow( vArr, Vec_IntSize(vArr1) + Vec_IntSize(vArr2) );
|
|
|
|
|
Vec_IntTwoMerge2Int( vArr1, vArr2, vArr );
|
|
|
|
|
}
|
2008-01-31 05:01:00 +01:00
|
|
|
|
2012-03-25 10:24:26 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
2013-05-05 10:54:11 +02:00
|
|
|
Synopsis [Returns the result of splitting of the two vectors.]
|
2012-03-25 10:24:26 +02:00
|
|
|
|
|
|
|
|
Description [Assumes that the vectors are sorted in the increasing order.]
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline void Vec_IntTwoSplit( Vec_Int_t * vArr1, Vec_Int_t * vArr2, Vec_Int_t * vArr, Vec_Int_t * vArr1n, Vec_Int_t * vArr2n )
|
|
|
|
|
{
|
|
|
|
|
int * pBeg1 = vArr1->pArray;
|
|
|
|
|
int * pBeg2 = vArr2->pArray;
|
|
|
|
|
int * pEnd1 = vArr1->pArray + vArr1->nSize;
|
|
|
|
|
int * pEnd2 = vArr2->pArray + vArr2->nSize;
|
|
|
|
|
while ( pBeg1 < pEnd1 && pBeg2 < pEnd2 )
|
|
|
|
|
{
|
|
|
|
|
if ( *pBeg1 == *pBeg2 )
|
|
|
|
|
Vec_IntPush( vArr, *pBeg1++ ), pBeg2++;
|
|
|
|
|
else if ( *pBeg1 < *pBeg2 )
|
|
|
|
|
Vec_IntPush( vArr1n, *pBeg1++ );
|
|
|
|
|
else
|
|
|
|
|
Vec_IntPush( vArr2n, *pBeg2++ );
|
|
|
|
|
}
|
|
|
|
|
while ( pBeg1 < pEnd1 )
|
|
|
|
|
Vec_IntPush( vArr1n, *pBeg1++ );
|
|
|
|
|
while ( pBeg2 < pEnd2 )
|
|
|
|
|
Vec_IntPush( vArr2n, *pBeg2++ );
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-01 09:35:04 +01:00
|
|
|
|
2011-04-07 22:49:03 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
2012-02-15 07:15:49 +01:00
|
|
|
Synopsis []
|
2011-04-07 22:49:03 +02:00
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline void Vec_IntSelectSort( int * pArray, int nSize )
|
|
|
|
|
{
|
|
|
|
|
int temp, i, j, best_i;
|
|
|
|
|
for ( i = 0; i < nSize-1; i++ )
|
|
|
|
|
{
|
|
|
|
|
best_i = i;
|
|
|
|
|
for ( j = i+1; j < nSize; j++ )
|
|
|
|
|
if ( pArray[j] < pArray[best_i] )
|
|
|
|
|
best_i = j;
|
|
|
|
|
temp = pArray[i];
|
|
|
|
|
pArray[i] = pArray[best_i];
|
|
|
|
|
pArray[best_i] = temp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-15 07:15:49 +01:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline void Vec_IntSelectSortCost( int * pArray, int nSize, Vec_Int_t * vCosts )
|
|
|
|
|
{
|
|
|
|
|
int temp, i, j, best_i;
|
|
|
|
|
for ( i = 0; i < nSize-1; i++ )
|
|
|
|
|
{
|
|
|
|
|
best_i = i;
|
|
|
|
|
for ( j = i+1; j < nSize; j++ )
|
|
|
|
|
if ( Vec_IntEntry(vCosts, pArray[j]) < Vec_IntEntry(vCosts, pArray[best_i]) )
|
|
|
|
|
best_i = j;
|
|
|
|
|
temp = pArray[i];
|
|
|
|
|
pArray[i] = pArray[best_i];
|
|
|
|
|
pArray[best_i] = temp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-30 06:22:26 +01:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline void Vec_IntPrint( Vec_Int_t * vVec )
|
|
|
|
|
{
|
|
|
|
|
int i, Entry;
|
|
|
|
|
printf( "Vector has %d entries: {", Vec_IntSize(vVec) );
|
|
|
|
|
Vec_IntForEachEntry( vVec, Entry, i )
|
|
|
|
|
printf( " %d", Entry );
|
|
|
|
|
printf( " }\n" );
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-11 09:22:05 +01:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int Vec_IntCompareVec( Vec_Int_t * p1, Vec_Int_t * p2 )
|
|
|
|
|
{
|
|
|
|
|
if ( p1 == NULL || p2 == NULL )
|
|
|
|
|
return (p1 != NULL) - (p2 != NULL);
|
|
|
|
|
if ( Vec_IntSize(p1) != Vec_IntSize(p2) )
|
|
|
|
|
return Vec_IntSize(p1) - Vec_IntSize(p2);
|
|
|
|
|
return memcmp( Vec_IntArray(p1), Vec_IntArray(p2), sizeof(int)*Vec_IntSize(p1) );
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-15 07:15:49 +01:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Appends the contents of the second vector.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
2012-02-25 01:18:38 +01:00
|
|
|
static inline void Vec_IntAppend( Vec_Int_t * vVec1, Vec_Int_t * vVec2 )
|
2012-02-15 07:15:49 +01:00
|
|
|
{
|
|
|
|
|
int Entry, i;
|
|
|
|
|
Vec_IntForEachEntry( vVec2, Entry, i )
|
|
|
|
|
Vec_IntPush( vVec1, Entry );
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-01 09:35:04 +01:00
|
|
|
|
|
|
|
|
ABC_NAMESPACE_HEADER_END
|
|
|
|
|
|
2008-01-31 05:01:00 +01:00
|
|
|
#endif
|
|
|
|
|
|
2005-07-29 17:01:00 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
/// END OF FILE ///
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|