Created
August 9, 2020 02:18
-
-
Save suntong/03d437e21c3ab62149759018eda73468 to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"github.com/hashicorp/golang-lru/simplelru" | |
"log" | |
) | |
func main() { | |
log.Println("Hello, playground") | |
evictCounter := 0 | |
onEvicted := func(k interface{}, v interface{}) { | |
if k != v { | |
log.Fatalf("Evict values not equal (%v!=%v)", k, v) | |
} | |
evictCounter++ | |
} | |
l, err := simplelru.NewLRU(128, onEvicted) | |
if err != nil { | |
log.Fatalf("err: %v", err) | |
} | |
for i := 0; i < 256; i++ { | |
l.Add(i, i) | |
} | |
if l.Len() != 128 { | |
log.Fatalf("bad len: %v", l.Len()) | |
} | |
if evictCounter != 128 { | |
log.Fatalf("bad evict count: %v", evictCounter) | |
} | |
for i, k := range l.Keys() { | |
if v, ok := l.Get(k); !ok || v != k || v != i+128 { | |
log.Fatalf("bad key: %v", k) | |
} | |
log.Println(i, k) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment