lru_map

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: Unlicense Imports: 4 Imported by: 0

README

lru_map

Extremely basic in-memory LRU cache, with the semantics of a generic map.

Reads and writes are O(1), by tracking key age using a linked list.

Documentation

Overview

Package lru_map implements an extremely basic in-memory LRU cache.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LRUMap

type LRUMap[K comparable, V any] interface {
	// Associate a value with a key in the map. If the map is full, the oldest
	// entry will be deleted.
	Set(K, V)
	// Retrieve the value associated with the given key. If the value is not
	// present, it will return false. This can happen either because the value
	// has not been set for the key, or its entry has been evicted.
	Get(K) (V, bool)
	// Remove an element from the map. This can improve efficiency as it allows
	// other objects to remain cached for longer.
	Drop(K)
	// Get all the keys present in the map.
	Keys() iter.Seq[K]
}

An LRUMap is a generic Map type, with an LRU eviction policy.

func New

func New[K comparable, V any](capacity int) LRUMap[K, V]

Create a new LRUMap, with a given fixed capacity.

Directories

Path Synopsis
A way worse implementation of LRUMap, its only function is to be so obvious in its implementation that its behavior is self-evidently correct, allowing it to be used as a reference in tests.
A way worse implementation of LRUMap, its only function is to be so obvious in its implementation that its behavior is self-evidently correct, allowing it to be used as a reference in tests.

Jump to

Keyboard shortcuts

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