-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (42 loc) · 831 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"fmt"
"go-lru/list"
)
func main() {
fmt.Println("LRU using doubly linked list")
lru := NewLRUCache(2)
lru.Put(1, 1)
lru.Put(2, 2)
fmt.Println(lru.Get(1))
lru.Put(3, 3)
fmt.Println(lru.Get(2))
lru.Put(4, 4)
fmt.Println(lru.Get(1))
fmt.Println(lru.Get(3))
fmt.Println(lru.Get(4))
fmt.Println("LRU using go inbuilt doubly linked list (container/list)")
llru := list.NewLRUCache(2)
llru.Put(1, 1)
llru.Put(2, 2)
fmt.Println(llru.Get(1))
llru.Put(3, 3)
fmt.Println(llru.Get(2))
llru.Put(4, 4)
fmt.Println(llru.Get(1))
fmt.Println(llru.Get(3))
fmt.Println(llru.Get(4))
}
// output
// LRU using doubly linked list
// 1
// -1
// -1
// 3
// 4
// LRU using go inbuilt doubly linked list (container/list)
// 1
// -1
// -1
// 3
// 4