chiark / gitweb /
documentation: trie pretty printing didn't handle the 11bit special case.
authorVladimír Vondruš <mosra@centrum.cz>
Sat, 8 Jan 2022 18:20:29 +0000 (19:20 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Sat, 8 Jan 2022 22:17:00 +0000 (23:17 +0100)
Better to have it tested directly, and not only through the JS
decoder part.

documentation/_search.py
documentation/test/populate-js-test-data.py
documentation/test/test_search.py

index c771b00617775ff661ef8daddb5800cee28d1869..1a1d893ee746cc6de21fc947b37efd7d233d44cc 100644 (file)
@@ -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
index 424d545bf1c51670cfd88768ba9ea215d7be56e1..81d9fa9c25d83e0ac79a42fd4a96329ae2a843e9 100755 (executable)
@@ -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)))
 
index 448d4d1f983cc84126a74de199b22851af8eb8ab..c716589a021440c3b448450ed70ac00b51539267 100755 (executable)
@@ -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)