cache

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Strings = New(
		xxhash.Sum64String,
		func(s string) bool {

			return len(s) > 256
		},
		func(a, b string) bool { return a == b },
	)

	StringMaps = New(
		func(m map[string]string) (hash uint64) {
			for k, v := range m {
				_, hashk := Strings.get(k)
				_, hashv := Strings.get(v)
				hash = hash ^ hashk ^ hashv
			}
			return
		},
		func(m map[string]string) bool {

			return len(m) > 32
		},
		maps.Equal,
	)
)

Functions

This section is empty.

Types

type Cache

type Cache[T any] struct {
	// contains filtered or unexported fields
}

Cache is a simple fixed size cache for efficient deduplication of objects.

func New

func New[T any](hashfn func(T) uint64, skipfn func(x T) bool, eqfn func(a, b T) bool) *Cache[T]

func (*Cache[T]) Get

func (c *Cache[T]) Get(x T) T

Get a cached object if any. If Get() was called previously with an object equal to [x] and it is found from the cache then it is returned, otherwise [x] is inserted into cache.

Jump to

Keyboard shortcuts

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