7days-golang icon indicating copy to clipboard operation
7days-golang copied to clipboard

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

Open GeeVong opened this issue 11 months ago • 0 comments

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

GeeVong avatar Aug 29 '23 03:08 GeeVong