Ignore:
Timestamp:
Oct 12, 2006, 11:34:20 PM (16 years ago)
Author:
livings124
Message:

Initial attempt at against the completeness of a specific piece.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/completion.c

    r261 r994  
    201201}
    202202
     203uint8_t tr_cpPercentBlocksInPiece( tr_completion_t * cp, int piece )
     204{
     205    tr_torrent_t * tor = cp->tor;
     206    int i;
     207    int blockCount, startBlock, endBlock;
     208    int complete;
     209    uint8_t * bitfield;
     210   
     211    blockCount  = tr_pieceCountBlocks( piece );
     212    startBlock  = tr_pieceStartBlock( piece );
     213    endBlock    = startBlock + blockCount;
     214    complete    = 0;
     215   
     216    bitfield = cp->blockBitfield;
     217
     218    for( i = startBlock; i < endBlock; i++ )
     219        if( tr_bitfieldHas( bitfield, i ) )
     220            complete++;
     221   
     222    return (complete * 100.0) / blockCount;
     223}
     224
    203225int tr_cpMissingBlockInPiece( tr_completion_t * cp, int piece )
    204226{
     
    211233
    212234    for( i = start; i < end; i++ )
    213     {
    214         if( tr_cpBlockIsComplete( cp, i ) || cp->blockDownloaders[i] )
    215         {
    216             continue;
    217         }
    218         return i;
    219     }
     235        if( !tr_cpBlockIsComplete( cp, i ) && !cp->blockDownloaders[i] )
     236            return i;
    220237
    221238    return -1;
Note: See TracChangeset for help on using the changeset viewer.