From be19fd5398bdde5c5c8ddfdca0a2a23a5569c9f4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 8 Jan 2022 19:20:29 +0100 Subject: [PATCH] documentation: trie pretty printing didn't handle the 11bit special case. Better to have it tested directly, and not only through the JS decoder part. --- documentation/_search.py | 5 +++++ documentation/test/populate-js-test-data.py | 4 ++-- documentation/test/test_search.py | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/documentation/_search.py b/documentation/_search.py index c771b006..1a1d893e 100644 --- a/documentation/_search.py +++ b/documentation/_search.py @@ -456,6 +456,11 @@ def _pretty_print_trie(serialized: bytearray, hashtable, stats, base_offset, ind 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 diff --git a/documentation/test/populate-js-test-data.py b/documentation/test/populate-js-test-data.py index 424d545b..81d9fa9c 100755 --- a/documentation/test/populate-js-test-data.py +++ b/documentation/test/populate-js-test-data.py @@ -115,8 +115,8 @@ map = ResultMap() 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))) diff --git a/documentation/test/test_search.py b/documentation/test/test_search.py index 448d4d1f..c716589a 100755 --- a/documentation/test/test_search.py +++ b/documentation/test/test_search.py @@ -147,6 +147,24 @@ h0xc3 """) 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) -- 2.30.2