Repository navigation
Conversation
Map[K, V] is the consumer the trie was landed for. Keys only need to be comparable, so structs, arrays and pointers work, which is what sets it apart from Tree. Map maps the values and keeps the keys, which is Vavr's mapValues: mapping whole entries could merge keys and would not be a functor. Because no key changes, the result reuses the trie's exact shape and nothing is hashed again. Iteration order is unspecified, as for a Go map, but String sorts by key the way fmt does, so printing a Map is deterministic and usable in examples. There is no dedicated conversion to or from a Go map: CollectMap(maps.All(m)) and maps.Collect(m.All()) already cover both directions. Sharing is measured rather than claimed: a Put into a map of ten thousand entries allocates seven times, a Delete of an absent key allocates nothing, and the benchmarks show Put going from six to ten allocations while the map grows a thousandfold. Closes #5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
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
collection.Map[K comparable, V any], the consumer the CHAMP trie from #24 was landed for. Closes #5.API
EmptyMap,CollectMap(iter.Seq2[K, V])— last value wins on a repeated keyIsEmpty,Len— O(1)Get(returnscontrol.Option[V]),ContainsKey,Put,Delete— O(log32 n)All(iter.Seq2),Keys,Values(iter.Seq) — O(n)Map[U],Filter,Fold[U],StringDecisions
Mapmaps the values and keeps the keys — Vavr'smapValues. Mapping whole entries could merge keys and would not be a functor. No key changes, so the result reuses the trie's exact shape (champMapValues) and nothing is hashed again: O(n).Stringsorts by key the wayfmtdoes, so printing is deterministic and usable inExampletests.ToGoMap/FromGoMap:CollectMap(maps.All(m))andmaps.Collect(m.All())already cover both directions, shown inExampleCollectMap.NaNkey behaves as in a Go map (added, never found), pinned by a test against the built-in map.Sharing, measured
Putinto a map of 10 000 entries allocates 7 times; aDeleteof an absent key allocates nothing (TestMapSharesStructure).Putgoes from 6 to 10 allocations while the map grows from 1 000 to 1 000 000 entries;Getallocates nothing.Checks
gofmt,go vet,golangci-lint(0 issues),go test -race -cover ./..., the no-dependencygo listcheck, andgo mod tidyleavinggo.mod/go.sumunchanged.README gains a
Mapsection backed byExampleMapandExampleCollectMap.This change was prepared by an AI agent and may not have been independently reviewed or tested.
🤖 Generated with Claude Code