intern

package module
v0.0.0-...-6c62f75 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: BSD-3-Clause Imports: 6 Imported by: 16

README

go4.org/intern Go Reference

What

Package intern lets you make smaller comparable values by boxing a larger comparable value (such as a string header) down into a single globally unique pointer.

Docs: https://pkg.go.dev/go4.org/intern

Status

This package is mature and stable. However, it depends on the implementation details of the Go runtime. Use with care.

This package is a core, low-level package with no substantive dependencies.

We take code review, testing, dependencies, and performance seriously, similar to Go's standard library or the golang.org/x repos.

Motivation

Package intern was initially created for package inet.af/netaddr.

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.

The GitHub repo is https://github.com/go4org/intern

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Value

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

A Value pointer is the handle to an underlying comparable value. See func Get for how Value pointers may be used.

func Get

func Get(cmpVal interface{}) *Value

Get returns a pointer representing the comparable value cmpVal.

The returned pointer will be the same for Get(v) and Get(v2) if and only if v == v2, and can be used as a map key.

func GetByString

func GetByString(s string) *Value

GetByString is identical to Get, except that it is specialized for strings. This avoids an allocation from putting a string into an interface{} to pass as an argument to Get.

func (*Value) Get

func (v *Value) Get() interface{}

Get returns the comparable value passed to the Get func that returned v.

Jump to

Keyboard shortcuts

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