Documentation
¶
Index ¶
- Constants
- func GetBytesFromPtr(ptr unsafe.Pointer, length int) []byte
- func Slice(s string) []byte
- type MemAwareMap
- func (m *MemAwareMap[K, V]) Count() int
- func (m *MemAwareMap[K, V]) Empty() bool
- func (m *MemAwareMap[K, V]) Exist(val K) bool
- func (m *MemAwareMap[K, V]) Get(k K) (v V, ok bool)
- func (m *MemAwareMap[K, V]) Init(v map[K]V) int64
- func (m *MemAwareMap[K, V]) Len() int
- func (m *MemAwareMap[K, V]) MockSeedForTest()
- func (m *MemAwareMap[K, V]) RealBytes() uint64
- func (m *MemAwareMap[K, V]) Set(key K, value V) (deltaBytes int64)
- func (m *MemAwareMap[K, V]) SetExt(key K, value V) (deltaBytes int64, insert bool)
- type MutableString
- type SwissMapWrap
Constants ¶
const ( DefBucketMemoryUsageForMapStringToAny = 312 DefBucketMemoryUsageForSetString = 248 DefBucketMemoryUsageForSetFloat64 = 184 DefBucketMemoryUsageForSetInt64 = 184 )
Memory usage constants for swiss map
Variables ¶
This section is empty.
Functions ¶
func GetBytesFromPtr ¶
GetBytesFromPtr return a bytes array from the given ptr and length
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()
MockSeedForTest sets the seed of the swissMap for testing. It should only be used in tests and should not be called on maps that are already in use, as it may cause issues with map operations. The map should be empty before calling this function.
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