From ef717e73137e7ce0c0f699bbfa4fc2da461fce37 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Wed, 22 Apr 2026 15:28:10 -0400 Subject: add children_headings to document abstraction Add int[] children_headings field to DocObj_MetaInfo_ and compute it in the post-processing pass of metadoc_from_src.d, right after last_descendant_ocn. Single O(n) pass builds a parent_ocn -> child heading OCNs map, then assigns to each heading object. Useful for tree-structured output. The .ssp serializer now reads directly from the abstraction field instead of pre-computing its own map. metadoc_object_setter.d: +1 line (field declaration) metadoc_from_src.d: +17 lines (computation) create_abstraction_txt.d: -10 lines (simplified) Co-Authored-By: Anthropic Claude Opus 4.6 (1M context) --- src/sisudoc/io_out/create_abstraction_txt.d | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'src/sisudoc/io_out') diff --git a/src/sisudoc/io_out/create_abstraction_txt.d b/src/sisudoc/io_out/create_abstraction_txt.d index f92b83c..af98f61 100644 --- a/src/sisudoc/io_out/create_abstraction_txt.d +++ b/src/sisudoc/io_out/create_abstraction_txt.d @@ -162,16 +162,6 @@ template spineAbstractionTxt() { output ~= "}"; output ~= ""; - /+ ↓ pre-compute heading children map (one pass over body) +/ - int[][int] heading_children; // parent_ocn -> [child heading OCNs] - if ("body" in doc_abstraction) { - foreach (obj; doc_abstraction["body"]) { - if (obj.metainfo.is_a == "heading" && obj.metainfo.parent_ocn != 0) { - heading_children[obj.metainfo.parent_ocn] ~= obj.metainfo.ocn; - } - } - } - /+ ↓ document sections +/ string[] section_order = ["head", "toc", "body", "endnotes", "glossary", "bibliography", "bookindex", "blurb"]; @@ -212,9 +202,9 @@ template spineAbstractionTxt() { output ~= ".last_descendant: " ~ obj.metainfo.last_descendant_ocn.to!string; /+ ↓ child headings (from pre-computed map) +/ - if (obj.metainfo.is_a == "heading" && obj.metainfo.ocn in heading_children) { + if (obj.metainfo.children_headings.length > 0) { string[] ch; - foreach (c; heading_children[obj.metainfo.ocn]) { + foreach (c; obj.metainfo.children_headings) { ch ~= c.to!string; } output ~= ".children: " ~ ch.join(" "); -- cgit v1.2.3