Changeset 5530


Ignore:
Timestamp:
Jun 24, 2017, 6:07:51 PM (20 months ago)
Author:
xwa163
Message:

fix some bugs and typos in lz4d_e_d prototype

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/lz4d/lz4d_e_d.py

    r5529 r5530  
    188188    output_pos = 0
    189189
    190     for (isCompressed, block_start, block_end_pos) in block_data:
     190    for (isCompressed, block_start_pos, block_end_pos) in block_data:
    191191
    192192        if isCompressed:
    193             token_pos = block_start
     193            token_pos = block_start_pos
    194194
    195195            while token_pos < block_end_pos:
     
    243243                    # Will Be a Select Instruction
    244244                    if match_extension_size > 0:
    245                         match_length += match_extension_size * 255 + ord(file_content[offset_pos + 2 + match_extension_size])
    246                
     245                        match_length += (match_extension_size - 1) * 255 + ord(file_content[offset_pos + 1 + match_extension_size])
     246
    247247                    new_M0_bits = ((1 << (match_length - 1)) - 1) << output_pos
    248248                    output_pos += match_length
     
    255255                    token_pos = offset_pos
    256256        else:
    257             uncompressed_data.append(block_start, block_length, output_pos)
    258             output_pos += block_end_pos - block_start_pos
     257            block_length = block_end_pos - block_start_pos
     258            uncompressed_data.append(block_start_pos, block_length, output_pos)
     259            output_pos += block_length
    259260
    260261    return E1_marker, M0_marker, uncompressed_data, output_pos
     
    263264def deposit_compressed(file_content, block_data, e1_marker, m0_marker, outputStrBuffer):
    264265   
    265     compressed_start_marker = 0
    266     compressed_end_marker = 0
    267     e_uncompressed_marker = 0
    268    
    269     for (isCompressed, block_start, block_end_pos) in block_data:
    270         if isCompressed:
    271             compressed_start_marker |= 1 << block_start
    272             compressed_end_marker |= 1 << block_end_pos
    273         else: e_uncompressed_marker |= (1 << block_end) - (1 << block_start)
    274 
    275     d_marker = (~(m0_marker | pablo.Advance(m0_marker))) & (~e_uncompressed_marker)
    276 
     266    d_marker = ~(m0_marker | pablo.Advance(m0_marker))
    277267    output_pos = 0
    278268
    279269    # Outer loop will iterate throught all of the compressed block
    280     while (compressed_start_marker):
     270    # while (compressed_start_marker):
     271    for (isCompressed, block_start_pos, block_end_pos) in block_data:
     272        if not isCompressed:
     273            # There will be much fewer uncompressed block than compressed block
     274            output_pos = output_pos + block_end_pos - block_start_pos
     275            continue
     276
    281277        output_pos_marker = pablo.ScanTo(singleton(output_pos), d_marker)
    282278        output_pos = position(output_pos_marker)
    283279
    284         compressed_start_bit = singletonStream(compressed_start_marker)
     280        compressed_start_bit = singleton(block_start_pos)
    285281        token_mark = compressed_start_bit
    286         compressed_start_marker = compressed_start_marker - compressed_start_bit
    287 
    288         compressed_end_bit = singletonStream(compressed_end_marker)
    289         compressed_end_marker = compressed_end_marker - compressed_end_bit
    290         compressed_end_bit_pos = position(compressed_end_bit)
    291 
    292         # token_pos = 1 << compressed_start_pos
    293         # token_mark = singleton(token_pos)
     282
    294283        last_match_len_marker = pablo.ScanTo(token_mark, e1_marker)  # first e1 bit
    295284        last_match_len_marker_pos = position(last_match_len_marker)
     
    302291
    303292        output_pos += literal_length
    304         while literal_end_pos < compressed_end_bit_pos:
     293        while literal_end_pos < block_end_pos:
    305294            offset_pos = literal_end_pos
    306295
     
    331320
    332321            output_pos += literal_length
    333         pass
    334322
    335323def deposit_uncompressed(file_content, uncompressed_block_data, outputStrBuffer):
    336324    for (uncompressed_start_pos, block_length, output_pos) in uncompressed_block_data:
    337325        uncompressed_end_pos = uncompressed_start_pos + block_length
    338         outputStrBuffer[output_pos: output_pos + copy_length] = list(
     326        outputStrBuffer[output_pos: output_pos + block_length] = list(
    339327            file_content[uncompressed_start_pos: uncompressed_end_pos]
    340328        )
    341         output_pos += copy_length
    342329
    343330'''
     
    375362
    376363        # Deposit compressed and uncompressed blocks
    377        
    378364        deposit_compressed(file_content, block_data, E1_marker, M0_marker, outputStrBuffer)
    379365        deposit_uncompressed(file_content, uncompressed_data, outputStrBuffer)
    380366
    381 
    382367        outputStr = ''.join(outputStrBuffer)
    383 
     368        # print(outputStr)
    384369        with open(outputFile, 'w') as f:
    385370            f.write(outputStr)
Note: See TracChangeset for help on using the changeset viewer.