-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jimchen
committed
Aug 22, 2024
1 parent
8bd5b76
commit 5bd2c25
Showing
15 changed files
with
731 additions
and
493 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/lovelysunlight/lru-go" | ||
) | ||
|
||
func main() { | ||
cache, _ := lru.New[string, string](2) | ||
cache.Put("apple", "red") | ||
cache.Put("banana", "yellow") | ||
|
||
var ( | ||
r, v string | ||
ok bool | ||
) | ||
|
||
r, ok = cache.Get("apple") | ||
fmt.Printf("Get() found: %v, value: %q\n", ok, r) | ||
|
||
r, ok = cache.Get("banana") | ||
fmt.Printf("Get() found: %v, value: %q\n", ok, r) | ||
|
||
r, ok = cache.Get("pear") | ||
fmt.Printf("Get() found: %v, value: %q\n", ok, r) | ||
|
||
r, ok = cache.Peek("apple") | ||
fmt.Printf("Peek() found: %v, value: %q\n", ok, r) | ||
|
||
r, ok = cache.Peek("banana") | ||
fmt.Printf("Peek() found: %v, value: %q\n", ok, r) | ||
|
||
r, ok = cache.Peek("pear") | ||
fmt.Printf("Peek() found: %v, value: %q\n", ok, r) | ||
|
||
r, ok = cache.Pop("banana") | ||
fmt.Printf("Pop() found: %v, value: %q\n", ok, r) | ||
|
||
r, v, ok = cache.RemoveOldest() | ||
fmt.Printf("RemoveOldest() found: %v, key: %q, value: %q\n", ok, r, v) | ||
|
||
fmt.Printf("Len() = : %v\n", cache.Len()) | ||
fmt.Printf("Cap() = : %v\n", cache.Cap()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.