chiark / gitweb /
doxygen: explicitly save symbol count.
authorVladimír Vondruš <mosra@centrum.cz>
Mon, 5 Feb 2018 01:59:07 +0000 (02:59 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Mon, 5 Feb 2018 01:59:07 +0000 (02:59 +0100)
With all the aliases the autodetected number was quite off.

doxygen/dox2html5.py
doxygen/search.js
doxygen/test/js-test-data/empty.bin
doxygen/test/js-test-data/searchdata.b85
doxygen/test/js-test-data/searchdata.bin
doxygen/test/js-test-data/unicode.bin
doxygen/test/js-test-data/wrong-magic.bin
doxygen/test/js-test-data/wrong-version.bin
doxygen/test/populate-js-test-data.py
doxygen/test/test-search.js
doxygen/test/test_search.py

index c87df8337cec028d316fd0a17026e9a7b123a633..51559ea8f4abc9f61970d205f640b2ab1da8c90c 100755 (executable)
@@ -332,13 +332,13 @@ class ResultMap:
         assert len(output) == offset
         return output
 
-search_data_header_struct = struct.Struct('<3sBI')
+search_data_header_struct = struct.Struct('<3sBHI')
 
-def serialize_search_data(trie: Trie, map: ResultMap, merge_subtrees=True, merge_prefixes=True) -> bytearray:
+def serialize_search_data(trie: Trie, map: ResultMap, symbol_count, merge_subtrees=True, merge_prefixes=True) -> bytearray:
     serialized_trie = trie.serialize(merge_subtrees=merge_subtrees)
     serialized_map = map.serialize(merge_prefixes=merge_prefixes)
-    # magic header, version, offset of result map
-    return search_data_header_struct.pack(b'MCS', 0, len(serialized_trie) + 8) + serialized_trie + serialized_map
+    # magic header, version, symbol count, offset of result map
+    return search_data_header_struct.pack(b'MCS', 0, symbol_count, len(serialized_trie) + 10) + serialized_trie + serialized_map
 
 xref_id_rx = re.compile(r"""(.*)_1(_[a-z-]+[0-9]+)$""")
 slugify_nonalnum_rx = re.compile(r"""[^\w\s-]""")
@@ -1796,7 +1796,7 @@ def build_search_data(state: State, merge_subtrees=True, add_lookahead_barriers=
             keyword_index = map.add(title, '', alias=index, suffix_length=suffix_length)
             trie.insert(search.lower(), keyword_index)
 
-    return serialize_search_data(trie, map, merge_subtrees=merge_subtrees, merge_prefixes=merge_prefixes)
+    return serialize_search_data(trie, map, len(state.search), merge_subtrees=merge_subtrees, merge_prefixes=merge_prefixes)
 
 def base85encode_search_data(data: bytearray) -> bytearray:
     return (b"/* Generated by http://mcss.mosra.cz/doxygen/. Do not edit. */\n" +
index 35060dd6fcda9f301f8fc0b7b218eba653f4b7b5..79903fe4df15a2152ba8425be63918f2c6167cfa 100644 (file)
@@ -40,7 +40,7 @@ var Search = {
         let view = new DataView(buffer);
 
         /* The file is too short to contain at least the headers */
-        if(view.byteLength < 18) {
+        if(view.byteLength < 20) {
             console.error("Search data too short");
             return false;
         }
@@ -58,13 +58,13 @@ var Search = {
         }
 
         /* Separate the data into the trie and the result map */
-        let mapOffset = view.getUint32(4, true);
-        this.trie = new DataView(buffer, 8, mapOffset - 8);
+        let mapOffset = view.getUint32(6, true);
+        this.trie = new DataView(buffer, 10, mapOffset - 10);
         this.map = new DataView(buffer, mapOffset);
 
         /* Set initial properties */
         this.dataSize = buffer.byteLength;
-        this.symbolCount = (this.map.getUint32(0, true) & 0x00ffffff)/4 - 1;
+        this.symbolCount = view.getUint16(4, true);
         this.maxResults = maxResults ? maxResults : 100;
         this.searchString = '';
         this.searchStack = [this.trie.getUint32(0, true)];
index 6d194001ded57661326bd550013ee951d9ef184b..67dc8acd8bab56f383e3fdd70215edb1172a03ab 100644 (file)
Binary files a/doxygen/test/js-test-data/empty.bin and b/doxygen/test/js-test-data/empty.bin differ
index 7353fb94be870904bba2013b0f2cadc5ff0333d8..ab4e029f896119ea02907c5c42130df8b2238ce9 100644 (file)
@@ -1 +1 @@
-O+!-viU9xsZ~*`S0RRC2009I504V?g2mk;m009mF0B!&Q6aWBe0RRI400AHX04V?gBme*?00Alh0B!&QFaQ8)00A}t0BryPJOBVX0RaL4LI8j|00Bq<0CE5UPyhgL00CA20CWHWTmS%L00CkE0A&FH1poj6ZU6u&00D9U04M+fcmM!y00Djg0BHaLga80-00D{s06GBy1OSi#fI0vHmH+@{00Eu=0A~OJqyPYJ00F810AT<F8UO%oXaE3qumAvZ00FiD06GBy006`QfI0vH$^Zap00Ghf0CWQY0RRI41poj6-T(k800HIz04M+f>;M3600P(m0Aca~0BHdL2LJ#80s#PJ009O80BisO3;_UV009yK0B!*Q2mk;99svL;00I~R0AV5l04M+fC;<R;00A-q0Am0GssI3CH~|1<0RRR700Bq=0A&CHOaTCA00B|~0AT<DSOEZV00CYB0Ac_EWB~wm00j5|0BvXh0CqkB0CH*p0COk+01!U_0BKhM04jR`0BMl`04TEn0By+t0Knw{008g+015s8002#4bZ7u>VQpn|aA9L*O<{CsE@*UZYybcf2s%1#X>KTKZgealX>N2W03&T_ZU6uPIyzQmV{~tF0Ap-nb8}5$bZB2OUolo?V{~tFE@*UZYyton20A)zX>KSfAY*TCb94YBZE0=*0025VQekdqWdLJrVRLg$VRUF;F<&uKVQyz-E@*UZYy<!o20A)zX>KSfAY*TCb94YBZE0>$VP|C^!n+_-bz*Q~XJr6$bz*Q~XJsyEbZu+|08(XRbYX61Y-I!h2LJ#9IyzEiV{|Af
\ No newline at end of file
+O+!-v2LOx#003|S000310RR921ONaj009U904M+f4gdgd009&L0BHdL0{{R4AOHX<00ATb04M+fDgXd(00A%n0BHaLHUI!^00BGz06GBy0suk)fI0vHNB{tG00B?{0B-;RRsaBW00CS80Am0FVgLYT0RRO600C|Q04V?gasU7*00DRa0B!&QegFVz00D#m0BryPiU0sQ0RaR6kN|)>00EW&0A&CHo&W%600E=`0B!&QssI3C00SBT0BvXh0Cund0CE5Uwg3P+0RaF2!~lRg00GJX0B8UK(f|N-0{{U40{{g800G_r04V?g<^TXF00Ha(0B!&R*Z=@w@&Ev70RRU8009C40A&CH1_1zU009gE0A~OJ5&-~i0RRX900ABW04V?h7y$rbA^`v>00Afg0CWHWG64W%00OE20AV-*0A&FH1^@s7NC5z400B$^0A~OJQUL&A00CG50B`^SUI74N00CqH0CfNa_y7QHXaE3qJ^=u7Y5@RqC;$KuKL7w}R{#JidjJ4wkpKWFvj6~X$p8Sr<p2Nx@Bjb_{r~^~O<{Cs0B&JzWpi+0V`WWYbZ9PUbZu+^01^l~I&EogC~0nVEFfuabSVHMZE0=*0025VR%K&!Z*l-*Y+-YAO<{CsUol@XR%K&!Z*neZbZu+`02l^3I&EogC@COgZ*FsR03&T_ZU6uPIyzEeZf9ixV{Bn_b4_7%XkRg3F;Zb}XJsyEbZu+|02c;2I&EogC@COgZ*FsR03&T_Zct%oWgx=4AX9Z>aA9X<0CRO>aA9X<E@*UZYy<#OWn*+<Zf9&|1ONvB00KHXQe|UwC@BB{
\ No newline at end of file
index f1bed6261f7ccaa7a92ed5e2d394331836ca08f0..5b2f09fc0245a94d81d488a64084909ea55e1504 100644 (file)
Binary files a/doxygen/test/js-test-data/searchdata.bin and b/doxygen/test/js-test-data/searchdata.bin differ
index 81595827d1393474b0a7389442aebe4092b6d603..914fd4a55637bdd26d235064f8caaba3724f0aa5 100644 (file)
Binary files a/doxygen/test/js-test-data/unicode.bin and b/doxygen/test/js-test-data/unicode.bin differ
index 01881b37a355110cb9648875c470e41c657ddcfb..253fe0fba18bf510f484924531b2ebbbac76c688 100644 (file)
Binary files a/doxygen/test/js-test-data/wrong-magic.bin and b/doxygen/test/js-test-data/wrong-magic.bin differ
index 478f0f2e3a1fa072d2fbc20cac3e544ccc818279..b2c67d7784f05d917ae5ef497425a0d07e434ca4 100644 (file)
@@ -1 +1 @@
-MCS\ 1              
\ No newline at end of file
+MCS\ 1                
\ No newline at end of file
index 062803719bc41fc93e386c91c7d086b19cd8b551..13ed568723728a5fdac6ee3c146edf08d28aef97 100755 (executable)
@@ -37,11 +37,11 @@ basedir = pathlib.Path(os.path.dirname(os.path.realpath(__file__)))/'js-test-dat
 with open(basedir/'short.bin', 'wb') as f:
     f.write(b'')
 with open(basedir/'wrong-magic.bin', 'wb') as f:
-    f.write(b'MOS\0              ')
+    f.write(b'MOS\0                ')
 with open(basedir/'wrong-version.bin', 'wb') as f:
-    f.write(b'MCS\1              ')
+    f.write(b'MCS\1                ')
 with open(basedir/'empty.bin', 'wb') as f:
-    f.write(serialize_search_data(Trie(), ResultMap()))
+    f.write(serialize_search_data(Trie(), ResultMap(), 0))
 
 trie = Trie()
 map = ResultMap()
@@ -70,9 +70,9 @@ trie.insert("rectangle", map.add("Rectangle", "", alias=range_index))
 trie.insert("rect()", map.add("Rectangle::Rect()", "", suffix_length=2, alias=range_index))
 
 with open(basedir/'searchdata.bin', 'wb') as f:
-    f.write(serialize_search_data(trie, map))
+    f.write(serialize_search_data(trie, map, 7))
 with open(basedir/'searchdata.b85', 'wb') as f:
-    f.write(base64.b85encode(serialize_search_data(trie, map), True))
+    f.write(base64.b85encode(serialize_search_data(trie, map, 7), True))
 
 trie = Trie()
 map = ResultMap()
@@ -81,4 +81,4 @@ trie.insert("hýždě", map.add("Hýždě", "#a", flags=ResultFlag.PAGE))
 trie.insert("hárá", map.add("Hárá", "#b", flags=ResultFlag.PAGE))
 
 with open(basedir/'unicode.bin', 'wb') as f:
-    f.write(serialize_search_data(trie, map))
+    f.write(serialize_search_data(trie, map, 2))
index 56b0c47b7f142d3b17685d1b56daa5fc973f3058..bffe1720e33ec31c8377e77a26813e7477fee8a0 100644 (file)
@@ -70,7 +70,7 @@ const { StringDecoder } = require('string_decoder');
 /* Verify that base85-decoded file is equivalent to the binary */
 {
     let binary = fs.readFileSync(path.join(__dirname, "js-test-data/searchdata.bin"));
-    assert.equal(binary.byteLength, 648);
+    assert.equal(binary.byteLength, 650);
     let b85 = fs.readFileSync(path.join(__dirname, "js-test-data/searchdata.b85"), {encoding: 'utf-8'});
     assert.deepEqual(new DataView(binary.buffer.slice(binary.byteOffset, binary.byteOffset + binary.byteLength)), new DataView(Search.base85decode(b85), 0, binary.byteLength));
 }
@@ -105,8 +105,8 @@ const { StringDecoder } = require('string_decoder');
 {
     let buffer = fs.readFileSync(path.join(__dirname, "js-test-data/searchdata.bin"));
     assert.ok(Search.init(buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength)));
-    assert.equal(Search.dataSize, 648);
-    assert.equal(Search.symbolCount, 9);
+    assert.equal(Search.dataSize, 650);
+    assert.equal(Search.symbolCount, 7);
     assert.equal(Search.maxResults, 100);
 
     /* Blow up */
@@ -188,8 +188,8 @@ const { StringDecoder } = require('string_decoder');
 {
     let buffer = fs.readFileSync(path.join(__dirname, "js-test-data/searchdata.bin"));
     assert.ok(Search.init(buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength), 3));
-    assert.equal(Search.dataSize, 648);
-    assert.equal(Search.symbolCount, 9);
+    assert.equal(Search.dataSize, 650);
+    assert.equal(Search.symbolCount, 7);
     assert.equal(Search.maxResults, 3);
     assert.deepEqual(Search.search('m'), [
         { name: 'Math',
@@ -210,8 +210,8 @@ const { StringDecoder } = require('string_decoder');
 {
     let b85 = fs.readFileSync(path.join(__dirname, "js-test-data/searchdata.b85"), {encoding: 'utf-8'});
     assert.ok(Search.load(b85));
-    assert.equal(Search.dataSize, 648); /* some padding on the end, that's okay */
-    assert.equal(Search.symbolCount, 9);
+    assert.equal(Search.dataSize, 652); /* some padding on the end, that's okay */
+    assert.equal(Search.symbolCount, 7);
     assert.equal(Search.maxResults, 100);
     assert.deepEqual(Search.search('min'), [
         { name: 'Math::min(int, int)',
@@ -232,7 +232,7 @@ const { StringDecoder } = require('string_decoder');
 {
     let buffer = fs.readFileSync(path.join(__dirname, "js-test-data/unicode.bin"));
     assert.ok(Search.init(buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength), 3));
-    assert.equal(Search.dataSize, 122);
+    assert.equal(Search.dataSize, 124);
     assert.equal(Search.symbolCount, 2);
     assert.deepEqual(Search.search('h'), [
         { name: Search.toUtf8('Hárá'),
index 6c7cd2bb3fac17d1237db7ae78fc2477d8e5775c..a6273b623ac23190a3cbfd5280eae3e33f369c7f 100755 (executable)
@@ -154,14 +154,13 @@ def pretty_print_map(serialized: bytes, colors=False):
     return out
 
 def pretty_print(serialized: bytes, show_merged=False, show_lookahead_barriers=True, colors=False):
-    magic, version, map_offset = search_data_header_struct.unpack_from(serialized)
+    magic, version, symbol_count, 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, show_lookahead_barriers=show_lookahead_barriers, colors=colors)
     pretty_map = pretty_print_map(serialized[map_offset:], colors=colors)
-    return pretty_trie + '\n' + pretty_map, stats
+    return '{} symbols\n'.format(symbol_count) + pretty_trie + '\n' + pretty_map, stats
 
 class TrieSerialization(unittest.TestCase):
     def __init__(self, *args, **kwargs):
@@ -350,8 +349,9 @@ class Serialization(unittest.TestCase):
         trie.insert("math::range", index)
         trie.insert("range", index)
 
-        serialized = serialize_search_data(trie, map)
+        serialized = serialize_search_data(trie, map, 3)
         self.compare(serialized, """
+3 symbols
 math [0]
 |   ::vector [1]
 |     range [2]
@@ -361,7 +361,7 @@ range [2]
 1: ::Vector [prefix=0[:0], type=CLASS] -> classMath_1_1Vector.html
 2: ::Range [prefix=0[:0], type=CLASS] -> classMath_1_1Range.html
 """)
-        self.assertEqual(len(serialized), 239)
+        self.assertEqual(len(serialized), 241)
 
 class Search(IntegrationTestCase):
     def __init__(self, *args, **kwargs):
@@ -374,8 +374,9 @@ class Search(IntegrationTestCase):
             serialized = f.read()
             search_data_pretty = pretty_print(serialized)[0]
         #print(search_data_pretty)
-        self.assertEqual(len(serialized), 4570)
+        self.assertEqual(len(serialized), 4572)
         self.assertEqual(search_data_pretty, """
+36 symbols
 deprecated_macro [0]
 ||        |     ($
 ||        |      ) [1]