| 1 |
package lfu_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
|
| 6 |
"github.com/Code-Hex/go-generics-cache/policy/lfu" |
| 7 |
) |
| 8 |
|
| 9 |
func ExampleNewCache() { |
| 10 |
c := lfu.NewCache[string, int]() |
| 11 |
c.Set("a", 1) |
| 12 |
c.Set("b", 2) |
| 13 |
av, aok := c.Get("a") |
| 14 |
bv, bok := c.Get("b") |
| 15 |
cv, cok := c.Get("c") |
| 16 |
fmt.Println(av, aok) |
| 17 |
fmt.Println(bv, bok) |
| 18 |
fmt.Println(cv, cok) |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
} |
| 24 |
|
| 25 |
func ExampleCache_Keys() { |
| 26 |
c := lfu.NewCache[string, int]() |
| 27 |
c.Set("a", 1) |
| 28 |
c.Set("b", 2) |
| 29 |
c.Set("c", 3) |
| 30 |
keys := c.Keys() |
| 31 |
for _, key := range keys { |
| 32 |
fmt.Println(key) |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
} |