-
Notifications
You must be signed in to change notification settings - Fork 2
/
lru_example_test.go
54 lines (46 loc) · 970 Bytes
/
lru_example_test.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
54
package collection_test
import (
"context"
"fmt"
"github.com/marstr/collection/v2"
)
func ExampleLRUCache() {
subject := collection.NewLRUCache[int, string](3)
subject.Put(1, "one")
subject.Put(2, "two")
subject.Put(3, "three")
subject.Put(4, "four")
fmt.Println(subject.Get(1))
fmt.Println(subject.Get(4))
// Output:
// false
// four true
}
func ExampleLRUCache_Enumerate() {
subject := collection.NewLRUCache[int, string](3)
subject.Put(1, "one")
subject.Put(2, "two")
subject.Put(3, "three")
subject.Put(4, "four")
for key := range subject.Enumerate(context.Background()) {
fmt.Println(key)
}
// Output:
// four
// three
// two
}
func ExampleLRUCache_EnumerateKeys() {
subject := collection.NewLRUCache[int, string](3)
subject.Put(1, "one")
subject.Put(2, "two")
subject.Put(3, "three")
subject.Put(4, "four")
for key := range subject.EnumerateKeys(context.Background()) {
fmt.Println(key)
}
// Output:
// 4
// 3
// 2
}