Ignore:
Timestamp:
Feb 21, 2011, 1:40:19 AM (11 years ago)
Author:
jordan
Message:

(trunk libT) code cleanup: moving bitset functions to their own .c file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bitset.h

    r11709 r12003  
    3030tr_bitset;
    3131
    32 static inline void
    33 tr_bitsetConstructor( tr_bitset * b, size_t size )
    34 {
    35     tr_bitfieldConstruct( &b->bitfield, size );
    36 }
     32void tr_bitsetReserve( tr_bitset * b, size_t size );
     33void tr_bitsetConstructor( tr_bitset * b, size_t size );
     34void tr_bitsetDestructor( tr_bitset * b );
    3735
    38 static inline void
    39 tr_bitsetDestructor( tr_bitset * b )
    40 {
    41     tr_bitfieldDestruct( &b->bitfield );
    42 }
     36void tr_bitsetSetHaveAll( tr_bitset * b );
     37void tr_bitsetSetHaveNone( tr_bitset * b );
    4338
    44 void tr_bitsetReserve( tr_bitset * b, size_t size );
     39int  tr_bitsetAdd( tr_bitset * b, size_t i );
    4540
    46 static inline tr_bool
    47 tr_bitsetHasFast( const tr_bitset * b, const size_t nth )
    48 {
    49     if( b->haveAll ) return TRUE;
    50     if( b->haveNone ) return FALSE;
    51     if( nth >= b->bitfield.bitCount ) return FALSE;
    52     return tr_bitfieldHasFast( &b->bitfield, nth );
    53 }
     41/***
     42****
     43***/
    5444
    55 static inline tr_bool
    56 tr_bitsetHas( const tr_bitset * b, const size_t nth )
    57 {
    58     if( b->haveAll ) return TRUE;
    59     if( b->haveNone ) return FALSE;
    60     if( nth >= b->bitfield.bitCount ) return FALSE;
    61     return tr_bitfieldHas( &b->bitfield, nth );
    62 }
     45double tr_bitsetPercent( const tr_bitset * b );
    6346
    64 static inline void
    65 tr_bitsetOr( tr_bitfield * a, const tr_bitset * b )
    66 {
    67     if( b->haveAll )
    68         tr_bitfieldAddRange( a, 0, a->bitCount );
    69     else if( !b->haveNone )
    70         tr_bitfieldOr( a, &b->bitfield );
    71 }
     47tr_bool tr_bitsetHas( const tr_bitset * b, const size_t nth );
     48
     49void tr_bitsetOr( tr_bitfield * a, const tr_bitset * b );
    7250
    7351/* set 'a' to all the flags that were in 'a' but not 'b' */
    74 static inline void
    75 tr_bitsetDifference( tr_bitfield * a, const tr_bitset * b )
    76 {
    77     if( b->haveAll )
    78         tr_bitfieldClear( a );
    79     else if( !b->haveNone )
    80         tr_bitfieldDifference( a, &b->bitfield );
    81 }
    82 
    83 static inline double
    84 tr_bitsetPercent( const tr_bitset * b )
    85 {
    86     if( b->haveAll ) return 1.0;
    87     if( b->haveNone ) return 0.0;
    88     if( b->bitfield.bitCount == 0 ) return 0.0;
    89     return tr_bitfieldCountTrueBits( &b->bitfield ) / (double)b->bitfield.bitCount;
    90 }
    91 
    92 static inline void
    93 tr_bitsetSetHaveAll( tr_bitset * b )
    94 {
    95     b->haveAll = 1;
    96     b->haveNone = 0;
    97 }
    98 
    99 static inline void
    100 tr_bitsetSetHaveNone( tr_bitset * b )
    101 {
    102     b->haveAll = 0;
    103     b->haveNone = 1;
    104 }
    105 
    106 static inline int
    107 tr_bitsetAdd( tr_bitset * b, size_t i )
    108 {
    109     int ret = 0;
    110     if( !b->haveAll ) {
    111         b->haveNone = 0;
    112         tr_bitsetReserve( b, i+1 );
    113         ret = tr_bitfieldAdd( &b->bitfield, i );
    114     }
    115     return ret;
    116 }
     52void tr_bitsetDifference( tr_bitfield * a, const tr_bitset * b );
    11753
    11854#endif
Note: See TracChangeset for help on using the changeset viewer.