LFU

package
v0.0.0-...-187d52e Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Example
package main

import (
	"fmt"
	"std/github.com/AbdallaMourad/Cache/src/LFU"
)

type Command struct {
	method          string
	data            []int
	expected_result interface{}
}

func main() {
	lru_cache := LFU.Constructor(3)
	test_cases := []Command{
		{"put", []int{2, 2}, nil},
		{"put", []int{1, 1}, nil},
		{"get", []int{2}, 2},
		{"get", []int{1}, 1},
		{"get", []int{2}, 2},
		{"put", []int{3, 3}, nil},
		{"put", []int{4, 4}, nil},
		{"get", []int{3}, -1},
		{"get", []int{2}, 2},
		{"get", []int{1}, 1},
		{"get", []int{4}, 4},
	}

	results := make([]interface{}, len(test_cases))

	for i, test_case := range test_cases {
		if test_case.method == "put" {
			lru_cache.Put(test_case.data[0], test_case.data[1])
		} else {
			results[i] = lru_cache.Get(test_case.data[0])
		}
	}

	fmt.Println(results)

}
Output:

[<nil> <nil> 2 1 2 <nil> <nil> -1 2 1 4]

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LFUCache

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

func Constructor

func Constructor(capacity int) LFUCache

func (*LFUCache) Get

func (this *LFUCache) Get(key int) int

func (*LFUCache) Put

func (this *LFUCache) Put(key int, value int)

Jump to

Keyboard shortcuts

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