symbolizer

package
v3.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2025 License: AGPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package symbolizer provides a string interning mechanism to reduce memory usage by reusing identical strings.

The Symbolizer maintains a cache of strings and returns the same instance when the same string is requested multiple times. This reduces memory usage when dealing with repeated strings, such as label names or values. It is not thread safe.

When the cache exceeds the maximum size, a small percentage of entries are randomly discarded to keep memory usage under control.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Symbolizer

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

func New

func New(initialCapacity int, maxSize int) *Symbolizer

New creates a new Symbolizer with the given initial capacity and maximum size.

func (*Symbolizer) Get

func (s *Symbolizer) Get(name string) string

Get returns a string from the symbolizer. If the string is not in the cache, a clone is inserted into the cache and returned.

Get may delete some values from the cache prior to inserting a new value if the maximum size is exceeded.

func (*Symbolizer) Reset

func (s *Symbolizer) Reset()

Reset clears the cache and resets the Symbolizer to its initial state, maintaining the existing maxSize.

Jump to

Keyboard shortcuts

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