ecodeclub / ecache

统一缓存 API
Apache License 2.0
12 stars 15 forks source link

feature add lru cache evict #30

Closed Stone-afk closed 10 months ago

codecov[bot] commented 11 months ago

Codecov Report

Attention: 13 lines in your changes are missing coverage. Please review.

Comparison is base (8c6eedc) 97.94% compared to head (799b8a2) 96.92%. Report is 1 commits behind head on main.

Files Patch % Lines
memory/lru/cache.go 90.15% 11 Missing and 2 partials :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #30 +/- ## ========================================== - Coverage 97.94% 96.92% -1.02% ========================================== Files 4 7 +3 Lines 632 845 +213 ========================================== + Hits 619 819 +200 - Misses 9 20 +11 - Partials 4 6 +2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

Stone-afk commented 11 months ago

其次,通过在 element 中维护 list,能够依次遍历链表,使用 pushBackList 在链表尾部添加元素或pushFrontList头部添加元素,这样的设计使得链表的操作更加方便和高效。

func (e *element[T]) nextElem() *element[T] {
    if n := e.next; e.list != nil && n != &e.list.root {
        return n
    }
    return nil
}

func (l *linkedList[T]) pushBackList(other *linkedList[T]) {
    l.lazyInit()
    e := other.front()
    for i := other.len(); i > 0; i-- {
        l.insertValue(e.Value, l.root.prev)
        e = e.nextElem()
    }
}
flycash commented 11 months ago

其次,通过在 element 中维护 list,能够依次遍历链表,使用 pushBackList 在链表尾部添加元素或pushFrontList头部添加元素,这样的设计使得链表的操作更加方便和高效。

func (e *element[T]) nextElem() *element[T] {
  if n := e.next; e.list != nil && n != &e.list.root {
      return n
  }
  return nil
}

func (l *linkedList[T]) pushBackList(other *linkedList[T]) {
  l.lazyInit()
  e := other.front()
  for i := other.len(); i > 0; i-- {
      l.insertValue(e.Value, l.root.prev)
      e = e.nextElem()
  }
}

这个也没必要,因为正常我们 list 操作,都是在对应的 Add 或者 Remove 里面,沿着 Element 追溯或者回溯。

所以这里不要反向依赖 list。

flycash commented 10 months ago

我草,GO build 都失败了。有 Data race

flycash commented 10 months ago

其余你也要修复了。