Skip to content

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

@GeeVong

Description

@GeeVong

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions