src/misc/vec/vecStr.h File Reference

#include <stdio.h>
Include dependency graph for vecStr.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Vec_Str_t_

Defines

#define Vec_StrForEachEntry(vVec, Entry, i)   for ( i = 0; (i < Vec_StrSize(vVec)) && (((Entry) = Vec_StrEntry(vVec, i)), 1); i++ )

Typedefs

typedef struct Vec_Str_t_ Vec_Str_t

Functions

static Vec_Str_tVec_StrAlloc (int nCap)
static Vec_Str_tVec_StrStart (int nSize)
static Vec_Str_tVec_StrAllocArray (char *pArray, int nSize)
static Vec_Str_tVec_StrAllocArrayCopy (char *pArray, int nSize)
static Vec_Str_tVec_StrDup (Vec_Str_t *pVec)
static Vec_Str_tVec_StrDupArray (Vec_Str_t *pVec)
static void Vec_StrFree (Vec_Str_t *p)
static char * Vec_StrReleaseArray (Vec_Str_t *p)
static char * Vec_StrArray (Vec_Str_t *p)
static int Vec_StrSize (Vec_Str_t *p)
static char Vec_StrEntry (Vec_Str_t *p, int i)
static void Vec_StrWriteEntry (Vec_Str_t *p, int i, char Entry)
static char Vec_StrEntryLast (Vec_Str_t *p)
static void Vec_StrGrow (Vec_Str_t *p, int nCapMin)
static void Vec_StrFill (Vec_Str_t *p, int nSize, char Entry)
static void Vec_StrShrink (Vec_Str_t *p, int nSizeNew)
static void Vec_StrClear (Vec_Str_t *p)
static void Vec_StrPush (Vec_Str_t *p, char Entry)
static int Vec_StrBase10Log (unsigned Num)
static void Vec_StrPrintNum (Vec_Str_t *p, int Num)
static void Vec_StrPrintStr (Vec_Str_t *p, char *pStr)
static void Vec_StrAppend (Vec_Str_t *p, char *pString)
static char Vec_StrPop (Vec_Str_t *p)
static int Vec_StrSortCompare1 (char *pp1, char *pp2)
static int Vec_StrSortCompare2 (char *pp1, char *pp2)
static void Vec_StrSort (Vec_Str_t *p, int fReverse)

Define Documentation

#define Vec_StrForEachEntry ( vVec,
Entry,
 )     for ( i = 0; (i < Vec_StrSize(vVec)) && (((Entry) = Vec_StrEntry(vVec, i)), 1); i++ )

MACRO DEFINITIONS ///

Definition at line 50 of file vecStr.h.


Typedef Documentation

typedef struct Vec_Str_t_ Vec_Str_t

CFile****************************************************************

FileName [vecStr.h]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Resizable arrays.]

Synopsis [Resizable arrays of characters.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

Id
vecStr.h,v 1.00 2005/06/20 00:00:00 alanmi Exp

] INCLUDES /// PARAMETERS /// BASIC TYPES ///

Definition at line 38 of file vecStr.h.


Function Documentation

static Vec_Str_t* Vec_StrAlloc ( int  nCap  )  [inline, static]

FUNCTION DEFINITIONS ///Function*************************************************************

Synopsis [Allocates a vector with the given capacity.]

Description []

SideEffects []

SeeAlso []

Definition at line 68 of file vecStr.h.

00069 {
00070     Vec_Str_t * p;
00071     p = ALLOC( Vec_Str_t, 1 );
00072     if ( nCap > 0 && nCap < 16 )
00073         nCap = 16;
00074     p->nSize  = 0;
00075     p->nCap   = nCap;
00076     p->pArray = p->nCap? ALLOC( char, p->nCap ) : NULL;
00077     return p;
00078 }

static Vec_Str_t* Vec_StrAllocArray ( char *  pArray,
int  nSize 
) [inline, static]

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

Synopsis [Creates the vector from an integer array of the given size.]

Description []

SideEffects []

SeeAlso []

Definition at line 111 of file vecStr.h.

00112 {
00113     Vec_Str_t * p;
00114     p = ALLOC( Vec_Str_t, 1 );
00115     p->nSize  = nSize;
00116     p->nCap   = nSize;
00117     p->pArray = pArray;
00118     return p;
00119 }

static Vec_Str_t* Vec_StrAllocArrayCopy ( char *  pArray,
int  nSize 
) [inline, static]

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

Synopsis [Creates the vector from an integer array of the given size.]

Description []

SideEffects []

SeeAlso []

Definition at line 132 of file vecStr.h.

00133 {
00134     Vec_Str_t * p;
00135     p = ALLOC( Vec_Str_t, 1 );
00136     p->nSize  = nSize;
00137     p->nCap   = nSize;
00138     p->pArray = ALLOC( char, nSize );
00139     memcpy( p->pArray, pArray, sizeof(char) * nSize );
00140     return p;
00141 }

