Skip to content

ErfanMomeniii/lfu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go version license version

lfu

lfu is a lightweight package that implements lfu cache algorithm in Go.

Documentation

Install

go get github.com/erfanmomeniii/lfu

Next, include it in your application:

import "github.com/erfanmomeniii/lfu"

Quick Start

The following example illustrates how to use this package

package main

import (
	"fmt"
	"github.com/erfanmomeniii/lru"
)

func main() {
	l := lru.New(2)
	// 2 is the size of lru (default 2000)
	
	l.Set("a", 12)
	l.Set("b", 13)
	
	fmt.Println(l.Get("a"))
	// 12
	
	l.Set("c", "hi")
	
	fmt.Println(l.Has("c"))
	// false
}

Usage

type Lfu

Lfu is an instantiation of the lfu.

func New

func New(size ...int64) *Lfu

New creates a new instance of a lfu.

func Set

func (l *Lfu) Set(key any, value any)

Set adds or updates with inputted key and value.

func Get

func (l *Lfu) Get(key any) any

Get returns the value associated with the inputted key.

func Has

func (l *Lfu) Has(key any) bool 

Has checks whether the key exists or not.

Contributing

Pull requests are welcome. For changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.