entry.go 539 B

1234567891011121314151617181920212223242526272829303132
  1. package arc
  2. import (
  3. list "github.com/bahlo/generic-list-go"
  4. )
  5. type entry[K comparable, V any] struct {
  6. key K
  7. value V
  8. ll *list.List[*entry[K, V]]
  9. el *list.Element[*entry[K, V]]
  10. ghost bool
  11. expires int64
  12. }
  13. func (e *entry[K, V]) setLRU(list *list.List[*entry[K, V]]) {
  14. e.detach()
  15. e.ll = list
  16. e.el = e.ll.PushBack(e)
  17. }
  18. func (e *entry[K, V]) setMRU(list *list.List[*entry[K, V]]) {
  19. e.detach()
  20. e.ll = list
  21. e.el = e.ll.PushFront(e)
  22. }
  23. func (e *entry[K, V]) detach() {
  24. if e.ll != nil {
  25. e.ll.Remove(e.el)
  26. }
  27. }