static void Vec_StrAppend ( Vec_Str_t p,
char *  pString 
) [inline, static]

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

Synopsis [Appends the string to the char vector.]

Description []

SideEffects []

SeeAlso []

Definition at line 489 of file vecStr.h.

00490 {
00491     int i, nLength = strlen(pString);
00492     Vec_StrGrow( p, p->nSize + nLength );
00493     for ( i = 0; i < nLength; i++ )
00494         p->pArray[p->nSize + i] = pString[i];
00495     p->nSize += nLength;
00496 }

static char* Vec_StrArray ( Vec_Str_t p  )  [inline, static]

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 237 of file vecStr.h.

00238 {
00239     return p->pArray;
00240 }

static int Vec_StrBase10Log ( unsigned  Num  )  [inline, static]

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

Synopsis [Finds the smallest integer larger of equal than the logarithm.]

Description [Returns [Log10(Num)].]

SideEffects []

SeeAlso []

Definition at line 415 of file vecStr.h.

00416 {
00417     int Res;
00418     assert( Num >= 0 );
00419     if ( Num == 0 ) return 0;
00420     if ( Num == 1 ) return 1;
00421         for ( Res = 0, Num--;  Num;  Num /= 10,  Res++ );
00422     return Res;
00423 } /* end of Extra_Base2Log */

static void Vec_StrClear ( Vec_Str_t p  )  [inline, static]

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 376 of file vecStr.h.

00377 {
00378     p->nSize = 0;
00379 }

static Vec_Str_t* Vec_StrDup ( Vec_Str_t pVec  )  [inline, static]

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

Synopsis [Duplicates the integer array.]

Description []

SideEffects []

SeeAlso []

Definition at line 154 of file vecStr.h.

00155 {
00156     Vec_Str_t * p;
00157     p = ALLOC( Vec_Str_t, 1 );
00158     p->nSize  = pVec->nSize;
00159     p->nCap   = pVec->nCap;
00160     p->pArray = p->nCap? ALLOC( char, p->nCap ) : NULL;
00161     memcpy( p->pArray, pVec->pArray, sizeof(char) * pVec->nSize );
00162     return p;
00163 }

static Vec_Str_t* Vec_StrDupArray ( Vec_Str_t pVec  )  [inline, static]

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

Synopsis [Transfers the array into another vector.]

Description []

SideEffects []

SeeAlso []

Definition at line 176 of file vecStr.h.

00177 {
00178     Vec_Str_t * p;
00179     p = ALLOC( Vec_Str_t, 1 );
00180     p->nSize  = pVec->nSize;
00181     p->nCap   = pVec->nCap;
00182     p->pArray = pVec->pArray;
00183     pVec->nSize  = 0;
00184     pVec->nCap   = 0;
00185     pVec->pArray = NULL;
00186     return p;
00187 }

static char Vec_StrEntry ( Vec_Str_t p,
int  i 
) [inline, static]

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 269 of file vecStr.h.

00270 {
00271     assert( i >= 0 && i < p->nSize );
00272     return p->pArray[i];
00273 }

static char Vec_StrEntryLast ( Vec_Str_t p  )  [inline, static]

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 303 of file vecStr.h.

00304 {
00305     assert( p->nSize > 0 );
00306     return p->pArray[p->nSize-1];
00307 }

static void Vec_StrFill ( Vec_Str_t p,
int  nSize,
char  Entry 
) [inline, static]

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

Synopsis [Fills the vector with given number of entries.]

Description []

SideEffects []

SeeAlso []

Definition at line 339 of file vecStr.h.

00340 {
00341     int i;
00342     Vec_StrGrow( p, nSize );
00343     p->nSize = nSize;
00344     for ( i = 0; i < p->nSize; i++ )
00345         p->pArray[i] = Entry;
00346 }

static void Vec_StrFree ( Vec_Str_t p  )  [inline, static]

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 200 of file vecStr.h.

00201 {
00202     FREE( p->pArray );
00203     FREE( p );
00204 }

static void Vec_StrGrow ( Vec_Str_t p,
int  nCapMin 
) [inline, static]

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

Synopsis [Resizes the vector to the given capacity.]

Description []

SideEffects []

SeeAlso []

Definition at line 320 of file vecStr.h.

00321 {
00322     if ( p->nCap >= nCapMin )
00323         return;
00324     p->pArray = REALLOC( char, p->pArray, 2 * nCapMin ); 
00325     p->nCap   = 2 * nCapMin;
00326 }

static char Vec_StrPop ( Vec_Str_t p  )  [inline, static]

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

Synopsis [Returns the last entry and removes it from the list.]

Description []

SideEffects []

SeeAlso []

Definition at line 509 of file vecStr.h.

00510 {
00511     assert( p->nSize > 0 );
00512     return p->pArray[--p->nSize];
00513 }

static void Vec_StrPrintNum ( Vec_Str_t p,
int  Num 
) [inline, static]

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 436 of file vecStr.h.

00437 {
00438     int i, nDigits;
00439     if ( Num < 0 )
00440     {
00441         Vec_StrPush( p, '-' );
00442         Num = -Num;
00443     }
00444     if ( Num < 10 )
00445     {
00446         Vec_StrPush( p, (char)('0' + Num) );
00447         return;
00448     }
00449     nDigits = Vec_StrBase10Log( Num );
00450     Vec_StrGrow( p, p->nSize + nDigits );
00451     for ( i = nDigits - 1; i >= 0; i-- )
00452     {
00453         Vec_StrWriteEntry( p, p->nSize + i, (char)('0' + Num % 10) );
00454         Num /= 10;
00455     }
00456     assert( Num == 0 );
00457     p->nSize += nDigits;
00458 }

static void Vec_StrPrintStr ( Vec_Str_t p,
char *  pStr 
) [inline, static]

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 471 of file vecStr.h.

00472 {
00473     int i, Length = strlen(pStr);
00474     for ( i = 0; i < Length; i++ )
00475         Vec_StrPush( p, pStr[i] );
00476 }

static void Vec_StrPush ( Vec_Str_t p,
char  Entry 
) [inline, static]

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 392 of file vecStr.h.

00393 {
00394     if ( p->nSize == p->nCap )
00395     {
00396         if ( p->nCap < 16 )
00397             Vec_StrGrow( p, 16 );
00398         else
00399             Vec_StrGrow( p, 2 * p->nCap );
00400     }
00401     p->pArray[p->nSize++] = Entry;
00402 }

static char* Vec_StrReleaseArray ( Vec_Str_t p  )  [inline, static]

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 217 of file vecStr.h.

00218 {
00219     char * pArray = p->pArray;
00220     p->nCap = 0;
00221     p->nSize = 0;
00222     p->pArray = NULL;
00223     return pArray;
00224 }

static void Vec_StrShrink ( Vec_Str_t p,
int  nSizeNew 
) [inline, static]

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 359 of file vecStr.h.

00360 {
00361     assert( p->nSize >= nSizeNew );
00362     p->nSize = nSizeNew;
00363 }

static int Vec_StrSize ( Vec_Str_t p  )  [inline, static]

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 253 of file vecStr.h.

00254 {
00255     return p->nSize;
00256 }

static void Vec_StrSort ( Vec_Str_t p,
int  fReverse 
) [inline, static]

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

Synopsis [Sorting the entries by their integer value.]

Description []

SideEffects []

SeeAlso []

Definition at line 568 of file vecStr.h.

00569 {
00570     if ( fReverse ) 
00571         qsort( (void *)p->pArray, p->nSize, sizeof(char), 
00572                 (int (*)(const void *, const void *)) Vec_StrSortCompare2 );
00573     else
00574         qsort( (void *)p->pArray, p->nSize, sizeof(char), 
00575                 (int (*)(const void *, const void *)) Vec_StrSortCompare1 );
00576 }

static int Vec_StrSortCompare1 ( char *  pp1,
char *  pp2 
) [inline, static]

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

Synopsis [Comparison procedure for two clauses.]

Description []

SideEffects []

SeeAlso []

Definition at line 526 of file vecStr.h.

00527 {
00528     // for some reason commenting out lines (as shown) led to crashing of the release version
00529     if ( *pp1 < *pp2 )
00530         return -1;
00531     if ( *pp1 > *pp2 ) //
00532         return 1;
00533     return 0; //
00534 }

static int Vec_StrSortCompare2 ( char *  pp1,
char *  pp2 
) [inline, static]

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

Synopsis [Comparison procedure for two clauses.]

Description []

SideEffects []

SeeAlso []

Definition at line 547 of file vecStr.h.

00548 {
00549     // for some reason commenting out lines (as shown) led to crashing of the release version
00550     if ( *pp1 > *pp2 )
00551         return -1;
00552     if ( *pp1 < *pp2 ) //
00553         return 1;
00554     return 0; //
00555 }

static Vec_Str_t* Vec_StrStart ( int  nSize  )  [inline, static]

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

Synopsis [Allocates a vector with the given size and cleans it.]

Description []

SideEffects []

SeeAlso []

Definition at line 91 of file vecStr.h.

00092 {
00093     Vec_Str_t * p;
00094     p = Vec_StrAlloc( nSize );
00095     p->nSize = nSize;
00096     memset( p->pArray, 0, sizeof(char) * nSize );
00097     return p;
00098 }

static void Vec_StrWriteEntry ( Vec_Str_t p,
int  i,
char  Entry 
) [inline, static]

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 286 of file vecStr.h.

00287 {
00288     assert( i >= 0 && i < p->nSize );
00289     p->pArray[i] = Entry;
00290 }


Generated on Tue Jan 5 12:19:22 2010 for abc70930 by  doxygen 1.6.1