{"id":13562441,"url":"https://github.com/alphadose/haxmap","last_synced_at":"2025-05-14T14:08:59.859Z","repository":{"id":54476488,"uuid":"522381412","full_name":"alphadose/haxmap","owner":"alphadose","description":"Fastest and most memory efficient golang concurrent hashmap","archived":false,"fork":false,"pushed_at":"2024-10-27T06:58:37.000Z","size":147,"stargazers_count":987,"open_issues_count":11,"forks_count":50,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-04-11T23:56:22.534Z","etag":null,"topics":["concurrent","fast","go","golang","hashmap","lock-free","map","memory-efficient","thread-safe"],"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/alphadose.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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-08-08T02:36:05.000Z","updated_at":"2025-04-10T20:57:01.000Z","dependencies_parsed_at":"2023-12-19T06:57:46.745Z","dependency_job_id":"b7183ed8-e065-4a9b-892d-8d7e0bdfc02d","html_url":"https://github.com/alphadose/haxmap","commit_stats":{"total_commits":85,"total_committers":7,"mean_commits":"12.142857142857142","dds":0.2941176470588235,"last_synced_commit":"fae115ca090791375c15c5c5188bba8428a08cf4"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphadose%2Fhaxmap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphadose%2Fhaxmap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphadose%2Fhaxmap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphadose%2Fhaxmap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alphadose","download_url":"https://codeload.github.com/alphadose/haxmap/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254160132,"owners_count":22024567,"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":["concurrent","fast","go","golang","hashmap","lock-free","map","memory-efficient","thread-safe"],"created_at":"2024-08-01T13:01:08.644Z","updated_at":"2025-05-14T14:08:54.849Z","avatar_url":"https://github.com/alphadose.png","language":"Go","readme":"# HaxMap\n\n[![GoDoc](https://godoc.org/github.com/alphadose/haxmap/svc?status.svg)](https://pkg.go.dev/github.com/alphadose/haxmap)\n[![Main Actions Status](https://github.com/alphadose/haxmap/workflows/Go/badge.svg)](https://github.com/alphadose/haxmap/actions)\n[![Go Report Card](https://goreportcard.com/badge/github.com/alphadose/haxmap)](https://goreportcard.com/report/github.com/alphadose/haxmap)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE.md)\n\u003e A lightning fast concurrent hashmap\n\nThe hashing algorithm used was [xxHash](https://github.com/Cyan4973/xxHash) and the hashmap's buckets were implemented using [Harris lock-free list](https://www.cl.cam.ac.uk/research/srg/netos/papers/2001-caslists.pdf)\n\n## Installation\n\nYou need Golang [1.18.x](https://go.dev/dl/) or above\n\n```bash\n$ go get github.com/alphadose/haxmap\n```\n\n## Usage\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/alphadose/haxmap\"\n)\n\nfunc main() {\n\t// initialize map with key type `int` and value type `string`\n\tmep := haxmap.New[int, string]()\n\n\t// set a value (overwrites existing value if present)\n\tmep.Set(1, \"one\")\n\n\t// get the value and print it\n\tval, ok := mep.Get(1)\n\tif ok {\n\t\tprintln(val)\n\t}\n\n\tmep.Set(2, \"two\")\n\tmep.Set(3, \"three\")\n\tmep.Set(4, \"four\")\n\n\t// ForEach loop to iterate over all key-value pairs and execute the given lambda\n\tmep.ForEach(func(key int, value string) bool {\n\t\tfmt.Printf(\"Key -\u003e %d | Value -\u003e %s\\n\", key, value)\n\t\treturn true // return `true` to continue iteration and `false` to break iteration\n\t})\n\n\tmep.Del(1) // delete a value\n\tmep.Del(0) // delete is safe even if a key doesn't exists\n\n\t// bulk deletion is supported too in the same API call\n\t// has better performance than deleting keys one by one\n\tmep.Del(2, 3, 4)\n\n\tif mep.Len() == 0 {\n\t\tprintln(\"cleanup complete\")\n\t}\n}\n```\n\n## Benchmarks\n\nBenchmarks were performed against [golang sync.Map](https://pkg.go.dev/sync#Map) and the latest [cornelk-hashmap](https://github.com/cornelk/hashmap)\n\nAll results were computed from [benchstat](https://pkg.go.dev/golang.org/x/perf/cmd/benchstat) of 20 runs (code available [here](./benchmarks))\n\n1. Concurrent Reads Only\n```\nname                         time/op\nHaxMapReadsOnly-8            6.94µs ± 4%\nGoSyncMapReadsOnly-8         21.5µs ± 3%\nCornelkMapReadsOnly-8        8.39µs ± 8%\n```\n\n2. Concurrent Reads with Writes\n```\nname                         time/op\nHaxMapReadsWithWrites-8      8.23µs ± 3%\nGoSyncMapReadsWithWrites-8   25.0µs ± 2%\nCornelkMapReadsWithWrites-8  8.83µs ±20%\n\nname                         alloc/op\nHaxMapReadsWithWrites-8      1.25kB ± 5%\nGoSyncMapReadsWithWrites-8   6.20kB ± 7%\nCornelkMapReadsWithWrites-8  1.53kB ± 9%\n\nname                         allocs/op\nHaxMapReadsWithWrites-8         156 ± 5%\nGoSyncMapReadsWithWrites-8      574 ± 7%\nCornelkMapReadsWithWrites-8     191 ± 9%\n```\n\nFrom the above results it is evident that `haxmap` takes the least time, memory and allocations in all cases making it the best golang concurrent hashmap in this period of time\n\n## Tips\n\n1. HaxMap by default uses [xxHash](https://github.com/cespare/xxhash) algorithm, but you can override this and plug-in your own custom hash function. Beneath lies an example for the same.\n```go\npackage main\n\nimport (\n\t\"github.com/alphadose/haxmap\"\n)\n\n// your custom hash function\n// the hash function signature must adhere to `func(keyType) uintptr`\nfunc customStringHasher(s string) uintptr {\n\treturn uintptr(len(s))\n}\n\nfunc main() {\n\tm := haxmap.New[string, string]() // initialize a string-string map\n\tm.SetHasher(customStringHasher) // this overrides the default xxHash algorithm\n\n\tm.Set(\"one\", \"1\")\n\tval, ok := m.Get(\"one\")\n\tif ok {\n\t\tprintln(val)\n\t}\n}\n```\n\n2. You can pre-allocate the size of the map which will improve performance in some cases.\n```go\npackage main\n\nimport (\n\t\"github.com/alphadose/haxmap\"\n)\n\nfunc main() {\n\tconst initialSize = 1 \u003c\u003c 10\n\n\t// pre-allocating the size of the map will prevent all grow operations\n\t// until that limit is hit thereby improving performance\n\tm := haxmap.New[int, string](initialSize)\n\n\tm.Set(1, \"1\")\n\tval, ok := m.Get(1)\n\tif ok {\n\t\tprintln(val)\n\t}\n}\n```\n","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falphadose%2Fhaxmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falphadose%2Fhaxmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falphadose%2Fhaxmap/lists"}