1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-06 21:52:28 +08:00

doc: update document for algorithm package

This commit is contained in:
dudaodong
2022-12-29 15:32:47 +08:00
parent 39c576248c
commit b5f7b0e670
6 changed files with 88 additions and 33 deletions

View File

@@ -570,6 +570,8 @@ func main() {
func NewLRUCache[K comparable, V any](capacity int) *LRUCache[K, V]
func (l *LRUCache[K, V]) Get(key K) (V, bool)
func (l *LRUCache[K, V]) Put(key K, value V)
func (l *LRUCache[K, V]) Delete(key K) bool
func (l *LRUCache[K, V]) Len() int
```
<b>Example:</b>
@@ -586,10 +588,14 @@ func main() {
cache.Put(1, 1)
cache.Put(2, 2)
cache.Put(3, 3)
_, ok := cache.Get(0) // ok -> false
fmt.Println(cache.Len()) // 3
v, ok := cache.Get(1) // v->1, ok->true
v, ok := cache.Get(1)
fmt.Println(v, ok) // 1 true
ok = cache.Delete(1)
fmt.Println(ok) // true
}
```