lru

package module
v0.0.0-...-7b1a2e7 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2020 License: MIT Imports: 4 Imported by: 1

README

lru

Simple implementation of LRU caching algorithms

Usage:

import "fmt"

func main() {
	lru, _ := NewLRU(3, func(key string, value interface{}) {
		fmt.Println("Evicted")
		fmt.Println("Key ", key)
		fmt.Println("Value", value)
	})

	lru.Put("a", 1)
	lru.Print()

	lru.Put("b", 2)
	lru.Print()

	lru.Put("c", 3)
	lru.Print()

	lru.Put("d", 4)
	lru.Print()

	lru.Get("b")
	lru.Print()

	lru.Clear()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Get(key string) (interface{}, bool)
	Put(key string, value interface{}) (interface{}, bool)
	Clear()
	Len() int
	Contins(key string) interface{}
}

type Elem

type Elem struct {
	Key   string
	Value interface{}
}

type EvictCallback

type EvictCallback func(key string, value interface{})

type LRU

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

func NewLRU

func NewLRU(c int, f EvictCallback) (*LRU, error)

func (*LRU) All

func (lru *LRU) All() []*Elem

func (*LRU) Clear

func (lru *LRU) Clear()

func (*LRU) Contains

func (lru *LRU) Contains(key string) interface{}

func (*LRU) Get

func (lru *LRU) Get(key string) (interface{}, bool)

func (*LRU) Init

func (lru *LRU) Init(data []*Elem) bool

func (*LRU) Len

func (lru *LRU) Len() int

func (*LRU) Print

func (lru *LRU) Print()

func (*LRU) Put

func (lru *LRU) Put(key string, value interface{}) (interface{}, bool)

func (*LRU) Remove

func (lru *LRU) Remove(key string) bool

Jump to

Keyboard shortcuts

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