memoization

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HInt

type HInt int

func (HInt) Hash

func (h HInt) Hash() string

type HString

type HString string

func (HString) Hash

func (h HString) Hash() string

type Hasher

type Hasher interface {
	Hash() string
}

type MemoCache

type MemoCache[H Hasher, T any] struct {
	// contains filtered or unexported fields
}

MemoCache represents a cache with a set capacity that uses an LRU eviction policy.

func NewMemoCache

func NewMemoCache[H Hasher, T any](capacity int) *MemoCache[H, T]

NewMemoCache creates a new MemoCache given a certain capacity.

func (*MemoCache[H, T]) Capacity

func (m *MemoCache[H, T]) Capacity() int

func (*MemoCache[H, T]) Get

func (m *MemoCache[H, T]) Get(h H) (T, bool)

Get returns the value associated with the given hashable item. If there is no corresponding value, the method returns nil.

func (*MemoCache[H, T]) Set

func (m *MemoCache[H, T]) Set(h H, value T)

Set sets the value for the hashable item.

func (*MemoCache[H, T]) Size

func (m *MemoCache[H, T]) Size() int

Jump to

Keyboard shortcuts

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