Documentation ¶
Overview ¶
Package intern lets you make smaller comparable values by boxing a larger comparable value (such as a 16 byte string header) down into a globally unique 8 byte pointer.
The globally unique pointers are garbage collected with weak references and finalizers. This package hides that.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type StringInterner ¶
type StringInterner struct {
// contains filtered or unexported fields
}
StringInterner interns strings while allowing them to be cleaned up by the GC. It can handle both string and []byte types without allocation.
func NewStringInterner ¶
func NewStringInterner() *StringInterner
NewStringInterner creates a new StringInterner
func (*StringInterner) Get ¶
func (s *StringInterner) Get(k []byte) *StringValue
Get returns a pointer representing the []byte k
The returned pointer will be the same for Get(v) and Get(v2) if and only if v == v2. The returned pointer will also be the same for a string with same contents as the byte slice.
func (*StringInterner) GetString ¶
func (s *StringInterner) GetString(k string) *StringValue
GetString returns a pointer representing the string k
The returned pointer will be the same for GetString(v) and GetString(v2) if and only if v == v2. The returned pointer will also be the same for a byte slice with same contents as the string.
type StringValue ¶
type StringValue struct {
// contains filtered or unexported fields
}
A StringValue pointer is the handle to the underlying string value. See Get how Value pointers may be used.