I needed deterministic map iteration order for my deterministic simulation testing (using the new testing/synctest package -- experimental in go1.24, but proposal approved to move forward, yay!) so I wrote a "dmap" which provides repeatably ordered full range scan for keys that can be turned into strings.
The cost is about 3x the memory. However since dmap is an order of magnitude faster than the built in Go map for repeated full- range scans, dmap still may be of general interest: https://github.com/glycerine/rpc25519/blob/master/dmap.go https://github.com/glycerine/rpc25519/blob/master/dmap_test.go You would need to extract these two files from the larger project (a few seconds work). Enjoy. go test -v -bench=BenchmarkDmapVsBuiltin -run=blah faketime = false goos: darwin goarch: amd64 pkg: github.com/glycerine/rpc25519 cpu: Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz BenchmarkDmapVsBuiltin BenchmarkDmapVsBuiltin/Set BenchmarkDmapVsBuiltin/Set/Dmap BenchmarkDmapVsBuiltin/Set/Dmap-8 48343575 22.36 ns/op BenchmarkDmapVsBuiltin/Set/Builtin BenchmarkDmapVsBuiltin/Set/Builtin-8 75154516 15.51 ns/op BenchmarkDmapVsBuiltin/Get BenchmarkDmapVsBuiltin/Get/Dmap BenchmarkDmapVsBuiltin/Get/Dmap-8 62711772 18.13 ns/op BenchmarkDmapVsBuiltin/Get/Builtin BenchmarkDmapVsBuiltin/Get/Builtin-8 100000000 10.89 ns/op BenchmarkDmapVsBuiltin/Delete BenchmarkDmapVsBuiltin/Delete/Dmap BenchmarkDmapVsBuiltin/Delete/Dmap-8 3335937 359.3 ns/op BenchmarkDmapVsBuiltin/Delete/Builtin BenchmarkDmapVsBuiltin/Delete/Builtin-8 27277524 39.09 ns/op BenchmarkDmapVsBuiltin/Range BenchmarkDmapVsBuiltin/Range/Dmap BenchmarkDmapVsBuiltin/Range/Dmap-8 316316 3477 ns/op << nice BenchmarkDmapVsBuiltin/Range/Dmap_ordercache BenchmarkDmapVsBuiltin/Range/Dmap_ordercache-8 2099700 560.4 ns/op << very nice BenchmarkDmapVsBuiltin/Range/Builtin BenchmarkDmapVsBuiltin/Range/Builtin-8 144405 7922 ns/op PASS ok github.com/glycerine/rpc25519 11.701s -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/b29c771b-f730-4cee-b0ab-ccedfea099fen%40googlegroups.com.