mapf

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2025 License: MIT Imports: 7 Imported by: 0

README

mapfactory

mapf is a mapfactory. It provide a uniq interface for various type of map engines. currently it supports two map engines: GoMap, GoSycMap, WeakMap and BigMap(bigtype.Map). However its extensible and new map engines can be appended easily. mapfactory just provides simple and basic maps (not parallel or thread-safe concurrent maps like sync.map). Because concurrency is different thing and any simple basic map can be used with concurrent solutions.

usage

any application that is using go standard map[K]V; can replace mapfactory to switch between map enginges easily.

example

m1 := mapf.NewMap[int, string](mapf.GoMap),
m2 := mapf.NewMap[string, float](mapf.BigMap) //, hintSize, kMarshaler, vMarshaler, checkCollision),

m1.Set(10, "ten")
m2.Set("Pi", 3.14)

v, ok := m1.Get(10)  // ten, true
_, ok = m2.Get("pi") // 0, false 

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

type Map[K comparable, V any] interface {
	Set(key K, value V)
	Get(key K) (value V, ok bool)
	Len() int
	Seq(func(key K, value V) bool)
	Delete(key K)
}

func NewMap

func NewMap[K comparable, V any](engine MapEngine, options ...any) Map[K, V]

func NewWeakMap

func NewWeakMap[K comparable, PV interface{ *V }, V any]() Map[K, PV]

type MapEngine

type MapEngine int
const (
	NotDefinedMap MapEngine = iota
	GoMap
	GoWeakMap
	GoSyncMap
	BigMap
)

func (MapEngine) String

func (e MapEngine) String() string

type WeakMap

type WeakMap[K comparable, PV interface{ *V }, V any] struct {
	// contains filtered or unexported fields
}

func (*WeakMap[K, PV, V]) Delete

func (wm *WeakMap[K, PV, V]) Delete(key K)

func (*WeakMap[K, PV, V]) Get

func (wm *WeakMap[K, PV, V]) Get(key K) (PV, bool)

func (*WeakMap[K, PV, V]) Len

func (wm *WeakMap[K, PV, V]) Len() int

func (*WeakMap[K, PV, V]) Seq

func (wm *WeakMap[K, PV, V]) Seq(f func(key K, value PV) bool)

func (*WeakMap[K, PV, V]) Set

func (wm *WeakMap[K, PV, V]) Set(key K, value PV)

Jump to

Keyboard shortcuts

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