summaryrefslogtreecommitdiffstats
path: root/src/misc/vec/vecStr.h
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2010-11-01 01:35:04 -0700
committerAlan Mishchenko <alanmi@berkeley.edu>2010-11-01 01:35:04 -0700
commit6130e39b18b5f53902e4eab14f6d5cdde5219563 (patch)
tree0db0628479a1b750e9af1f66cb8379ebd0913d31 /src/misc/vec/vecStr.h
parentf0e77f6797c0504b0da25a56152b707d3357f386 (diff)
downloadabc-6130e39b18b5f53902e4eab14f6d5cdde5219563.tar.gz
abc-6130e39b18b5f53902e4eab14f6d5cdde5219563.tar.bz2
abc-6130e39b18b5f53902e4eab14f6d5cdde5219563.zip
initial commit of public abc
Diffstat (limited to 'src/misc/vec/vecStr.h')
-rw-r--r--src/misc/vec/vecStr.h111
1 files changed, 55 insertions, 56 deletions
diff --git a/src/misc/vec/vecStr.h b/src/misc/vec/vecStr.h
index bd10154c..c92760f2 100644
--- a/src/misc/vec/vecStr.h
+++ b/src/misc/vec/vecStr.h
@@ -21,12 +21,16 @@
#ifndef __VEC_STR_H__
#define __VEC_STR_H__
+
////////////////////////////////////////////////////////////////////////
/// INCLUDES ///
////////////////////////////////////////////////////////////////////////
#include <stdio.h>
+ABC_NAMESPACE_HEADER_START
+
+
////////////////////////////////////////////////////////////////////////
/// PARAMETERS ///
////////////////////////////////////////////////////////////////////////
@@ -214,6 +218,25 @@ static inline void Vec_StrFree( Vec_Str_t * p )
SeeAlso []
***********************************************************************/
+static inline void Vec_StrFreeP( Vec_Str_t ** p )
+{
+ if ( *p == NULL )
+ return;
+ ABC_FREE( (*p)->pArray );
+ ABC_FREE( (*p) );
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
static inline char * Vec_StrReleaseArray( Vec_Str_t * p )
{
char * pArray = p->pArray;
@@ -359,11 +382,12 @@ static inline void Vec_StrFill( Vec_Str_t * p, int nSize, char Fill )
static inline void Vec_StrFillExtra( Vec_Str_t * p, int nSize, char Fill )
{
int i;
- if ( p->nSize >= nSize )
+ if ( nSize <= p->nSize )
return;
- if ( nSize < 2 * p->nSize )
- nSize = 2 * p->nSize;
- Vec_StrGrow( p, nSize );
+ if ( nSize > 2 * p->nCap )
+ Vec_StrGrow( p, nSize );
+ else if ( nSize > p->nCap )
+ Vec_StrGrow( p, 2 * p->nCap );
for ( i = p->nSize; i < nSize; i++ )
p->pArray[i] = Fill;
p->nSize = nSize;
@@ -459,26 +483,22 @@ static inline void Vec_StrPush( Vec_Str_t * p, char Entry )
p->pArray[p->nSize++] = Entry;
}
-/**Function********************************************************************
-
- Synopsis [Finds the smallest integer larger of equal than the logarithm.]
+/**Function*************************************************************
- Description [Returns [Log10(Num)].]
+ Synopsis [Returns the last entry and removes it from the list.]
+ Description []
+
SideEffects []
SeeAlso []
-******************************************************************************/
-static inline int Vec_StrBase10Log( unsigned Num )
+***********************************************************************/
+static inline char Vec_StrPop( Vec_Str_t * p )
{
- int Res;
- assert( Num >= 0 );
- if ( Num == 0 ) return 0;
- if ( Num == 1 ) return 1;
- for ( Res = 0, Num--; Num; Num /= 10, Res++ );
- return Res;
-} /* end of Extra_Base2Log */
+ assert( p->nSize > 0 );
+ return p->pArray[--p->nSize];
+}
/**Function*************************************************************
@@ -493,26 +513,22 @@ static inline int Vec_StrBase10Log( unsigned Num )
***********************************************************************/
static inline void Vec_StrPrintNum( Vec_Str_t * p, int Num )
{
- int i, nDigits;
- if ( Num < 0 )
- {
- Vec_StrPush( p, '-' );
- Num = -Num;
- }
- if ( Num < 10 )
+ int i;
+ char Digits[16];
+ if ( Num == 0 )
{
- Vec_StrPush( p, (char)('0' + Num) );
+ Vec_StrPush( p, '0' );
return;
}
- nDigits = Vec_StrBase10Log( Num );
- Vec_StrGrow( p, p->nSize + nDigits );
- for ( i = nDigits - 1; i >= 0; i-- )
+ if ( Num < 0 )
{
- Vec_StrWriteEntry( p, p->nSize + i, (char)('0' + Num % 10) );
- Num /= 10;
+ Vec_StrPush( p, '-' );
+ Num = -Num;
}
- assert( Num == 0 );
- p->nSize += nDigits;
+ for ( i = 0; Num; Num /= 10, i++ )
+ Digits[i] = (char)('0' + Num % 10);
+ for ( i--; i >= 0; i-- )
+ Vec_StrPush( p, Digits[i] );
}
/**Function*************************************************************
@@ -526,7 +542,7 @@ static inline void Vec_StrPrintNum( Vec_Str_t * p, int Num )
SeeAlso []
***********************************************************************/
-static inline void Vec_StrPrintStr( Vec_Str_t * p, char * pStr )
+static inline void Vec_StrPrintStr( Vec_Str_t * p, const char * pStr )
{
int i, Length = strlen(pStr);
for ( i = 0; i < Length; i++ )
@@ -544,30 +560,9 @@ static inline void Vec_StrPrintStr( Vec_Str_t * p, char * pStr )
SeeAlso []
***********************************************************************/
-static inline void Vec_StrAppend( Vec_Str_t * p, char * pString )
+static inline void Vec_StrAppend( Vec_Str_t * p, const char * pString )
{
- int i, nLength = strlen(pString);
- Vec_StrGrow( p, p->nSize + nLength );
- for ( i = 0; i < nLength; i++ )
- p->pArray[p->nSize + i] = pString[i];
- p->nSize += nLength;
-}
-
-/**Function*************************************************************
-
- Synopsis [Returns the last entry and removes it from the list.]
-
- Description []
-
- SideEffects []
-
- SeeAlso []
-
-***********************************************************************/
-static inline char Vec_StrPop( Vec_Str_t * p )
-{
- assert( p->nSize > 0 );
- return p->pArray[--p->nSize];
+ Vec_StrPrintStr( p, pString );
}
/**Function*************************************************************
@@ -655,6 +650,10 @@ static inline void Vec_StrSort( Vec_Str_t * p, int fReverse )
(int (*)(const void *, const void *)) Vec_StrSortCompare1 );
}
+
+
+ABC_NAMESPACE_HEADER_END
+
#endif
////////////////////////////////////////////////////////////////////////