partmap

package module
v0.0.0-...-7593c80 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2023 License: MIT Imports: 5 Imported by: 0

README

Simple and fast partitioned map

Faster then writing to std map.

Project motivation

go test -bench=. -benchtime=3s

goos: darwin
goarch: amd64
pkg: github.com/vadimInshakov/partmap
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz

BenchmarkStd/set_std_concurrently-12                  3289076   1332 ns/op
BenchmarkSyncStd/set_sync_map_std_concurrently-12     2408612   1691 ns/op
BenchmarkPartitioned/set_partitioned_concurrently-12  13536134  408.6 ns/op <-

Usage:

m := partmap.NewPartitionedMapWithDefaultPartitioner(3) // 3 partitions
m.Set("key", 123)
value, err := m.Get("key")
if err != nil && !errors.Is(err, partmap.ErrNotFound) {
    panic(err)
}

println(value) // 123

if err := m.Del("key"); err != nil {
    panic(err)
}

https://pkg.go.dev/github.com/vadiminshakov/partmap

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyKey is returned when empty key is provided.
	ErrEmptyKey = errors.New("empty key provided")
	// ErrNotFound is returned when key is not found in map.
	ErrNotFound = errors.New("key not found")
)

Functions

func BenchmarkPartitioned

func BenchmarkPartitioned(b *testing.B)

func BenchmarkStd

func BenchmarkStd(b *testing.B)

func BenchmarkSyncStd

func BenchmarkSyncStd(b *testing.B)

Types

type HashSumPartitioner

type HashSumPartitioner struct {
	// contains filtered or unexported fields
}

func NewHashSumPartitioner

func NewHashSumPartitioner(partitionsNum uint) *HashSumPartitioner

func (*HashSumPartitioner) Find

func (h *HashSumPartitioner) Find(key string) (uint, error)

type PartitionedMap

type PartitionedMap struct {
	// contains filtered or unexported fields
}

PartitionedMap is a map that is partitioned into several maps.

func NewPartitionedMap

func NewPartitionedMap(partitioner partitioner, partsnum uint) *PartitionedMap

NewPartitionedMap creates new partitioned map with given partitioner and number of partitions.

func NewPartitionedMapWithDefaultPartitioner

func NewPartitionedMapWithDefaultPartitioner(partsnum uint) *PartitionedMap

NewPartitionedMapWithDefaultPartitioner creates new partitioned map with default partitioner and given number of partitions.

func (*PartitionedMap) Del

func (c *PartitionedMap) Del(key string) error

Del deletes value for given key.

func (*PartitionedMap) Get

func (c *PartitionedMap) Get(key string) (any, error)

Get returns value for given key.

func (*PartitionedMap) Set

func (c *PartitionedMap) Set(key string, value any) error

Set sets value for given key.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL