hack

package
v1.1.0-beta.0...-2774ccb Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefBucketMemoryUsageForMapStringToAny = 312
	DefBucketMemoryUsageForSetString      = 248
	DefBucketMemoryUsageForSetFloat64     = 184
	DefBucketMemoryUsageForSetInt64       = 184
)

Memory usage constants for swiss map

Variables

This section is empty.

Functions

func GetBytesFromPtr

func GetBytesFromPtr(ptr unsafe.Pointer, length int) []byte

GetBytesFromPtr return a bytes array from the given ptr and length

func Slice

func Slice(s string) []byte

Slice converts string to slice without copy. Use at your own risk.

Types

type MemAwareMap

type MemAwareMap[K comparable, V any] struct {
	M map[K]V

	Bytes uint64
	// contains filtered or unexported fields
}

MemAwareMap is a map with memory usage tracking.

func NewMemAwareMap

func NewMemAwareMap[K comparable, V any](capacity int) *MemAwareMap[K, V]

NewMemAwareMap creates a new MemAwareMap with the given initial capacity.

func (*MemAwareMap[K, V]) Count

func (m *MemAwareMap[K, V]) Count() int

Count returns the number of elements in the map.

func (*MemAwareMap[K, V]) Empty

func (m *MemAwareMap[K, V]) Empty() bool

Empty returns true if the map is empty.

func (*MemAwareMap[K, V]) Exist

func (m *MemAwareMap[K, V]) Exist(val K) bool

Exist returns true if the key exists in the map.

func (*MemAwareMap[K, V]) Get

func (m *MemAwareMap[K, V]) Get(k K) (v V, ok bool)

Get the value of the key.

func (*MemAwareMap[K, V]) Init

func (m *MemAwareMap[K, V]) Init(v map[K]V) int64

Init initializes the MemAwareMap with the given map and returns the initial memory size. The input map should NOT be nil.

func (*MemAwareMap[K, V]) Len

func (m *MemAwareMap[K, V]) Len() int

Len returns the number of elements in the map.

func (*MemAwareMap[K, V]) MockSeedForTest

func (m *MemAwareMap[K, V]) MockSeedForTest(seed uint64) (oriSeed uint64)

MockSeedForTest sets the seed of the swissMap inside MemAwareMap

func (*MemAwareMap[K, V]) RealBytes

func (m *MemAwareMap[K, V]) RealBytes() uint64

RealBytes returns the real memory size of the map. Compute the real size is expensive, so do not call it frequently. Make sure the `seed` is same when testing the memory size.

func (*MemAwareMap[K, V]) Set

func (m *MemAwareMap[K, V]) Set(key K, value V) (deltaBytes int64)

Set sets the value for the key in the map and returns the memory delta.

func (*MemAwareMap[K, V]) SetExt

func (m *MemAwareMap[K, V]) SetExt(key K, value V) (deltaBytes int64, insert bool)

SetExt sets the value for the key in the map and returns the memory delta and whether it's an insert.

type MutableString

type MutableString string

MutableString can be used as string via string(MutableString) without performance loss.

func String

func String(b []byte) MutableString

String converts slice to MutableString without copy. The MutableString can be converts to string without copy. Use it at your own risk.

type SwissMapWrap

type SwissMapWrap struct {
	Type *swissMapType
	Data *swissMap
}

SwissMapWrap is a wrapper of map to access its internal structure.

func ToSwissMap

func ToSwissMap[K comparable, V any](m map[K]V) (sm SwissMapWrap)

ToSwissMap converts a map to SwissMapWrap.

func (*SwissMapWrap) Size

func (m *SwissMapWrap) Size() uint64

Size returns the accurate memory size

Jump to

Keyboard shortcuts

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