import ansilexer
class Trie:
- # root | | header | values | child |
- # offset | ... | size | value # | ... | offsets ... |
- # 32b | | 8b | 8b | n*16b | 8b + 24b |
+ # root | | header | values | child |
+ # offset | ... | size/2 | value # | ... | offsets ... |
+ # 32b | | 8b | 8b | n*16b | 8b + 24b |
root_offset_struct = struct.Struct('<I')
header_struct = struct.Struct('<BB')
value_struct = struct.Struct('<H')
child_offsets += [(char, offset)]
# Serialize this node
- size = 2 + 2*len(self.values) + 4*len(child_offsets)
-
+ size = int(2 + 2*len(self.values) + 4*len(child_offsets))
serialized = bytearray()
- serialized += self.header_struct.pack(size, len(self.values))
+ serialized += self.header_struct.pack(int(size/2), len(self.values))
for v in self.values:
serialized += self.value_struct.pack(v)
out += ']'
# print children
- if base_offset + size - offset > 4: draw_pipe = True
+ if base_offset + size*2 - offset > 4: draw_pipe = True
child_count = 0
- while offset < base_offset + size:
+ while offset < base_offset + size*2:
if child_count or value_count:
out += '\n'
out += indent
max node values: {}
max node children: {}
max node value index: {}
-max node child offset: {}""".lstrip().format(stats.node_count, stats.max_node_size, stats.max_node_values, stats.max_node_children, stats.max_node_value_index, stats.max_node_child_offset)
+max node child offset: {}""".lstrip().format(stats.node_count, stats.max_node_size*2, stats.max_node_values, stats.max_node_children, stats.max_node_value_index, stats.max_node_child_offset)
return out, stats
def pretty_print_map(serialized: bytes):
magic, version, map_offset = search_data_header_struct.unpack_from(serialized)
assert magic == b'MCS'
assert version == 0
+ assert not search_data_header_struct.size % 4
pretty_trie, stats = pretty_print_trie(serialized[search_data_header_struct.size:map_offset], show_merged=show_merged)
pretty_map = pretty_print_map(serialized[map_offset:])