Ignore:
Timestamp:
Mar 30, 2011, 4:14:57 AM (11 years ago)
Author:
jordan
Message:

(trunk libT) handle situations where we don't know the bitfield's upper bound in advance. This comes up sometimes with magnet links.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bitfield.h

    r12251 r12262  
    2525{
    2626    uint8_t *  bits;
     27    size_t     alloc_count;
     28
    2729    size_t     bit_count;
    28     size_t     byte_count;
     30
    2931    size_t     true_count;
    3032
     
    7072***/
    7173
    72 bool   tr_bitfieldSetFromBitfield( tr_bitfield*, const tr_bitfield* );
     74void   tr_bitfieldSetFromBitfield( tr_bitfield*, const tr_bitfield* );
    7375
    74 bool   tr_bitfieldSetRaw( tr_bitfield*, const void * bits, size_t byte_count );
     76void   tr_bitfieldSetRaw( tr_bitfield*, const void * bits, size_t byte_count );
    7577
    7678void*  tr_bitfieldGetRaw( const tr_bitfield * b, size_t * byte_count );
     
    8284size_t  tr_bitfieldCountRange( const tr_bitfield*, size_t begin, size_t end );
    8385
    84 static inline size_t
    85 tr_bitfieldCountTrueBits( const tr_bitfield * b )
    86 {
    87     assert( b->true_count == tr_bitfieldCountRange( b, 0, b->bit_count ) );
    88     return b->true_count;
    89 }
     86size_t  tr_bitfieldCountTrueBits( const tr_bitfield * b );
    9087
    9188static inline bool
     
    125122tr_bitfieldHas( const tr_bitfield * b, size_t n )
    126123{
    127     return tr_bitfieldTestFast( b, n )
    128         && tr_bitfieldHasFast( b, n );
     124    if( tr_bitfieldHasAll( b ) ) return true;
     125    if( tr_bitfieldHasNone( b ) ) return false;
     126    if( n>>3u >= b->alloc_count ) return false;
     127    return ( b->bits[n>>3u] << ( n & 7u ) & 0x80 ) != 0;
    129128}
    130129
Note: See TracChangeset for help on using the changeset viewer.