Changeset 3164 for trunk/libtransmission/utils.c
- Timestamp:
- Sep 25, 2007, 5:43:39 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/utils.c
r3117 r3164 751 751 } 752 752 753 #define BIN(nth) ((nth>>3)) 754 #define BIT(nth) (1<<(7-(nth%8))) 753 int 754 tr_bitfieldHas( const tr_bitfield * bitfield, size_t nth ) 755 { 756 static const uint8_t ands[8] = { 128, 64, 32, 16, 8, 4, 2, 1 }; 757 return bitfield!=NULL && (bitfield->bits[nth>>3u] & ands[nth&7u] ); 758 } 755 759 756 760 void 757 761 tr_bitfieldAdd( tr_bitfield * bitfield, size_t nth ) 758 762 { 759 assert( bitfield != NULL ); 760 assert( BIN(nth) < bitfield->len ); 761 bitfield->bits[ BIN(nth) ] |= BIT(nth); 763 static const uint8_t ands[8] = { 128, 64, 32, 16, 8, 4, 2, 1 }; 764 bitfield->bits[nth>>3u] |= ands[nth&7u]; 762 765 } 763 766 … … 777 780 size_t nth ) 778 781 { 782 static const uint8_t rems[8] = { 127, 191, 223, 239, 247, 251, 253, 254 }; 783 779 784 if( bitfield != NULL ) 780 { 781 const size_t bin = BIN(nth); 782 assert( bin < bitfield->len ); 783 bitfield->bits[bin] &= ~BIT(nth); 784 } 785 bitfield->bits[nth>>3u] &= rems[nth&7u]; 785 786 } 786 787
Note: See TracChangeset
for help on using the changeset viewer.