lfu

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2019 License: MIT Imports: 2 Imported by: 0

README

lfu

Thead-safe Least Frequently Used (LFU) cache replacement policy implementation with O(1) complexity

Build Status Go Report Card Coverage Status godoc GitHub release

Usages

capacity = 10
// create a new LFU cache with capacity
// if capacity is set to non-positive integer
// the cache won't do any eviction
lfu := lfu.New(capacity)

// set k, v
lfu.Set("k1", "v1")

// get v for k
v, ok := lfu.Get("k1")

// evict certain number of items
lfu.Evict(1)

// get current size of lfu
size := lfu.Size()

References

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LFU

type LFU interface {
	Set(k string, v interface{})
	Get(k string) (v interface{}, ok bool)
	Evict(n int)
	Size() int
}

LFU interface defines the operations that an lfu implementation should support

func New

func New(cap int) LFU

New create a new lfu-cache that support the LFU interface. The cap parameter specifies the capacity of the LFU cache

Jump to

Keyboard shortcuts

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