Conversation
TurkeyMan
force-pushed
the
ow/bimap
branch
12 times, most recently
from
August 25, 2026 09:19
d86c3f2 to
bd3fc87
Compare
TurkeyMan
marked this pull request as draft
September 14, 2026 04:17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a compact canonical-first
BiMap, compile-timeStaticBiMap, and packed runtime synthesis.BiMap!(K, V = void, has_reverse = true, has_ack = false)keeps unique K and V arrays independently sorted when reverse lookup is enabled.BiMapIndexesfor byte/ushort cross-index storage, widening, insertion, adjustment, and acknowledgement packing.V=voidmaps K directly to a linear or adopted ordinal without value storage.has_ackis enabled. Bit 0 stores acknowledgement and the ordinal occupies the remaining bits.const(char)[]API while storing sorted ushort offsets into aligned, length-prefixed packed character buffers.urt.algorithm.binary_search; repeated strings are deduplicated before packing.StaticBiMap!entriesaccepts eitherKVP!(K, V)[N]or plainK[N]; the latter emits an immutableBiMap!(K, void)whose ordinals follow declaration order. The template itself is the generated public scope:.mapis the immutable map and manifest.k2declis exact-width sorted-key-to-declaration metadata. Key and value strings share one aligned string block, and equal-width k2v/v2k tables share one concatenated map block.synthesise_bimap(entries, scratch = null)builds the same canonical representation from a complete runtime table. It qsorts source ordinals, deduplicates endpoints, performs one exact persistent allocation laid out as theBiMap, sorted endpoint arrays, packed strings, and cross maps, then returns aconst(BiMap*). Callers may supply the reusable ushort source-index workspace; the convenience path uses temporary memory.release_synthesised_bimap()releases the whole owned block once. Mutating APIs are unavailable through the const result.Static and runtime construction share source-index qsort, deduplication, string packing, and integer-map helpers. Endpoint-aware work instantiates only per endpoint type; integer-only helpers are non-template. The embedded build emits no runtime-synthesis functions when the runtime constructor is unused.
urt.si.unitnow usesStaticBiMap!(KVP!(string, ScaledUnit)[])for spelling lookup and canonical reverse lookup. The map owns its packed spelling strings; manifest.k2declis consumed only at CTFE to produce a 10-byte packed prefixability bitmap. The manifest spelling specs remain the CTFE parsing path because D cannot dereference pointers stored in an immutable static object during evaluation.On the BL808 M0 release build,
.textis0xe7fae,.rodatais0x239e8, andm0fw.binis 1,129,696 bytes. Relative to the pre-migration build, that is 88 bytes less text, 64 bytes less rodata, and a 192-byte smaller firmware image. The small lookup-layer inline hints are size-significant under LDC-Oz: removing them increased.textby 684 bytes and the image by 704 bytes, while restoring them returned the image exactly to this baseline.Tests cover dynamic, static, and runtime-synthesised maps; KVP and ordinal-only construction; narrow/wide and mixed-width storage; concatenated equal-width maps; canonical duplicate endpoints; acknowledgements; sparse ordinals; copied packed strings; embedded NULs; empty strings; CTFE construction; pointer keys; declaration-order output; const runtime ownership; and the complete unit parsing/formatting table. The forced Linux DMD suite passes 72/72 modules, and the BL808 M0 release build passes.