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.