655
656 BitMap::idx_t BitMap::count_one_bits() const {
657 init_pop_count_table(); // If necessary.
658 idx_t sum = 0;
659 typedef unsigned char uchar;
660 for (idx_t i = 0; i < size_in_words(); i++) {
661 bm_word_t w = map()[i];
662 for (size_t j = 0; j < sizeof(bm_word_t); j++) {
663 sum += num_set_bits_from_table(uchar(w & 255));
664 w >>= 8;
665 }
666 }
667 return sum;
668 }
669
670 void BitMap::print_on_error(outputStream* st, const char* prefix) const {
671 st->print_cr("%s[" PTR_FORMAT ", " PTR_FORMAT ")",
672 prefix, p2i(map()), p2i((char*)map() + (size() >> LogBitsPerByte)));
673 }
674
675 #ifndef PRODUCT
676
677 void BitMap::print_on(outputStream* st) const {
678 tty->print("Bitmap(" SIZE_FORMAT "):", size());
679 for (idx_t index = 0; index < size(); index++) {
680 tty->print("%c", at(index) ? '1' : '0');
681 }
682 tty->cr();
683 }
684
685 #endif
|
655
656 BitMap::idx_t BitMap::count_one_bits() const {
657 init_pop_count_table(); // If necessary.
658 idx_t sum = 0;
659 typedef unsigned char uchar;
660 for (idx_t i = 0; i < size_in_words(); i++) {
661 bm_word_t w = map()[i];
662 for (size_t j = 0; j < sizeof(bm_word_t); j++) {
663 sum += num_set_bits_from_table(uchar(w & 255));
664 w >>= 8;
665 }
666 }
667 return sum;
668 }
669
670 void BitMap::print_on_error(outputStream* st, const char* prefix) const {
671 st->print_cr("%s[" PTR_FORMAT ", " PTR_FORMAT ")",
672 prefix, p2i(map()), p2i((char*)map() + (size() >> LogBitsPerByte)));
673 }
674
675 void BitMap::copy_from(BitMap& other, idx_t start_bit, idx_t end_bit) {
676 // Copy prefix.
677 while (bit_in_word(start_bit) != 0 && start_bit < end_bit) {
678 tty->print_cr("prefix: "SIZE_FORMAT, start_bit);
679 at_put(start_bit, other.at(start_bit));
680 start_bit++;
681 }
682 // Copy suffix.
683 while (bit_in_word(end_bit) != 0 && end_bit > start_bit) {
684 end_bit--;
685 at_put(end_bit, other.at(end_bit));
686 tty->print_cr("suffix: "SIZE_FORMAT, end_bit);
687 }
688
689 assert(bit_in_word(start_bit) == 0, "can only handle aligned copy for now, bit: "SIZE_FORMAT, bit_in_word(start_bit));
690 assert(bit_in_word(end_bit) == 0, "can only handle aligned copy for now, bit: "SIZE_FORMAT, bit_in_word(end_bit));
691
692 idx_t start_word = word_index(start_bit);
693 idx_t end_word = word_index(end_bit);
694 Copy::conjoint_jbytes(other._map + start_word, _map + start_word, (end_word - start_word) * sizeof(bm_word_t));
695 }
696
697 #ifndef PRODUCT
698
699 void BitMap::print_on(outputStream* st) const {
700 tty->print("Bitmap(" SIZE_FORMAT "):", size());
701 for (idx_t index = 0; index < size(); index++) {
702 tty->print("%c", at(index) ? '1' : '0');
703 }
704 tty->cr();
705 }
706
707 #endif
|