LRU

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: 1 Imported by: 0

Documentation

Overview

Example
package main

import "fmt"

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

func main() {
	lru_cache := Constructor(2)
	test_cases := []Command{
		{"put", []int{1, 1}, nil},
		{"put", []int{2, 2}, nil},
		{"get", []int{1}, 1},
		{"put", []int{3, 3}, nil},
		{"get", []int{2}, -1},
		{"put", []int{4, 4}, nil},
		{"get", []int{1}, -1},
		{"get", []int{3}, 3},
		{"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> 1 <nil> -1 <nil> -1 3 4]

Index

Examples

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 Constructor

func Constructor(capacity int) LRUCache

func (*LRUCache) Get

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

func (*LRUCache) Put

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

Jump to

Keyboard shortcuts

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