(trunk libT) move tr_bitfield into its own, package-visible source files. this may break the mac build temporarily until the xcode file gets synced

This commit is contained in:
Charles Kerr
2009-06-15 00:11:06 +00:00
parent 2e23c8fade
commit 8e676171d4
8 changed files with 318 additions and 297 deletions

View File

@@ -379,76 +379,6 @@ int tr_httpParseURL( const char * url,
int * setme_port,
char ** setme_path );
/***
****
***/
typedef struct tr_bitfield
{
uint8_t * bits;
size_t bitCount;
size_t byteCount;
}
tr_bitfield;
tr_bitfield* tr_bitfieldConstruct( tr_bitfield*, size_t bitcount );
tr_bitfield* tr_bitfieldDestruct( tr_bitfield* );
static TR_INLINE tr_bitfield* tr_bitfieldNew( size_t bitcount )
{
return tr_bitfieldConstruct( tr_new0( tr_bitfield, 1 ), bitcount );
}
static TR_INLINE void tr_bitfieldFree( tr_bitfield * b )
{
tr_free( tr_bitfieldDestruct( b ) );
}
tr_bitfield* tr_bitfieldDup( const tr_bitfield* ) TR_GNUC_MALLOC;
void tr_bitfieldClear( tr_bitfield* );
int tr_bitfieldAdd( tr_bitfield*, size_t bit );
int tr_bitfieldRem( tr_bitfield*, size_t bit );
int tr_bitfieldAddRange( tr_bitfield *, size_t begin, size_t end );
int tr_bitfieldRemRange( tr_bitfield*, size_t begin, size_t end );
void tr_bitfieldDifference( tr_bitfield *, const tr_bitfield * );
int tr_bitfieldIsEmpty( const tr_bitfield* );
size_t tr_bitfieldCountTrueBits( const tr_bitfield* );
tr_bitfield* tr_bitfieldOr( tr_bitfield*, const tr_bitfield* );
/** A stripped-down version of bitfieldHas to be used
for speed when you're looping quickly. This version
has none of tr_bitfieldHas()'s safety checks, so you
need to call tr_bitfieldTestFast() first before you
start looping. */
static TR_INLINE tr_bool tr_bitfieldHasFast( const tr_bitfield * b, const size_t nth )
{
return ( b->bits[nth>>3u] << ( nth & 7u ) & 0x80 ) != 0;
}
/** @param high the highest nth bit you're going to access */
static TR_INLINE tr_bool tr_bitfieldTestFast( const tr_bitfield * b, const size_t high )
{
return ( b != NULL )
&& ( b->bits != NULL )
&& ( high < b->bitCount );
}
static TR_INLINE tr_bool tr_bitfieldHas( const tr_bitfield * b, size_t nth )
{
return tr_bitfieldTestFast( b, nth ) && tr_bitfieldHasFast( b, nth );
}
double tr_getRatio( double numerator, double denominator );
int* tr_parseNumberRange( const char * str, int str_len, int * setmeCount ) TR_GNUC_MALLOC;