Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more api in example #138

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 25 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,30 @@ import (
)

func main() {
l, _ := lru.New[int, any](128)
for i := 0; i < 256; i++ {
l.Add(i, nil)
}
if l.Len() != 128 {
panic(fmt.Sprintf("bad len: %v", l.Len()))
}
l, _ := lru.New[int, any](128)
for i := 0; i < 256; i++ {
l.Add(i, nil)
}

fmt.Printf("the lru length is %d\n", l.Len())

ok := l.Contains(127)
if !ok {
fmt.Printf("the key is not found\n")
}

val, ok := l.Get(129)
if ok {
fmt.Printf("the value is %v\n", val)
}

l.Resize(64)
fmt.Printf("the lru length is %d\n", l.Len())

// Output:
// the lru length is 128
// the key is not found
// the value is <nil>
// the lru length is 64
}
```