github.com/kelleygo/clashcore@v1.0.2/common/arc/entry.go (about)

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