Store IndexName tags as a sorted symbol dictionary#195
Merged
Conversation
A small `AbstractDict` backed by two parallel sorted vectors with linear-scan lookup, suited to the small key counts of index-name tags. Equality and hashing are structural over the sorted vectors, so they are cheap and order-independent by construction. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Back IndexName tags with the internal SortedDict{Symbol,Symbol} instead
of a Dict{String,String}. Symbol keys and values compare and hash faster
than strings, and the sorted backing makes equality, hashing, and
ordering plain vector operations with no per-call allocation.
IndexName comparison now short-circuits in id, then plev, then tags, so
distinct ids never touch the tags and comparing an index against a primed
or retagged copy of itself rejects on the prime level instead of walking
the full tag set.
The public tag API stays string-valued: gettag returns a String, tags
returns an AbstractDict from strings to strings, and settag/hastag and the
IndexName constructor accept either strings or symbols. An internal
tags_stored exposes the raw symbol dictionary for the comparison, hashing,
and display paths.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #195 +/- ##
==========================================
+ Coverage 72.67% 73.65% +0.97%
==========================================
Files 28 29 +1
Lines 1486 1545 +59
==========================================
+ Hits 1080 1138 +58
- Misses 406 407 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
33802aa to
aa8bead
Compare
settags no longer normalizes its argument: the IndexName tags field is
typed, so `@set` enforces the type on construction, and its only callers
(settag/unsettag) already build a SortedDict{Symbol,Symbol}. Split the
conversion into to_symbol_pair (convert one pair's key and value to
symbols) and to_tags, which accepts either a single bare Pair or a
collection of pairs by dispatch, mirroring how Dict's constructor handles
the same two shapes.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
aa8bead to
0f7c7ce
Compare
Replace the custom linear _searchsortedfirst, a misleading name for a linear scan, with findfirst, and drop the dead key/value converts. The keys stay sorted on insert, so lookups could later call searchsortedfirst for larger collections. Credit TensorKit.jl's SortedVectorDict as the model and note DataStructures.jl's SortedDict and Dictionaries.jl's ArrayDictionary as comparable designs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
45502b5 to
06454a5
Compare
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.
Summary
Stores
IndexNametags in a sorted, symbol-keyed dictionary instead of aDict{String, String}, which makes name comparison and hashing substantially faster while keeping the tag API string-based.The tag store is now an internal
SortedDict{Symbol, Symbol}, a smallAbstractDictbacked by two parallel sorted vectors with linear-scan lookup, suited to the handful of tags an index carries. Symbol keys and values compare and hash faster than strings, and the sorted backing makes equality, hashing, and ordering plain vector operations with no per-call allocation.IndexNamecomparison now also short-circuits inid, thenplev, then tags, so the common case of distinct ids never touches the tags, and comparing an index against a primed or retagged copy of itself rejects on the prime level instead of walking the full tag set.The public tag API stays string-valued:
gettagreturns aString,tagsreturns anAbstractDictfrom strings to strings, andsettag/hastagand theIndexNameconstructor accept either strings or symbols. An internaltags_storedexposes the raw symbol dictionary for the comparison, hashing, and display paths.