https://github.com/linxgnu/fimap
Fast map which takes uint64 as key.
https://github.com/linxgnu/fimap
fast golang key-value map uint64
Last synced: 10 months ago
JSON representation
Fast map which takes uint64 as key.
- Host: GitHub
- URL: https://github.com/linxgnu/fimap
- Owner: linxGnu
- License: apache-2.0
- Created: 2019-03-11T07:08:15.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-06-05T06:01:25.000Z (over 2 years ago)
- Last Synced: 2025-01-24T05:41:44.706Z (11 months ago)
- Topics: fast, golang, key-value, map, uint64
- Language: Go
- Homepage:
- Size: 22.5 KB
- Stars: 3
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fimap
[](https://travis-ci.org/linxGnu/fimap)
[](https://goreportcard.com/report/github.com/linxGnu/fimap)
[](https://coveralls.io/github/linxGnu/fimap?branch=master)
[](https://godoc.org/github.com/linxGnu/fimap)
A fast map that uses `uint64` for the index key and `interface{}` for the data, based on http://java-performance.info/implementing-world-fastest-java-int-to-int-hash-map/
It is 1.5-2X faster than the builtin map.
### Installing
To start using `fimap`, install Go and run `go get`:
```
go get -u github.com/linxGnu/fimap
```
### Example
```go
import "github.com/linxGnu/fimap"
// 1000: expect capacity
// 0.5: threshold. When cardinality >= threshold * capacity
// the map would grow 2x
s, _ := fimap.New(1000, 0.5)
// set
s.Set(123, struct{}{})
s.Set(345, 128)
// get
v, exist := s.Get(123)
// get number of elements in map
s.Size()
// create new map and clone from orginal
c := s.Clone()
// iterate
s.Iterate(func(key uint64, value interface{}) error {
// do some thing with key value
return nil // return non nil error if you want to stop iteration
})
```
### Benchmark
```scala
system_profiler SPHardwareDataType
Hardware:
Hardware Overview:
Model Name: MacBook Pro
Model Identifier: MacBookPro14,3
Processor Name: Intel Core i7
Processor Speed: 2.8 GHz
Number of Processors: 1
Total Number of Cores: 4
L2 Cache (per Core): 256 KB
L3 Cache: 6 MB
Memory: 16 GB
Boot ROM Version: 185.0.0.0.0
SMC Version (system): 2.45f0
```
```scala
goos: darwin
goarch: amd64
pkg: github.com/linxGnu/fimap
BenchmarkFIMapSmall-8 22826 52884 ns/op 98368 B/op 23 allocs/op
BenchmarkFIMapMedium-8 5 235211344 ns/op 201326656 B/op 45 allocs/op
BenchmarkFIMapLarge-8 1 1515300167 ns/op 805306432 B/op 49 allocs/op
BenchmarkMapSmall-8 13306 89721 ns/op 47813 B/op 65 allocs/op
BenchmarkMapMedium-8 3 406576060 ns/op 99906680 B/op 76844 allocs/op
BenchmarkMapLarge-8 1 2055357735 ns/op 403988760 B/op 306818 allocs/op
```