Skip to content

linxGnu/fimap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fimap

Build Status Go Report Card Coverage Status godoc

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

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

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
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