{"id":13714210,"url":"https://github.com/wdamron/amt","last_synced_at":"2025-04-30T01:31:54.743Z","repository":{"id":49063305,"uuid":"517092903","full_name":"wdamron/amt","owner":"wdamron","description":"Hash Array Mapped Trie (HAMT) implemented in Go (1.18+ generics)","archived":false,"fork":false,"pushed_at":"2022-07-27T02:30:00.000Z","size":39,"stargazers_count":67,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-05T21:34:03.123Z","etag":null,"topics":["data-structures","go","hamt","hash-map","hash-set","unsafe"],"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/wdamron.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}},"created_at":"2022-07-23T15:22:09.000Z","updated_at":"2025-02-17T16:20:21.000Z","dependencies_parsed_at":"2022-09-19T00:41:39.183Z","dependency_job_id":null,"html_url":"https://github.com/wdamron/amt","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wdamron%2Famt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wdamron%2Famt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wdamron%2Famt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wdamron%2Famt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wdamron","download_url":"https://codeload.github.com/wdamron/amt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251611560,"owners_count":21617420,"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","hamt","hash-map","hash-set","unsafe"],"created_at":"2024-08-02T23:01:54.891Z","updated_at":"2025-04-30T01:31:54.487Z","avatar_url":"https://github.com/wdamron.png","language":"Go","funding_links":[],"categories":["Repositories"],"sub_categories":[],"readme":"# package amt\n\nPackage `amt` implements the Hash Array Mapped Trie (HAMT) in Go (1.18+ generics).\n\nSee \"Ideal Hash Trees\" (Phil Bagwell, 2001) for an overview of the implementation, advantages,\nand disadvantages of HAMTs.\n\nThe AMT implementation has a natural cardinality of 16 for the root trie and all sub-tries;\neach AMT level is indexed by 4 hash bits. The depth of a map or set will be on the order of log16(N).\n\n**This package uses unsafe pointers/pointer-arithmetic extensively**, so it is inherently unsafe and not guaranteed\nto work today or tomorrow. Unsafe pointers enable a compact memory layout with fewer allocations, and effectively reduce\nthe depth of a map or set by reducing the number of pointers dereferenced along the path to a key or value.\nNo attention is paid to 32-bit architectures since it's now the year 2000, but compatibility may still be there.\n\nAn alternative approach, using an interface type to represent either a key-value pair or entry slice (sub-trie),\nhas a few drawbacks. Interface values are the size of 2 pointers (versus 1 when using unsafe pointers),\nwhich would increase the memory overhead for key-value/sub-trie entries by 50% (e.g. 24 bytes versus 16 bytes\non 64-bit architectures). If the interface value is assigned a slice of entries (sub-trie), a new allocation\n(the size of 3 pointers) is required for the slice-header before it can be wrapped into the interface value. \nAccessing an entry slice (sub-trie) through an interface value requires _(1)_ dereferencing the interface's data \npointer to get to the slice-header (among other things), then _(2)_ dereferencing the slice-header's data pointer \nto access an entry in the slice. Unsafe pointers eliminate the extra allocation and overhead of _(1)_, allowing \nentries to point directly to either a key-value struct or an array of entries. Generics enable a type-safe \nimplementation, where the key-value type of a map or set is fixed after instantiation.\n\n```go\nimport \"github.com/wdamron/amt\"\n```\n\n## More Info\n\n* [Paper (PDF): Ideal Hash Trees (Phil Bagwell, 2001)](https://lampwww.epfl.ch/papers/idealhashtrees.pdf)\n* [Docs (pkg.go.dev)](https://pkg.go.dev/github.com/wdamron/amt)\n* [Hash Array Mapped Trie (Wikipedia)](https://en.wikipedia.org/wiki/Hash_array_mapped_trie)\n\nThe memory layouts of Go interfaces and slices are detailed in the following articles:\n\n* [Go Data Structures: Interfaces (Russ Cox)](https://research.swtch.com/interfaces)\n* [Go Slices: usage and internals (Andrew Gerrand)](https://go.dev/blog/slices-intro)\n* [Go internals: invariance and memory layout of slices (Eli Bendersky)](https://eli.thegreenplace.net/2021/go-internals-invariance-and-memory-layout-of-slices/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwdamron%2Famt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwdamron%2Famt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwdamron%2Famt/lists"}