out = ''
result_count, child_count = Trie.header_struct.unpack_from(serialized, base_offset)
+ # If result count has the high bit set, it's stored in 11 bits and child
+ # count in 4 bits instead of 7 + 8
+ if result_count & 0x80:
+ result_count = (result_count & 0x7f) | ((child_count & 0xf0) << 3)
+ child_count = child_count & 0x0f
stats.max_node_results = max(result_count, stats.max_node_results)
stats.max_node_children = max(child_count, stats.max_node_children)
offset = base_offset + Trie.header_struct.size
for i in range(128):
trie.insert("__init__", map.add(f"Foo{i}.__init__(self)", f"Foo{i}.html#__init__", suffix_length=6, flags=ResultFlag.from_type(ResultFlag.NONE, EntryType.FUNC)))
-# It's __init_subclass__, but here I want to trigger the case of both a high
-# amount of results and some children as well.
+# It's __init_subclass__ (one underscore, not two), but here I want to trigger
+# the case of both a high amount of results and some children as well.
for i in [3, 15, 67]:
trie.insert("__init__subclass__", map.add(f"Foo{i}.__init__subclass__(self)", f"Foo{i}.html#__init__subclass__", suffix_length=6, flags=ResultFlag.from_type(ResultFlag.NONE, EntryType.FUNC)))
""")
self.assertEqual(len(serialized), 82)
+ def test_many_results(self):
+ trie = Trie()
+
+ for i in range(128):
+ trie.insert("__init__", i)
+ # It's __init_subclass__ (one underscore, not two), but here I want to
+ # trigger the case of both a high amount of results and some children
+ # as well.
+ for i in [203, 215, 267]:
+ trie.insert("__init__subclass__", i)
+
+ serialized = trie.serialize()
+ self.compare(serialized, """
+__init__ [{}]
+ subclass__ [203, 215, 267]
+""".format(', '.join([str(i) for i in range(128)])))
+ self.assertEqual(len(serialized), 376)
+
class MapSerialization(unittest.TestCase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)