[1893] | 1 | /* |
---|
| 2 | * id_symbol_table.hpp - Identity Symbol Table Pablo Template |
---|
| 3 | * Created on: 18-December-2011 |
---|
| 4 | * Author: Ken Herdy |
---|
| 5 | * |
---|
| 6 | * BitBlock type arguments must adhere to the 'full-block invariant' |
---|
| 7 | * and mask partial block with null bytes. |
---|
| 8 | * |
---|
| 9 | * Number of length groups MUST coincide with the |
---|
| 10 | * number compiler generated length groups. |
---|
| 11 | * |
---|
| 12 | */ |
---|
| 13 | #ifndef ID_SYMBOL_TABLE_TEMPLATE_HPP |
---|
| 14 | #define ID_SYMBOL_TABLE_TEMPLATE_HPP |
---|
| 15 | |
---|
| 16 | #include "symbol_table.hpp" |
---|
| 17 | #include "hash_table.hpp" |
---|
| 18 | #include "../lib/carryQ.hpp" |
---|
| 19 | #include "../lib/bitblock_iterator.hpp" |
---|
| 20 | #include "../lib/bitblock_scan.hpp" |
---|
| 21 | |
---|
[1929] | 22 | /* NOTE: C++ template code and Pablo generated length groups must coincide. */ |
---|
[1893] | 23 | static const uint32_t LGTH_GROUPS = 17; |
---|
| 24 | |
---|
[1929] | 25 | template<class HASH_TABLE> |
---|
| 26 | IDISA_ALWAYS_INLINE void do_block(HASH_TABLE h_table, uint32_t lgth, uint8_t * raw_buffer, BitBlock * ends, uint8_t * h0, uint8_t * h1) { |
---|
[1893] | 27 | |
---|
[1929] | 28 | int32_t spos, epos; |
---|
| 29 | ForwardScanner<BitBlock, scanword_t> scanner(ends); |
---|
| 30 | scanner.scan_to_next(); |
---|
| 31 | epos = scanner.get_pos(); |
---|
[1893] | 32 | |
---|
[1929] | 33 | // if(first segment block) { |
---|
| 34 | // Buffer management ensures contiguous memory. |
---|
| 35 | // } |
---|
[1893] | 36 | |
---|
[1929] | 37 | uint32_t bucket; |
---|
[1893] | 38 | |
---|
[1929] | 39 | while(epos != -1) { |
---|
| 40 | spos = (epos - lgth); |
---|
| 41 | bucket = h_table.get_bucket(h0, h1, spos, lgth); |
---|
[1893] | 42 | |
---|
[1929] | 43 | cout << "Value:" << string((char *)&(raw_buffer[spos]), lgth) << endl; |
---|
| 44 | cout << "Hash:" << bucket << endl; |
---|
| 45 | cout << "GID:" << h_table.lookup_or_insert(bucket,&raw_buffer[spos],lgth) << endl; |
---|
[1893] | 46 | |
---|
[1929] | 47 | epos = scanner.scan_to_next(); |
---|
| 48 | } |
---|
[1893] | 49 | |
---|
[1929] | 50 | } |
---|
[1893] | 51 | |
---|
| 52 | template<class ALLOCATOR> |
---|
| 53 | class id_symbol_table: public symbol_table { |
---|
| 54 | public: |
---|
[1929] | 55 | id_symbol_table():h4(4096) { |
---|
[1893] | 56 | |
---|
[1929] | 57 | // for(int lgth=1;lgth<LGTH_GROUPS;lgth++) { |
---|
| 58 | // zero_partial(partial_offset[lgth]); |
---|
| 59 | // //partial_offset[lgth] =0; |
---|
| 60 | // } |
---|
[1893] | 61 | |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | ~id_symbol_table() {} |
---|
| 65 | |
---|
| 66 | // Groups & groups |
---|
[1929] | 67 | void resolve(uint8_t raw_buffer [], Markers markers [], Groups groups [], Hash hash [], uint32_t blocks, AoS_symbol symbol_ary [], const uint32_t symbols) { |
---|
[1893] | 68 | |
---|
[1929] | 69 | // segment_size = 1; |
---|
[1893] | 70 | |
---|
[1929] | 71 | for(uint32_t k=0;k<blocks;k++) { |
---|
[1893] | 72 | |
---|
[1929] | 73 | /* TODO - Migrate 'do_segment to 'hash table' class. */ |
---|
| 74 | // do_segment<hash_table<identity_strategy_t<uint8_t,1>, hash_strategy_t<1>, ALLOCATOR> >(h1, groups.starts, groups.ends_1, segment_size); |
---|
| 75 | // do_segment<hash_table<identity_strategy_t<uint16_t,2>, hash_strategy_t<2>, ALLOCATOR> >(h2, groups.starts, groups.ends_2, segment_size); |
---|
| 76 | // do_segment<hash_table<identity_strategy_t<uint16_t,3>, hash_strategy_t<3>, ALLOCATOR> >(h3, groups.starts, groups.ends_3, segment_size); |
---|
| 77 | // do_segment<hash_table<identity_strategy_t<uint32_t,4>, hash_strategy_t<4>, ALLOCATOR> >(h4, groups.starts, groups.ends_4, segment_size); |
---|
[1893] | 78 | |
---|
[1929] | 79 | do_block<hash_table <identity_strategy_t<uint32_t,4>, hash_strategy_t<4>, ALLOCATOR> >(h4, 4, &raw_buffer[k*BLOCK_SIZE], &groups[k].ends_4, &raw_buffer[k*BLOCK_SIZE], &raw_buffer[k*BLOCK_SIZE]); |
---|
[1893] | 80 | |
---|
[1929] | 81 | // do_block<hash_table<identity_strategy_t<uint32_t,5>, hash_strategy_d, ALLOCATOR> >(h5, 5, (uint8_t *)&buffer[k], (uint8_t *)&groups[k].ends_5, (uint8_t *)&buffer[k], (uint8_t *)&buffer[k]); |
---|
| 82 | // do_block<hash_table<identity_strategy_t<uint32_t,5>, hash_strategy_t<5>, ALLOCATOR> >(h5, groups[k].starts, groups[k].ends_5); |
---|
| 83 | // do_segment<hash_table<identity_strategy_t<uint32_t,6>, hash_strategy_t<6>, ALLOCATOR> >(h6, groups.starts, groups.ends_6, segment_size); |
---|
| 84 | // do_segment<hash_table<identity_strategy_t<uint32_t,7>, hash_strategy_t<7>, ALLOCATOR> >(h7, groups.starts, groups.ends_7, segment_size); |
---|
| 85 | // do_segment<hash_table<identity_strategy_t<uint32_t,8>, hash_strategy_t<8>, ALLOCATOR> >(h8, groups.starts, groups.ends_8, segment_size); |
---|
| 86 | // do_segment<hash_table<identity_strategy_t<uint32_t,9>, hash_strategy_t<9>, ALLOCATOR> >(h9, groups.starts, groups.ends_9, segment_size); |
---|
| 87 | // do_segment<hash_table<identity_strategy_t<uint32_t,10>, hash_strategy_t<10>, ALLOCATOR> >(h10, groups.starts, groups.ends_10, segment_size); |
---|
[1893] | 88 | |
---|
[1929] | 89 | // do_segment<hash_table<identity_strategy_t<uint32_t,11>, hash_strategy_t<11>, ALLOCATOR> >(h11, groups.starts, groups.ends_11, segment_size); |
---|
| 90 | // do_segment<hash_table<identity_strategy_t<uint32_t,12>, hash_strategy_t<12>, ALLOCATOR> >(h12, groups.starts, groups.ends_12, segment_size); |
---|
| 91 | // do_segment<hash_table<identity_strategy_t<uint32_t,13>, hash_strategy_t<13>, ALLOCATOR> >(h13, groups.starts, groups.ends_13, segment_size); |
---|
| 92 | // do_segment<hash_table<identity_strategy_t<uint32_t,14>, hash_strategy_t<14>, ALLOCATOR> >(h14, groups.starts, groups.ends_14, segment_size); |
---|
| 93 | // do_segment<hash_table<identity_strategy_t<uint32_t,15>, hash_strategy_t<15>, ALLOCATOR> >(h15, groups.starts, groups.ends_15, segment_size); |
---|
[1893] | 94 | |
---|
[1929] | 95 | // do_segment<hash_table<identity_strategy_t<BitBlock,16>, hash_strategy_t<16>, ALLOCATOR> >(h16, starts, groups.ends_16, segment_size); |
---|
| 96 | // do_segment<hash_table<identity_strategy_d, hash_strategy_d, ALLOCATOR> >(hgte_17, starts, groups.ends_gte_17, segment_size); |
---|
| 97 | |
---|
[1893] | 98 | } |
---|
| 99 | |
---|
[1929] | 100 | /* Final Block */ |
---|
[1893] | 101 | } |
---|
| 102 | |
---|
| 103 | // void resolve(uint8_t * segment, uint32_t segment_blocks, BitBlock * starts, BitBlock * ends, BitBlock * hash_values, SoA_symbol & symbols) {} |
---|
| 104 | private: |
---|
[1929] | 105 | /* |
---|
| 106 | hash_table<1, identity_strategy_t<uint8_t,1>, hash_strategy_t<1>, ALLOCATOR> h1; |
---|
| 107 | hash_table<2, identity_strategy_t<uint16_t,2>, hash_strategy_t<2>, ALLOCATOR> h2; |
---|
| 108 | hash_table<3, identity_strategy_t<uint16_t,3>, hash_strategy_t<3>, ALLOCATOR> h3; |
---|
| 109 | */ |
---|
[1893] | 110 | hash_table<identity_strategy_t<uint32_t,4>, hash_strategy_t<4>, ALLOCATOR> h4; |
---|
| 111 | |
---|
[1929] | 112 | //hash_table<identity_strategy_t<uint32_t,5>, hash_strategy_d, ALLOCATOR> h5; |
---|
| 113 | /* |
---|
| 114 | hash_table<6, identity_strategy_t<uint32_t,6>, hash_strategy_d, ALLOCATOR> h6; |
---|
| 115 | hash_table<7, identity_strategy_t<uint32_t,7>, hash_strategy_d, ALLOCATOR> h7; |
---|
| 116 | hash_table<8, identity_strategy_t<uint32_t,8>, hash_strategy_d, ALLOCATOR> h8; |
---|
| 117 | hash_table<9, identity_strategy_t<uint32_t,9>, hash_strategy_d, ALLOCATOR> h9; |
---|
| 118 | hash_table<10, identity_strategy_t<uint32_t,10>, hash_strategy_d, ALLOCATOR> h10; |
---|
[1893] | 119 | |
---|
[1929] | 120 | hash_table<11, identity_strategy_t<uint32_t,11>, hash_strategy_t<11>, ALLOCATOR> h11; |
---|
| 121 | hash_table<12, identity_strategy_t<uint32_t,12>, hash_strategy_t<12>, ALLOCATOR> h12; |
---|
| 122 | hash_table<13, identity_strategy_t<uint32_t,13>, hash_strategy_t<13>, ALLOCATOR> h13; |
---|
| 123 | hash_table<14, identity_strategy_t<uint32_t,14>, hash_strategy_t<14>, ALLOCATOR> h14; |
---|
| 124 | hash_table<15, identity_strategy_t<uint32_t,15>, hash_strategy_t<15>, ALLOCATOR> h15; |
---|
[1893] | 125 | |
---|
[1929] | 126 | hash_table<16, identity_strategy_t<BitBlock,16>, hash_strategy_t<16>, ALLOCATOR> h16; |
---|
| 127 | */ |
---|
| 128 | /*Default */ |
---|
| 129 | /* |
---|
| 130 | hash_table<0, identity_strategy_d, hash_strategy_d, ALLOCATOR> hgte_17; |
---|
| 131 | */ |
---|
[1893] | 132 | |
---|
[1929] | 133 | //int32_t partial_offset[LGTH_GROUPS+1]; /* lgth indexed array, 1,2,.. */ |
---|
[1893] | 134 | }; |
---|
| 135 | |
---|
| 136 | #endif // ID_SYMBOL_TABLE_TEMPLATE_HPP |
---|
| 137 | |
---|
[1929] | 138 | /* |
---|
[1893] | 139 | |
---|
| 140 | 1. How do we stitch together C code and Pablo generated code. |
---|
| 141 | - Variables, starts, ends |
---|
| 142 | - Length groups |
---|
| 143 | - EOF mask |
---|
| 144 | |
---|
| 145 | */ |
---|
| 146 | |
---|
| 147 | /* |
---|
| 148 | template<class SYMBOL, class ALLOCATOR> |
---|
| 149 | class div2: public symbol_table_strategy<SYMBOL, ALLOCATOR> { |
---|
| 150 | |
---|
| 151 | public: |
---|
| 152 | div2() {} |
---|
| 153 | ~div2() {} |
---|
| 154 | |
---|
| 155 | void resolve(BitBlock * buffer, BitBlock * starts, BitBlock * ends, BitBlock * hash_basis_0, BitBlock * hash_basis_1, uint32_t segment_size, AoS_symbol * symbol_ary, const uint32_t symbol_ary_size) { |
---|
| 156 | cout << "div2 Strategy" << endl; |
---|
| 157 | } |
---|
| 158 | //void resolve(uint8_t * segment, uint32_t segment_blocks, BitBlock * starts, BitBlock * ends, SoA_symbol & symbols); |
---|
| 159 | }; |
---|
| 160 | |
---|
| 161 | template<class SYMBOL, class ALLOCATOR> |
---|
| 162 | class log2: public symbol_table_strategy<SYMBOL, ALLOCATOR> { |
---|
| 163 | |
---|
| 164 | public: |
---|
| 165 | log2() {} |
---|
| 166 | ~log2() {} |
---|
| 167 | |
---|
| 168 | void resolve(BitBlock * buffer, BitBlock * starts, BitBlock * ends, BitBlock * hash_basis_0, BitBlock * hash_basis_1, uint32_t segment_size, AoS_symbol * symbol_ary, const uint32_t symbol_ary_size) { |
---|
| 169 | cout << "log2 Strategy" << endl; |
---|
| 170 | } |
---|
| 171 | //void resolve(uint8_t * segment, uint32_t segment_blocks, BitBlock * starts, BitBlock * ends, SoA_symbol & symbols); |
---|
| 172 | }; |
---|
| 173 | */ |
---|
| 174 | |
---|