mmap

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: MIT Imports: 11 Imported by: 0

README

MMap - An Efficient & High Cardinality Hash Map that Lives inside Memcached Servers

Warning: This is an experimental package, and should NOT be used in production environments

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeBucketKeyString

func ComputeBucketKeyString[R RootKey, K Key](
	elemCount uint64,
	rootKey R, key K,
) string

ComputeBucketKeyString ...

func ComputeBucketKeyStringWithSeparator

func ComputeBucketKeyStringWithSeparator[R RootKey, K Key](
	elemCount uint64,
	rootKey R, key K,
	separator string,
) string

ComputeBucketKeyStringWithSeparator ...

func NewBucketUnmarshaler

func NewBucketUnmarshaler[T Value](
	unmarshaler item.Unmarshaler[T],
) func(data []byte) (Bucket[T], error)

NewBucketUnmarshaler ...

Types

type Bucket

type Bucket[T Value] struct {
	Values []T
}

Bucket ...

func (Bucket[T]) Marshal

func (b Bucket[T]) Marshal() ([]byte, error)

Marshal ...

type BucketKey

type BucketKey[R RootKey] struct {
	RootKey R
	SizeLog uint8
	Hash    uint64
	Sep     string // separator
}

BucketKey ...

func ComputeBucketKey

func ComputeBucketKey[R RootKey, K Key](
	elemCount uint64,
	rootKey R, key K,
	separator string,
) BucketKey[R]

ComputeBucketKey ...

func (BucketKey[R]) GetHashRange

func (k BucketKey[R]) GetHashRange() HashRange

GetHashRange ...

func (BucketKey[R]) String

func (k BucketKey[R]) String() string

String ...

type FillKey

type FillKey[R comparable] struct {
	RootKey R
	Range   HashRange
}

FillKey ...

type Filler

type Filler[T any, R any] func(ctx context.Context, rootKey R, hashRange HashRange) func() ([]T, error)

Filler ...

func NewMultiGetFiller

func NewMultiGetFiller[T any, R comparable, K Key](
	multiGetFunc func(ctx context.Context, keys []FillKey[R]) ([]T, error),
	getRootKey func(v T) R,
	getKey func(v T) K,
) Filler[T, R]

NewMultiGetFiller converts from function often using SELECT WHERE IN into a Filler[T, R] that allow to be passed to New

type HashRange

type HashRange struct {
	Begin uint64 // inclusive
	End   uint64 // inclusive
}

HashRange for range of value [begin, end] includes both ends More specific: begin <= h <= end For each hash value h

type Key

type Key interface {
	comparable
	Hash() uint64
}

Key child key constraint

type Map

type Map[T Value, R RootKey, K Key] struct {
	// contains filtered or unexported fields
}

Map ...

func New

func New[T Value, R RootKey, K Key](
	pipeline memproxy.Pipeline,
	unmarshaler item.Unmarshaler[T],
	filler Filler[T, R],
	getKeyFunc func(v T) K,
	options ...MapOption,
) *Map[T, R, K]

New ...

func (*Map[T, R, K]) Get

func (m *Map[T, R, K]) Get(
	ctx context.Context,
	elemCount uint64,
	rootKey R, key K,
) func() (Option[T], error)

Get from Map The elemCount need *NOT* be exact, but *MUST* be monotonically increasing Otherwise Map can return incorrect values

func (*Map[T, R, K]) GetItemStats

func (m *Map[T, R, K]) GetItemStats() item.Stats

GetItemStats returns the underlining item stats

type MapOption

type MapOption func(conf *mapConfig)

MapOption ...

func WithItemOptions

func WithItemOptions(options ...item.Option) MapOption

WithItemOptions ...

func WithSeparator

func WithSeparator(sep string) MapOption

WithSeparator ...

type Option

type Option[T any] struct {
	Valid bool
	Data  T
}

Option an optional value

type RootKey

type RootKey interface {
	item.Key

	// AvgBucketSizeLog returns the logarithm base 2 of expected average size per bucket
	// values should be between [0, 8]
	// value = 0 => average 1 element per bucket
	// value = 3 => average 8 elements per bucket
	AvgBucketSizeLog() uint8
}

RootKey constraints

type Value

type Value interface {
	item.Value
}

Value constraints

Jump to

Keyboard shortcuts

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