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_identity_template.cpp

    r1666 r1684  
     1//#define USE_ITER
     2
    13#include "../symtab_global.h"
    24#include <pbgs_identity_symbol_table.h>
     
    2022int buffer_last;
    2123char * source;
    22 LineColTracker tracker;
    23 TagMatcher matcher;
    24 ErrorTracker error_tracker;
    2524BitBlock EOF_mask = simd<1>::constant<1>();
    2625
     
    3332PBGSIdentitySymbolTable pbgs_symbol_table;
    3433
    35 /* StreamScan & Post Process Declarations */
    36 //      static inline int StreamScanToFirst(ScanBlock * stream, int blk_count, int ProcessPos(int), int * error_pos_in_block)
    37 static inline int StreamScan(ScanBlock * stream, int blk_count, int ProcessPos(int), int * error_pos_in_block);
    38 
    3934@global
    4035
     
    4237static inline void s2p_do_final_block(BytePack U8[], Basis_bits & basis_bits, BitBlock EOF_mask);
    4338static inline void postprocess_do_block(Dictionary& dictionary, Hash_data hash_data);
     39
     40void do_process(FILE *infile, FILE *outfile);
     41
     42static inline void validate_block_length_grouping(BitBlockForwardIterator & start, int block_base);
     43
    4444static inline int ElemStart_grouping(int start_pos, int L) ;
    4545static inline int StreamScanLengthGrouping(ScanBlock * stream, int blk_count);
    4646static inline int ScanForwardPos(BitBlock * block, int pos);
    4747static inline int compute_hash_value (int lgth, int start);
    48 
    49 void do_process(FILE *infile, FILE *outfile);
    5048
    5149int main(int argc, char * argv[]) {
     
    129127}
    130128
    131 /* StreamScan & Post Process Definitions */
    132 static inline int StreamScan(ScanBlock * stream, int blk_count, int ProcessPos(int), int * error_pos_in_block) {
    133 
    134         int blk;
    135         int block_pos = 0;
    136         int pos;
    137 
    138         for (blk = 0; blk < blk_count; blk++) {
    139                 ScanBlock s = stream[blk];
    140                 while(s) {
    141                         pos = (cfzl(s) + block_pos);
    142                         int code = (ProcessPos(pos));
    143                         if (code) {
    144                                 *error_pos_in_block = pos;
    145                                 return code; // error code
    146                         }
    147                         s = s & (s-1);  // clear rightmost bit.
    148                 }
    149                 block_pos += 8 * sizeof(ScanBlock);
    150         }
    151         return 0;
    152 }
    153 
    154 
    155129static inline int compute_hash_value (int lgth, int start)
    156130{
     
    161135
    162136static inline int ElemStart_grouping(int start_pos, int L) {
    163     int start = block_base + start_pos;
    164     int end = start + L;
    165     int hashvalue = compute_hash_value(L, start - block_base);
     137    int hashvalue = compute_hash_value(L, start_pos - block_base);
    166138    int gid = 0;
    167139
     
    169141    {
    170142    case 1:
    171         gid = pbgs_symbol_table.Lookup_or_Insert_Name<1>(source + start, hashvalue);
    172         break;
     143        gid = pbgs_symbol_table.Lookup_or_Insert_Name<1>(source + start_pos, hashvalue);
     144        break;
    173145    case 2:
    174         gid = pbgs_symbol_table.Lookup_or_Insert_Name<2>(source + start, hashvalue);
    175         break;
     146        gid = pbgs_symbol_table.Lookup_or_Insert_Name<2>(source + start_pos, hashvalue);
     147        break;
    176148    case 3:
    177         gid = pbgs_symbol_table.Lookup_or_Insert_Name<3>(source + start, hashvalue);
    178         break;
     149        gid = pbgs_symbol_table.Lookup_or_Insert_Name<3>(source + start_pos, hashvalue);
     150        break;
    179151    case 4:
    180         gid = pbgs_symbol_table.Lookup_or_Insert_Name<4>(source + start, hashvalue);
    181         break;
     152        gid = pbgs_symbol_table.Lookup_or_Insert_Name<4>(source + start_pos, hashvalue);
     153        break;
    182154    case 5:
    183         gid = pbgs_symbol_table.Lookup_or_Insert_Name<5>(source + start, hashvalue);
    184         break;
     155        gid = pbgs_symbol_table.Lookup_or_Insert_Name<5>(source + start_pos, hashvalue);
     156        break;
    185157    case 6:
    186         gid = pbgs_symbol_table.Lookup_or_Insert_Name<6>(source + start, hashvalue);
    187         break;
     158        gid = pbgs_symbol_table.Lookup_or_Insert_Name<6>(source + start_pos, hashvalue);
     159        break;
    188160    case 7:
    189         gid = pbgs_symbol_table.Lookup_or_Insert_Name<7>(source + start, hashvalue);
    190         break;
     161        gid = pbgs_symbol_table.Lookup_or_Insert_Name<7>(source + start_pos, hashvalue);
     162        break;
    191163    case 8:
    192         gid = pbgs_symbol_table.Lookup_or_Insert_Name<8>(source + start, hashvalue);
    193         break;
     164        gid = pbgs_symbol_table.Lookup_or_Insert_Name<8>(source + start_pos, hashvalue);
     165        break;
    194166    case 9:
    195         gid = pbgs_symbol_table.Lookup_or_Insert_Name<9>(source + start, hashvalue);
    196         break;
     167        gid = pbgs_symbol_table.Lookup_or_Insert_Name<9>(source + start_pos, hashvalue);
     168        break;
    197169    case 10:
    198         gid = pbgs_symbol_table.Lookup_or_Insert_Name<10>(source + start, hashvalue);
    199         break;
     170        gid = pbgs_symbol_table.Lookup_or_Insert_Name<10>(source + start_pos, hashvalue);
     171        break;
    200172    case 11:
    201         gid = pbgs_symbol_table.Lookup_or_Insert_Name<11>(source + start, hashvalue);
    202         break;
     173        gid = pbgs_symbol_table.Lookup_or_Insert_Name<11>(source + start_pos, hashvalue);
     174        break;
    203175    case 12:
    204         gid = pbgs_symbol_table.Lookup_or_Insert_Name<12>(source + start, hashvalue);
    205         break;
     176        gid = pbgs_symbol_table.Lookup_or_Insert_Name<12>(source + start_pos, hashvalue);
     177        break;
    206178    case 13:
    207         gid = pbgs_symbol_table.Lookup_or_Insert_Name<13>(source + start, hashvalue);
    208         break;
     179        gid = pbgs_symbol_table.Lookup_or_Insert_Name<13>(source + start_pos, hashvalue);
     180        break;
    209181    case 14:
    210         gid = pbgs_symbol_table.Lookup_or_Insert_Name<14>(source + start, hashvalue);
    211         break;
     182        gid = pbgs_symbol_table.Lookup_or_Insert_Name<14>(source + start_pos, hashvalue);
     183        break;
    212184    case 15:
    213         gid = pbgs_symbol_table.Lookup_or_Insert_Name<15>(source + start, hashvalue);
    214         break;
     185        gid = pbgs_symbol_table.Lookup_or_Insert_Name<15>(source + start_pos, hashvalue);
     186        break;
    215187    case 16:
    216         gid = pbgs_symbol_table.Lookup_or_Insert_Name<16>(source + start, hashvalue);
    217         break;
     188        gid = pbgs_symbol_table.Lookup_or_Insert_Name<16>(source + start_pos, hashvalue);
     189        break;
    218190    default:
    219         gid = pbgs_symbol_table.Lookup_or_Insert_Name(source + start, hashvalue, L);
    220         break;
     191        gid = pbgs_symbol_table.Lookup_or_Insert_Name(source + start_pos, hashvalue, L);
     192        break;
    221193    }
    222194
    223195    gids.push_back(gid);
    224196#if DEBUG
     197    int end = start_pos + L;
    225198    char* symbol = new char[L+1];
    226     strncpy ( symbol, source + start, L );
     199    strncpy ( symbol, source + start_pos, L );
    227200    symbol[L] ='\0';
    228     printf ("%s | L: %i | start: %i[%i] | end: %i[%i] | gid: %i | hashvalue: %i | symbol: %s\n", __FUNCTION__, L, start, start-buffer_base, end, end-buffer_base, gid, hashvalue, symbol );
     201    printf ("%s | L: %i | start: %i[%i] | end: %i[%i] | gid: %i | hashvalue: %i | symbol: %s\n", __FUNCTION__, L, start_pos, start_pos-buffer_base, end, end-buffer_base, gid, hashvalue, symbol );
    229202    delete symbol; symbol = 0;
    230203#endif
     
    232205}
    233206
    234 static inline int StreamScanLengthGrouping(ScanBlock * stream, int blk_count) {
    235     int blk;
    236     int block_pos = 0;
    237     for (blk = 0; blk < blk_count; blk++) {
    238         ScanBlock s = stream[blk];
    239         while(s) {
    240             int start_pos = cfzl(s) + block_pos;
    241             int end_pos = ScanForwardPos (&elem_ends, start_pos);
    242             if (end_pos)
    243             {
    244                 ElemStart_grouping(start_pos, end_pos - start_pos);
    245             }
    246             s = s & (s-1);  // clear rightmost bit.
    247         }
    248         block_pos += 8 * sizeof(ScanBlock);
    249     }
    250     return 0;
     207inline void validate_block_length_grouping(BitBlockForwardIterator & start, int block_base) {
     208
     209    BitBlockForwardIterator end;
     210    int start_pos, end_pos, lgth;
     211
     212    while(start != end) {
     213        start_pos = *start;
     214        end_pos = ScanForwardPos (&elem_ends, start_pos);
     215        if (end_pos)
     216        {
     217            lgth = end_pos - start_pos;
     218            start_pos += block_base;
     219            ElemStart_grouping(start_pos, lgth);
     220        }
     221        start++;
     222    }
    251223}
    252224
     
    258230    if (block_boundary_case)
    259231    {
    260         int end_pos = count_forward_zeroes(elem_ends);
    261         ElemStart_grouping (last_elem_start, end_pos-last_elem_start);
    262         block_boundary_case = false;
     232        int end_pos = count_forward_zeroes(elem_ends);
     233        ElemStart_grouping (last_elem_start + block_base, end_pos-last_elem_start);
     234        block_boundary_case = false;
    263235    }
    264236
    265237    if ( bitblock_has_bit(dictionary.Word_starts) )
    266238    {
    267         StreamScanLengthGrouping((ScanBlock *) &dictionary.Word_starts, sizeof(BitBlock)/sizeof(ScanBlock));
     239        BitBlockForwardIterator iter_length_grouping(&dictionary.Word_starts);
     240        validate_block_length_grouping(iter_length_grouping, block_base);
    268241    }
    269242
Note: See TracChangeset for help on using the changeset viewer.