Example #1
0
 /** Resizes the current bitset to hold n bits.
 Existing bits will not be changed. If the array size is increased,
 the value of the new bits are undefined.
 
 \Warning When shirnking, the current implementation may still leave the
 "deleted" bits in place which will mess up the popcount. 
 */
 inline void resize(size_t n) {
   len = n;
   //need len bits
   arrlen = (n / (sizeof(size_t) * 8)) + (n % (sizeof(size_t) * 8) > 0);
   array = (size_t*)realloc(array, sizeof(size_t) * arrlen);
   fix_trailing_bits();
 }
Example #2
0
 /** Resizes the current bitset to hold n bits.
 Existing bits will not be changed. If the array size is increased,
 the value of the new bits are undefined.
 
 \Warning When shirnking, the current implementation may still leave the
 "deleted" bits in place which will mess up the popcount. 
 */
 inline void resize(size_t n) {
   len = n;
   //need len bits
   size_t prev_arrlen = arrlen;
   arrlen = (n / (sizeof(size_t) * 8)) + (n % (sizeof(size_t) * 8) > 0);
   array = (size_t*)realloc(array, sizeof(size_t) * arrlen);
   // this zeros the remainder of the block after the last bit
   fix_trailing_bits();
   // if we grew, we need to zero all new blocks
   if (arrlen > prev_arrlen) {
     // Use  this version;  may special  case to  memset,  which is
     // faster than loop.
     std::fill(&array[prev_arrlen], &array[arrlen], 0);
   }
 }
Example #3
0
 void invert() {
   for (size_t i = 0; i < arrlen; ++i) {
     array[i] = ~array[i];
   }
   fix_trailing_bits();
 }
Example #4
0
 /// Sets all bits to 1
 inline void fill() {
   for (size_t i = 0;i < arrlen; ++i) array[i] = (size_t) - 1;
   fix_trailing_bits();
 }