Changeset 4045 for trunk/lib


Ignore:
Timestamp:
Aug 19, 2014, 2:23:01 PM (5 years ago)
Author:
ksherdy
Message:

Added a scanner to scan a stream of bitblocks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/bitblock_iterator.hpp

    r4032 r4045  
    183183};
    184184
     185template <class bitblock_t, class scanblock_t>
     186class BitBlockStreamScanner {
     187
     188public:
     189
     190BitBlockStreamScanner():  bitblock_ary(NULL),
     191                          bitblock_cnt(-1),
     192                          bitblock_idx(-1),
     193                          scanblock_idx(-1)
     194{
     195  current._bitblock = simd<1>::constant<0>();
     196}
     197
     198void init(bitblock_t *s, uint32_t size) {
     199  bitblock_ary           = s;
     200  bitblock_cnt           = size;
     201  bitblock_idx           = 0;
     202  scanblock_idx          = 0;
     203  current._bitblock      = bitblock_ary[0];
     204}
     205
     206int scan_to_next() {
     207
     208  while(1) {
     209   
     210    for(scanblock_idx; scanblock_idx < (sizeof(bitblock_t)/sizeof(scanblock_t)); scanblock_idx++) {
     211      scanblock_t scan_item = current._scanblock[scanblock_idx];
     212      if(scan_item != 0) {
     213        int bit_pos = scan_forward_zeroes(scan_item);
     214        scan_item = scan_item & (scan_item - 1);
     215        current._scanblock[scanblock_idx] = scan_item;
     216        return (bitblock_idx * (sizeof(bitblock_t)*8)) + (scanblock_idx * sizeof(scanblock_t)*8) + bit_pos;
     217      }
     218    }
     219   
     220    scanblock_idx = 0;
     221    bitblock_idx++;
     222
     223    if(bitblock_idx >= bitblock_cnt) {
     224      return -1;
     225    }
     226    current._bitblock = bitblock_ary[bitblock_idx];
     227  }
     228
     229}
     230private:
     231
     232  union {  bitblock_t   _bitblock;
     233           scanblock_t  _scanblock[sizeof(bitblock_t)/sizeof(scanblock_t)];} current;
     234
     235  bitblock_t * bitblock_ary;
     236  uint32_t bitblock_cnt;
     237  uint32_t bitblock_idx;
     238  uint32_t scanblock_idx; 
     239 
     240};
     241
     242
    185243/*=============================================================================
    186244
Note: See TracChangeset for help on using the changeset viewer.