11import path from "path" ;
2- import { readFileSync , existsSync } from "fs" ;
2+ import { readFileSync } from "fs" ;
33
44import { env } from "../../../utils/misc.js" ;
55import { DataEntry } from "./search.js" ;
66import { HeadingEntry , HeadingsBySpec } from "./scraper.js" ;
77
8- /** Headings indexed by id for O(1) lookup. */
9- type HeadingsIndex = {
10- [ shortname : string ] : { [ id : string ] : HeadingEntry } ;
11- } ;
12-
138export class Store {
149 version = - 1 ;
1510 bySpec : { [ shortname : string ] : DataEntry [ ] } = { } ;
@@ -21,8 +16,8 @@ export class Store {
2116 title : string ;
2217 } ;
2318 } = { } ;
24- /** Headings indexed by spec shortname, then by fragment id. */
25- headings : HeadingsIndex = { } ;
19+ /** Headings pre- indexed by spec shortname, then by fragment id. */
20+ headings : HeadingsBySpec = { } ;
2621 /** Reverse lookup: shortname → spec title. */
2722 private specTitleByShortname : Map < string , string > = new Map ( ) ;
2823
@@ -35,8 +30,7 @@ export class Store {
3530 this . byTerm = readJson ( "xref.json" ) ;
3631 this . bySpec = readJson ( "specs.json" ) ;
3732 this . specmap = readJson ( "specmap.json" ) ;
38- const rawHeadings : HeadingsBySpec = readJsonOptional ( "headings.json" ) ;
39- this . headings = indexHeadings ( rawHeadings ) ;
33+ this . headings = readJsonOptional ( "headings.json" ) ;
4034 this . specTitleByShortname = buildSpecTitleMap ( this . specmap ) ;
4135 this . version = Date . now ( ) ;
4236 }
@@ -81,19 +75,6 @@ function readJsonOptional(filename: string) {
8175 }
8276}
8377
84- /** Index headings arrays by id for O(1) lookup per spec. */
85- function indexHeadings ( raw : HeadingsBySpec ) : HeadingsIndex {
86- const indexed : HeadingsIndex = Object . create ( null ) ;
87- for ( const [ shortname , headings ] of Object . entries ( raw ) ) {
88- const byId : { [ id : string ] : HeadingEntry } = Object . create ( null ) ;
89- for ( const h of headings ) {
90- byId [ h . id ] = h ;
91- }
92- indexed [ shortname ] = byId ;
93- }
94- return indexed ;
95- }
96-
9778/** Build a shortname → title map from the specmap for O(1) title lookup. */
9879function buildSpecTitleMap ( specmap : Store [ "specmap" ] ) : Map < string , string > {
9980 const result = new Map < string , string > ( ) ;
0 commit comments