lru

package module
v0.0.0-...-cec346d Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2020 License: MIT Imports: 1 Imported by: 0

README

Golang LRU Cache

Simple implementation using container/list and map

Example

import github.com/duyquang6/go-lru-cache

func example() {
	cache := lru.NewLRUCache(2)     // initialize new cache with cap = 2
	cache.Put("one", 1)   
	cache.Put("two", 2)
	log.Println(cache.Get("one"))   // return 1
	cache.Put("three", 3)
	log.Println(cache.Get("two"))   // return -1
	cache.Put("four", 4)
	log.Println(cache.Get(1))       // return -1
	log.Println(cache.Get(3))
	log.Println(cache.Get(4))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LRUCache

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

func NewLRUCache

func NewLRUCache(capacity int) LRUCache

func (*LRUCache) Get

func (this *LRUCache) Get(key string) interface{}

func (*LRUCache) Put

func (this *LRUCache) Put(key string, value interface{})

type Node

type Node struct {
	Key string
	Val interface{}
}

Jump to

Keyboard shortcuts

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