Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gee-cache/day1-lru/ 文档描述问题 #76

Open
GeeVong opened this issue Aug 29, 2023 · 0 comments
Open

gee-cache/day1-lru/ 文档描述问题 #76

GeeVong opened this issue Aug 29, 2023 · 0 comments

Comments

@GeeVong
Copy link

GeeVong commented Aug 29, 2023

day1-lru/geecache/lru/lru.go - github

day1文档:如果键存在,则更新对应节点的值,并将该节点移到队尾。
代码:更新存在的key,元素是移动到列表l的最前

code:
// MoveToFront moves element e to the front of list l.
// If e is not an element of l, the list is not modified.
// The element must not be nil.
func (l *List) MoveToFront(e *Element) {
if e.list != l || l.root.next == e {
return
}
// see comment in List.Remove about initialization of l
l.move(e, &l.root)
}

testing res:
2023-08-29T11:34:23+08:00 INF lru_test.go:103 > nbytes:4 ,maxBytes201 [tag]=TestOnEvicted
ll's element:{k1,v1} c.nbytes:4,elementSize:4

2023-08-29T11:34:23+08:00 INF lru_test.go:103 > nbytes:8 ,maxBytes201 [tag]=TestOnEvicted
ll's element:{k2,v2} c.nbytes:8,elementSize:4
ll's element:{k1,v1} c.nbytes:8,elementSize:4

2023-08-29T11:34:23+08:00 INF lru_test.go:103 > nbytes:12 ,maxBytes201 [tag]=TestOnEvicted
ll's element:{k3,v3} c.nbytes:12,elementSize:4
ll's element:{k2,v2} c.nbytes:12,elementSize:4
ll's element:{k1,v1} c.nbytes:12,elementSize:4

2023-08-29T11:34:23+08:00 INF lru_test.go:103 > nbytes:16 ,maxBytes201 [tag]=TestOnEvicted
ll's element:{k2,v22222} c.nbytes:16,elementSize:8
ll's element:{k3,v3} c.nbytes:16,elementSize:4
ll's element:{k1,v1} c.nbytes:16,elementSize:4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant