Package intmap implements a fast integer keyed map. Map data is kept densely packed in order to improve data locality.
Set and Get operations are consistently faster than the builtin map[int]interface{}: Get takes from 25 to 50% less time, depending on CPU architecture and map size. On some CPUs like an AMD FX, there is even an actual drop off point in map size (~16384) where the builtin map gets slightly faster.
Benchmark sample (*Builtin are performed using a regular map[int]interface{}):
BenchmarkIntMapSet-6 28105802 37.53 ns/op
BenchmarkBuiltinMapSet-6 21551445 53.44 ns/op
BenchmarkIntMapGet-6 35170137 33.10 ns/op
BenchmarkBuiltinMapGet-6 26973751 44.79 ns/op
BenchmarkIntMapDelete-6 33600421 32.16 ns/op
BenchmarkBuiltinMapDelete-6 38036679 28.68 ns/op
The delete test is wrong since we end up deleting millions of non-existent keys, which is not a typical use case. Regardless, deletes are slower than with the builtin map.
The implementation is based on http://java-performance.info/implementing-world-fastest-java-int-to-int-hash-map/.
The stored values can be of any type.