Changeset 2011 for trunk/lib


Ignore:
Timestamp:
Apr 9, 2012, 10:58:48 PM (7 years ago)
Author:
ksherdy
Message:

Modified block index from one-based to zero-based blk index for reverse scanner.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/bitblock_scan.hpp

    r1994 r2011  
    1818 */
    1919 
     20
    2021// Base
    2122template <class bitblock_t, class scanblock_t>
     
    5354
    5455        IDISA_ALWAYS_INLINE int32_t scan_to_next() {
    55                 while (this->blk < (sizeof(bitblock_t)/sizeof(scanblock_t))){
     56                while (this->blk < BLOCK_COUNT){
    5657                        if(has_bit(this->scan_blk)){
    5758                                this->pos = scan_forward_zeroes(this->scan_blk) + (this->blk * (sizeof(scanblock_t)*8));
     
    7475                this->blk = new_pos / (sizeof(scanblock_t)*8);
    7576                this->pos = new_pos % (sizeof(scanblock_t)*8);
    76                 this->scan_blk = ((scanblock_t *)this->strm)[this->blk];
     77                this->scan_blk = ((scanblock_t *)this->strm)[this->blk];
    7778                // clear bit at pos and all positions to the right.
    7879                scanblock_t marker = one_bit << this->pos;
     
    8182
    8283        IDISA_ALWAYS_INLINE bool is_done() {return (-1==this->pos);}
    83         IDISA_ALWAYS_INLINE void set_strm(const bitblock_t * strm) {this->strm = strm;}
     84        IDISA_ALWAYS_INLINE void set_strm(const bitblock_t * strm) {this->strm = strm;}
    8485        IDISA_ALWAYS_INLINE const bitblock_t * get_strm() const {return this->strm;}
    8586        IDISA_ALWAYS_INLINE int32_t get_pos() const {return this->pos;}
     87
     88        static const uint32_t BLOCK_COUNT = sizeof(bitblock_t)/sizeof(scanblock_t);
    8689
    8790};
     
    99102                this->strm = s;
    100103                this->pos = 0;
    101                 this->blk = BLOCK_COUNT;
     104                this->blk = BLOCK_COUNT-1;
    102105                this->scan_blk = *((scanblock_t *)s + (BLOCK_COUNT-1));
    103106        }
     
    105108        IDISA_ALWAYS_INLINE int32_t scan_to_next() {
    106109                const scanblock_t one_bit = 1;  /* ensure enough bits for shift: one_bit << this->pos */
    107                 while (this->blk > 0){
     110                while (this->blk >= 0){
    108111                        if(has_bit(this->scan_blk)){
    109                                 this->pos = (sizeof(scanblock_t)*8 - scan_backward_zeroes(this->scan_blk) -1) + ( (this->blk-1) * sizeof(scanblock_t)*8 );
     112                                this->pos = (sizeof(scanblock_t)*8 - scan_backward_zeroes(this->scan_blk) -1) + ( (this->blk) * sizeof(scanblock_t)*8 );
    110113                                this->scan_blk = this->scan_blk ^ (one_bit << this->pos); // clear leftmost bit
    111114                                return (this->pos);
     
    113116
    114117                        this->blk--;
    115                         this->scan_blk = *((scanblock_t *)this->strm + this->blk-1);
     118                        this->scan_blk = *((scanblock_t *)this->strm + this->blk);
    116119                };
    117120
     
    123126        IDISA_ALWAYS_INLINE void move_to(uint32_t new_pos) {
    124127                const scanblock_t one_bit = 1;
    125                 this->blk = new_pos / (sizeof(scanblock_t)*8);
     128                this->blk = (new_pos / (sizeof(scanblock_t)*8));
    126129                this->pos = new_pos % (sizeof(scanblock_t)*8);
    127                 this->scan_blk = ((scanblock_t *)this->strm)[this->blk];
     130                this->scan_blk = ((scanblock_t *)this->strm)[this->blk];
    128131                // clear bit at pos and all positions to the left.
    129132                scanblock_t marker = one_bit << this->pos;
    130                 this->scan_blk = this->scan_blk &(marker-1);
     133                this->scan_blk = this->scan_blk & (marker-1);
    131134        }
    132135
    133136        IDISA_ALWAYS_INLINE bool is_done() {return (-1==this->pos);}
    134         IDISA_ALWAYS_INLINE void set_strm(const bitblock_t * strm) {this->strm = strm;}
     137        IDISA_ALWAYS_INLINE void set_strm(const bitblock_t * strm) {this->strm = strm;}
    135138        IDISA_ALWAYS_INLINE const bitblock_t * get_strm() const {return this->strm;}
    136139        IDISA_ALWAYS_INLINE int32_t get_pos() const {return this->pos;}
Note: See TracChangeset for help on using the changeset viewer.