Ignore:
Timestamp:
Nov 15, 2011, 1:19:24 AM (8 years ago)
Author:
vla24
Message:

SymbolTable?: updated templates implementation to use BitBlockForwardIterator?. Fixed block boundary case handling for div2 grouping strategy.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/SymbolTable/dictionary_pbgs_identity_template.cpp

    r1666 r1684  
    3232PBGSIdentitySymbolTable pbgs_symbol_table;
    3333
    34 /* StreamScan & Post Process Declarations */
    35 //      static inline int StreamScanToFirst(ScanBlock * stream, int blk_count, int ProcessPos(int), int * error_pos_in_block)
    36 static inline int StreamScan(ScanBlock * stream, int blk_count, int ProcessPos(int), int * error_pos_in_block);
    37 
    3834@global
    3935
     
    4137static inline void s2p_do_final_block(BytePack U8[], Basis_bits & basis_bits, BitBlock EOF_mask);
    4238static inline void postprocess_do_block(Dictionary& dictionary, Hash_data hash_data);
     39
     40void do_process(FILE *infile, FILE *outfile);
     41
     42template <int L> static inline void validate_block_length_grouping(BitBlockForwardIterator & start, int block_base);
     43
    4344static inline int ScanBackwardPos(BitBlock * block, int pos);
    4445static inline int compute_hash_value (int lgth, int start);
    4546template <int L> static inline int ElemEnd_grouping(int pos);
    46 template <int L> static inline int StreamScanLengthGrouping(ScanBlock * stream, int blk_count);
    47 
    48 void do_process(FILE *infile, FILE *outfile);
    4947
    5048int main(int argc, char * argv[]) {
     
    127125}
    128126
    129 /* StreamScan & Post Process Definitions */
    130 static inline int StreamScan(ScanBlock * stream, int blk_count, int ProcessPos(int), int * error_pos_in_block) {
    131 
    132         int blk;
    133         int block_pos = 0;
    134         int pos;
    135 
    136         for (blk = 0; blk < blk_count; blk++) {
    137                 ScanBlock s = stream[blk];
    138                 while(s) {
    139                         pos = (cfzl(s) + block_pos);
    140                         int code = (ProcessPos(pos));
    141                         if (code) {
    142                                 *error_pos_in_block = pos;
    143                                 return code; // error code
    144                         }
    145                         s = s & (s-1);  // clear rightmost bit.
    146                 }
    147                 block_pos += 8 * sizeof(ScanBlock);
    148         }
    149         return 0;
    150 }
    151 
    152127static inline int compute_hash_value (int lgth, int start)
    153128{
     
    158133
    159134template <int L>
    160 static inline int ElemEnd_grouping(int pos) {
    161     int end = block_base + pos;
     135static inline int ElemEnd_grouping(int end) {
    162136    int start = end - L;
    163137    int hashvalue = compute_hash_value(L, start - block_base);
     
    175149
    176150template<>
    177 inline int ElemEnd_grouping<17>(int pos) {
    178     int end = block_base + pos;
    179     int start = ScanBackwardPos (&elem_starts, pos) + block_base;
     151inline int ElemEnd_grouping<17>(int end) {
     152    int start = ScanBackwardPos (&elem_starts, end - block_base) + block_base;
    180153    int lgth = end - start;
    181154    int hashvalue = compute_hash_value(lgth, start - block_base);
     
    188161//    else
    189162    {
    190         gid = pbgs_symbol_table.Lookup_or_Insert_Name(source + start, hashvalue, lgth);
     163        gid = pbgs_symbol_table.Lookup_or_Insert_Name(source + start, hashvalue, lgth);
    191164    }
    192165    gids.push_back(gid);
     
    201174
    202175template <int L>
    203 static inline int StreamScanLengthGrouping(ScanBlock * stream, int blk_count) {
    204     int blk;
    205     int block_pos = 0;
    206     for (blk = 0; blk < blk_count; blk++) {
    207         ScanBlock s = stream[blk];
    208         while(s) {
    209             int end_pos = cfzl(s) + block_pos;
    210             ElemEnd_grouping<L>(end_pos);
    211             s = s & (s-1);  // clear rightmost bit.
    212         }
    213         block_pos += 8 * sizeof(ScanBlock);
    214     }
    215     return 0;
     176static inline void validate_block_length_grouping(BitBlockForwardIterator & start, int block_base) {
     177
     178    BitBlockForwardIterator end;
     179    int block_pos;
     180
     181    while(start != end) {
     182        block_pos = block_base + *start;
     183        ElemEnd_grouping<L>(block_pos);
     184        start++;
     185    }
    216186}
    217187
     
    223193    if ( bitblock_has_bit(dictionary.Word_ends_1) )
    224194    {
    225         StreamScanLengthGrouping<1>((ScanBlock *) &dictionary.Word_ends_1, sizeof(BitBlock)/sizeof(ScanBlock));
     195        BitBlockForwardIterator iter_length_grouping_1(&dictionary.Word_ends_1);
     196        validate_block_length_grouping<1>(iter_length_grouping_1, block_base);
    226197    }
    227198
    228199    if ( bitblock_has_bit(dictionary.Word_ends_2) )
    229200    {
    230         StreamScanLengthGrouping<2>((ScanBlock *) &dictionary.Word_ends_2, sizeof(BitBlock)/sizeof(ScanBlock));
     201        BitBlockForwardIterator iter_length_grouping_2(&dictionary.Word_ends_2);
     202        validate_block_length_grouping<2>(iter_length_grouping_2, block_base);
    231203    }
    232204
    233205    if ( bitblock_has_bit(dictionary.Word_ends_3) )
    234206    {
    235         StreamScanLengthGrouping<3>((ScanBlock *) &dictionary.Word_ends_3, sizeof(BitBlock)/sizeof(ScanBlock));
     207        BitBlockForwardIterator iter_length_grouping_3(&dictionary.Word_ends_3);
     208        validate_block_length_grouping<3>(iter_length_grouping_3, block_base);
    236209    }
    237210
    238211    if ( bitblock_has_bit(dictionary.Word_ends_4) )
    239212    {
    240         StreamScanLengthGrouping<4>((ScanBlock *) &dictionary.Word_ends_4, sizeof(BitBlock)/sizeof(ScanBlock));
     213        BitBlockForwardIterator iter_length_grouping_4(&dictionary.Word_ends_4);
     214        validate_block_length_grouping<4>(iter_length_grouping_4, block_base);
    241215    }
    242216
    243217    if ( bitblock_has_bit(dictionary.Word_ends_5) )
    244218    {
    245         StreamScanLengthGrouping<5>((ScanBlock *) &dictionary.Word_ends_5, sizeof(BitBlock)/sizeof(ScanBlock));
     219        BitBlockForwardIterator iter_length_grouping_5(&dictionary.Word_ends_5);
     220        validate_block_length_grouping<5>(iter_length_grouping_5, block_base);
    246221    }
    247222
    248223    if ( bitblock_has_bit(dictionary.Word_ends_6) )
    249224    {
    250         StreamScanLengthGrouping<6>((ScanBlock *) &dictionary.Word_ends_6, sizeof(BitBlock)/sizeof(ScanBlock));
     225        BitBlockForwardIterator iter_length_grouping_6(&dictionary.Word_ends_6);
     226        validate_block_length_grouping<6>(iter_length_grouping_6, block_base);
    251227    }
    252228
    253229    if ( bitblock_has_bit(dictionary.Word_ends_7) )
    254230    {
    255         StreamScanLengthGrouping<7>((ScanBlock *) &dictionary.Word_ends_7, sizeof(BitBlock)/sizeof(ScanBlock));
     231        BitBlockForwardIterator iter_length_grouping_7(&dictionary.Word_ends_7);
     232        validate_block_length_grouping<7>(iter_length_grouping_7, block_base);
    256233    }
    257234
    258235    if ( bitblock_has_bit(dictionary.Word_ends_8) )
    259236    {
    260         StreamScanLengthGrouping<8>((ScanBlock *) &dictionary.Word_ends_8, sizeof(BitBlock)/sizeof(ScanBlock));
     237        BitBlockForwardIterator iter_length_grouping_8(&dictionary.Word_ends_8);
     238        validate_block_length_grouping<8>(iter_length_grouping_8, block_base);
    261239    }
    262240
    263241    if ( bitblock_has_bit(dictionary.Word_ends_9) )
    264242    {
    265         StreamScanLengthGrouping<9>((ScanBlock *) &dictionary.Word_ends_9, sizeof(BitBlock)/sizeof(ScanBlock));
     243        BitBlockForwardIterator iter_length_grouping_9(&dictionary.Word_ends_9);
     244        validate_block_length_grouping<9>(iter_length_grouping_9, block_base);
    266245    }
    267246
    268247    if ( bitblock_has_bit(dictionary.Word_ends_10) )
    269248    {
    270         StreamScanLengthGrouping<10>((ScanBlock *) &dictionary.Word_ends_10, sizeof(BitBlock)/sizeof(ScanBlock));
     249        BitBlockForwardIterator iter_length_grouping_10(&dictionary.Word_ends_10);
     250        validate_block_length_grouping<10>(iter_length_grouping_10, block_base);
    271251    }
    272252
    273253    if ( bitblock_has_bit(dictionary.Word_ends_11) )
    274254    {
    275         StreamScanLengthGrouping<11>((ScanBlock *) &dictionary.Word_ends_11, sizeof(BitBlock)/sizeof(ScanBlock));
     255        BitBlockForwardIterator iter_length_grouping_11(&dictionary.Word_ends_11);
     256        validate_block_length_grouping<11>(iter_length_grouping_11, block_base);
    276257    }
    277258
    278259    if ( bitblock_has_bit(dictionary.Word_ends_12) )
    279260    {
    280         StreamScanLengthGrouping<12>((ScanBlock *) &dictionary.Word_ends_12, sizeof(BitBlock)/sizeof(ScanBlock));
     261        BitBlockForwardIterator iter_length_grouping_12(&dictionary.Word_ends_12);
     262        validate_block_length_grouping<12>(iter_length_grouping_12, block_base);
    281263    }
    282264
    283265    if ( bitblock_has_bit(dictionary.Word_ends_13) )
    284266    {
    285         StreamScanLengthGrouping<13>((ScanBlock *) &dictionary.Word_ends_13, sizeof(BitBlock)/sizeof(ScanBlock));
     267        BitBlockForwardIterator iter_length_grouping_13(&dictionary.Word_ends_13);
     268        validate_block_length_grouping<13>(iter_length_grouping_13, block_base);
    286269    }
    287270
    288271    if ( bitblock_has_bit(dictionary.Word_ends_14) )
    289272    {
    290         StreamScanLengthGrouping<14>((ScanBlock *) &dictionary.Word_ends_14, sizeof(BitBlock)/sizeof(ScanBlock));
     273        BitBlockForwardIterator iter_length_grouping_14(&dictionary.Word_ends_14);
     274        validate_block_length_grouping<14>(iter_length_grouping_14, block_base);
    291275    }
    292276
    293277    if ( bitblock_has_bit(dictionary.Word_ends_15) )
    294278    {
    295         StreamScanLengthGrouping<15>((ScanBlock *) &dictionary.Word_ends_15, sizeof(BitBlock)/sizeof(ScanBlock));
     279        BitBlockForwardIterator iter_length_grouping_15(&dictionary.Word_ends_15);
     280        validate_block_length_grouping<15>(iter_length_grouping_15, block_base);
    296281    }
    297282
    298283    if ( bitblock_has_bit(dictionary.Word_ends_16) )
    299284    {
    300         StreamScanLengthGrouping<16>((ScanBlock *) &dictionary.Word_ends_16, sizeof(BitBlock)/sizeof(ScanBlock));
     285        BitBlockForwardIterator iter_length_grouping_16(&dictionary.Word_ends_16);
     286        validate_block_length_grouping<16>(iter_length_grouping_16, block_base);
    301287    }
    302288
    303289    if ( bitblock_has_bit(dictionary.Word_ends_17_and_longer) )
    304290    {
    305         StreamScanLengthGrouping<17>((ScanBlock *) &dictionary.Word_ends_17_and_longer, sizeof(BitBlock)/sizeof(ScanBlock));
     291        BitBlockForwardIterator iter_length_grouping_remaining(&dictionary.Word_ends_17_and_longer);
     292        validate_block_length_grouping<17>(iter_length_grouping_remaining, block_base);
    306293    }
    307294
Note: See TracChangeset for help on using the changeset viewer.