{"id":13397021,"url":"https://github.com/cornelk/hashmap","last_synced_at":"2025-05-14T09:06:25.137Z","repository":{"id":37615395,"uuid":"64799269","full_name":"cornelk/hashmap","owner":"cornelk","description":"A Golang lock-free thread-safe HashMap optimized for fastest read access.","archived":false,"fork":false,"pushed_at":"2025-03-09T17:22:56.000Z","size":243,"stargazers_count":1845,"open_issues_count":8,"forks_count":118,"subscribers_count":42,"default_branch":"main","last_synced_at":"2025-05-14T09:04:53.161Z","etag":null,"topics":["fast","go","golang","hashmap","lock-free","map","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cornelk.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,"zenodo":null}},"created_at":"2016-08-02T23:31:19.000Z","updated_at":"2025-05-08T13:18:44.000Z","dependencies_parsed_at":"2025-04-11T03:31:50.812Z","dependency_job_id":"1bd691d2-9734-46e5-a21d-c8f5a6890c7c","html_url":"https://github.com/cornelk/hashmap","commit_stats":{"total_commits":148,"total_committers":13,"mean_commits":"11.384615384615385","dds":0.1283783783783784,"last_synced_commit":"36b3b9c2b7ec993f1ef12a6957d45826aca726e6"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cornelk%2Fhashmap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cornelk%2Fhashmap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cornelk%2Fhashmap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cornelk%2Fhashmap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cornelk","download_url":"https://codeload.github.com/cornelk/hashmap/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254110374,"owners_count":22016391,"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":["fast","go","golang","hashmap","lock-free","map","thread-safe"],"created_at":"2024-07-30T18:01:09.521Z","updated_at":"2025-05-14T09:06:25.113Z","avatar_url":"https://github.com/cornelk.png","language":"Go","readme":"# hashmap\n\n[![Build status](https://github.com/cornelk/hashmap/actions/workflows/go.yaml/badge.svg?branch=main)](https://github.com/cornelk/hashmap/actions)\n[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white\u0026style=flat-square)](https://pkg.go.dev/github.com/cornelk/hashmap)\n[![Go Report Card](https://goreportcard.com/badge/github.com/cornelk/hashmap)](https://goreportcard.com/report/github.com/cornelk/hashmap)\n[![codecov](https://codecov.io/gh/cornelk/hashmap/branch/main/graph/badge.svg?token=NS5UY28V3A)](https://codecov.io/gh/cornelk/hashmap)\n\n## Overview\n\nA Golang lock-free thread-safe HashMap optimized for fastest read access.\n\nIt is not a general-use HashMap and currently has slow write performance for write heavy uses.\n\nThe minimal supported Golang version is 1.19 as it makes use of Generics and the new atomic package helpers.\n\n## Usage\n\nExample uint8 key map uses:\n\n```\nm := New[uint8, int]()\nm.Set(1, 123)\nvalue, ok := m.Get(1)\n```\n\nExample string key map uses:\n\n```\nm := New[string, int]()\nm.Set(\"amount\", 123)\nvalue, ok := m.Get(\"amount\")\n```\n\nUsing the map to count URL requests:\n```\nm := New[string, *int64]()\nvar i int64\ncounter, _ := m.GetOrInsert(\"api/123\", \u0026i)\natomic.AddInt64(counter, 1) // increase counter\n...\ncount := atomic.LoadInt64(counter) // read counter\n```\n\n## Benchmarks\n\nReading from the hash map for numeric key types in a thread-safe way is faster than reading from a standard Golang map\nin an unsafe way and four times faster than Golang's `sync.Map`:\n\n```\nReadHashMapUint-8                676ns ± 0%\nReadHaxMapUint-8                 689ns ± 1%\nReadGoMapUintUnsafe-8            792ns ± 0%\nReadXsyncMapUint-8               954ns ± 0%\nReadGoSyncMapUint-8             2.62µs ± 1%\nReadSkipMapUint-8               3.27µs ±10%\nReadGoMapUintMutex-8            29.6µs ± 2%\n```\n\nReading from the map while writes are happening:\n```\nReadHashMapWithWritesUint-8      860ns ± 1%\nReadHaxMapWithWritesUint-8       930ns ± 1%\nReadGoSyncMapWithWritesUint-8   3.06µs ± 2%\n```\n\nWrite performance without any concurrent reads:\n\n```\nWriteGoMapMutexUint-8           14.8µs ± 2%\nWriteHashMapUint-8              22.3µs ± 1%\nWriteGoSyncMapUint-8            69.3µs ± 0%\n```\n\nThe benchmarks were run with Golang 1.19.1 on Linux and a Ryzen 9 5900X CPU using `make benchmark-perflock`.\n\n## Technical details\n\n* Technical design decisions have been made based on benchmarks that are stored in an external repository:\n  [go-benchmark](https://github.com/cornelk/go-benchmark)\n\n* The library uses a sorted linked list and a slice as an index into that list.\n\n* The Get() function contains helper functions that have been inlined manually until the Golang compiler will inline them automatically.\n\n* It optimizes the slice access by circumventing the Golang size check when reading from the slice.\n  Once a slice is allocated, the size of it does not change.\n  The library limits the index into the slice, therefore the Golang size check is obsolete.\n  When the slice reaches a defined fill rate, a bigger slice is allocated and all keys are recalculated and transferred into the new slice.\n\n* For hashing, specialized xxhash implementations are used that match the size of the key type where available\n","funding_links":[],"categories":["Go","Misc","开源类库","Open source library","Backend frameworks \u0026 libraries","Repositories"],"sub_categories":["数据结构","Data Structure"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcornelk%2Fhashmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcornelk%2Fhashmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcornelk%2Fhashmap/lists"}