{"id":23181466,"url":"https://github.com/barrenszeppelin/pmmap","last_synced_at":"2025-09-01T17:45:14.472Z","repository":{"id":144424788,"uuid":"487881724","full_name":"BarrensZeppelin/pmmap","owner":"BarrensZeppelin","description":"Go implemenation of Persistent Mergeable Hash Maps","archived":false,"fork":false,"pushed_at":"2023-08-18T20:17:57.000Z","size":41,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-10T11:21:21.153Z","etag":null,"topics":["data-structures","go","hashmap","immutable","tree"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BarrensZeppelin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-02T14:45:45.000Z","updated_at":"2022-05-24T19:53:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"8a6b7001-a467-42fd-8488-537c4fab01ec","html_url":"https://github.com/BarrensZeppelin/pmmap","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BarrensZeppelin%2Fpmmap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BarrensZeppelin%2Fpmmap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BarrensZeppelin%2Fpmmap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BarrensZeppelin%2Fpmmap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BarrensZeppelin","download_url":"https://codeload.github.com/BarrensZeppelin/pmmap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247280263,"owners_count":20912967,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-structures","go","hashmap","immutable","tree"],"created_at":"2024-12-18T08:15:59.585Z","updated_at":"2025-04-05T03:15:43.602Z","avatar_url":"https://github.com/BarrensZeppelin.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Persistent Mergeable Hash Map (pmmap)\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/BarrensZeppelin/pmmap.svg)](https://pkg.go.dev/github.com/BarrensZeppelin/pmmap)\n\nThis package provides a Go implementation of a persistent key-value hash map with an efficient _merge_ operation.\n\nThe maps are immutable, so modifying operations (inserts and removals) return a copy of the map with the operation applied.\n\nThe backing data structure is a [patricia trie](https://en.wikipedia.org/wiki/Radix_tree#PATRICIA) on key hashes.\n\n## Usage\n\nThe map uses generics to make the API ergonomic. Therefore Go 1.18+ is required.\n\nInstall: `go get github.com/BarrensZeppelin/pmmap`\n\n```go\nhasher := pmmap.NumericHasher[int]()\nmap0 := pmmap.New[string](hasher)\nmap1 := map0.Insert(42, \"Hello World\")\nfmt.Println(map0.Lookup(42)) // \"\", false\nfmt.Println(map1.Lookup(42)) // \"Hello World\", true\n```\n\nTo create a map with key type `K` you must supply an implementation of `Hasher[K]`:\n\n```go\ntype Hasher[K any] interface {\n\tEqual(a, b K) bool\n\tHash(K) uint64\n}\n```\n\nDefault hasher implementations are included for numeric types and strings.\n\n## Merges\n\nThe hash maps support a merge operation that will join the key-value pairs in two maps into a single map.\nThis operation is made efficient by:\n\n* Re-using substructures from the two merged maps when possible.\n\n\tFor instance, merging a map with an empty map returns the first map directly without traversing any of its elements.\n\n* Skipping processing of shared substructures.\n\n\tFor instance, merging a map with itself always takes constant time.\n\nRe-using shared substructures in merged maps drastically reduces memory usage and execution time of the merge operation.\nGenerally, merging a map with a version of the map with $r$ new insertions will take linear time in $r$ (indepedent of the size of the map, compared to looping over one of the maps).\n\nWhen the merged maps both contain a mapping for a key, the mapped values are merged with a user-provided value merging binary operator $f$.\nThis operator must be commutative and idempotent:\n\n$$\n\\forall a, b. f(a, b) = f(b, a) \\textrm{ and } f(a, a) = a\n$$\n\n```go\nmap2 := map0.Insert(42, \"Hello Wzrld\").Insert(43, \"Goodbye\")\nfmt.Println(\n\tmap1.Merge(map2, func(a, b string) (string, bool) {\n\t\t// Return the lexicographically smallest string\n\t\tif a \u003e b {\n\t\t\ta, b = b, a\n\t\t}\n\t\treturn a, a == b\n\t})\n) // [42 ↦ Hello World 43 ↦ Goodbye]\n```\n\nThe returned flag should be `true` iff. the two values are equal.\nThis allows the implementation to re-use more substructures.\n\n## Benchmarks\n\nThe project includes some performance benchmarks that compare the speed of insert and lookup operations to that of Go's builtin `map` implementation.\nInserts are roughly 8-10 times slower than the builtin map and lookups are roughly 6 times slower.\nThis map implementation is not a good general-purpose replacement for hash maps.\nIt is most useful when the merge operation is used to speed up merges of large maps and when large maps must be copied (which is essentially free due to immutability).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarrenszeppelin%2Fpmmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbarrenszeppelin%2Fpmmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarrenszeppelin%2Fpmmap/lists"}