Skip to content

请教一下, 为什么是用链表? #40

@yangliyl

Description

@yangliyl
func (b *bucket) Flush(reinsert func(*Timer)) {
	var ts []*Timer

	b.mu.Lock()
	for e := b.timers.Front(); e != nil; {
		next := e.Next()

		t := e.Value.(*Timer)
		b.remove(t)
		ts = append(ts, t)

		e = next
	}
	b.mu.Unlock()

	b.SetExpiration(-1) // TODO: Improve the coordination with b.Add()

	for _, t := range ts {
		reinsert(t)
	}
}

bucket为什么是用链表呢? 没有体会到它的作用.
添加task的时候直接追加的数组尾部, 到期时直接遍历数组取出所有task. 因为每个bucket里的task到期时间都是一样的, 那直接用数组不行吗?
请大佬解惑

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