https://github.com/octu0/armap
HashMap on Arena
https://github.com/octu0/armap
arena-allocator hashmap hashset linked-list
Last synced: 3 months ago
JSON representation
HashMap on Arena
- Host: GitHub
- URL: https://github.com/octu0/armap
- Owner: octu0
- License: mit
- Created: 2024-11-21T12:04:00.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-11-25T09:26:38.000Z (about 1 year ago)
- Last Synced: 2025-07-06T07:04:10.440Z (6 months ago)
- Topics: arena-allocator, hashmap, hashset, linked-list
- Language: Go
- Homepage: https://pkg.go.dev/github.com/octu0/armap
- Size: 37.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `armap`
[](https://github.com/octu0/armap/blob/master/LICENSE)
[](https://pkg.go.dev/github.com/octu0/armap)
[](https://goreportcard.com/report/github.com/octu0/armap)
[](https://github.com/octu0/armap/releases)
HashMap on [Arena](https://github.com/ortuman/nuke)
features:
- [Generics](https://go.dev/doc/tutorial/generics) support
- `Map` and `Set`, `LinkedList` types
- Minimal GC overhead map implements
- `comparable` key hash function uses [maphash](https://github.com/dolthub/maphash)
## Installation
```bash
go get github.com/octu0/armap
```
## Example
```go
package main
import (
"fmt"
"github.com/octu0/armap"
)
func main() {
a := armap.NewArena(1024*1024, 4) // 1MB buffer size * 4
defer a.Release() // release memory
m := armap.NewMap[string, string](a, armap.WithCapacity(1000))
m.Set("hello", "world1")
v, ok := m.Get("hello")
fmt.Println(v, ok) // => world1 true
m.Set("hello", "world2")
v, ok = m.Get("hello")
fmt.Println(v, ok) // => world2 true
m.Clear() // reset map, reuse memory
v, ok = m.Get("hello")
fmt.Println(v, ok) // => "" false
}
```
## GC Benchmark
average GC time improved by ~200x.
```
$ go test -run=BenchmarkGC -bench=BenchmarkGC -benchtime=3x -v .
goos: darwin
goarch: amd64
pkg: github.com/octu0/armap
cpu: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
BenchmarkGCSet
BenchmarkGCSet/golangmap
armap_benchmark_test.go:92: min/avg/max/median = 59.526209ms/83.101306ms/270.682439ms/60.953085ms
armap_benchmark_test.go:92: min/avg/max/median = 59.485567ms/67.009433ms/125.832941ms/59.875661ms
BenchmarkGCSet/golangmap-8 3 223366544 ns/op
BenchmarkGCSet/armap
armap_benchmark_test.go:117: min/avg/max/median = 216.152µs/377.403µs/507.442µs/377.907µs
armap_benchmark_test.go:117: min/avg/max/median = 291.639µs/354.231µs/576.287µs/314.844µs
BenchmarkGCSet/armap-8 3 1353591775 ns/op
PASS
```
# License
MIT, see LICENSE file for details.