mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
refactor add push/pop function
This commit is contained in:
parent
c5a6f9bb6b
commit
efe431ead0
@ -16,14 +16,13 @@ func TestHeapPushPop(t *testing.T) {
|
||||
path := fmt.Sprintf("%v", 10-i)
|
||||
m := time.Duration(10 - i)
|
||||
n := newKV(nil, path, path, 0, 0, nil, "", time.Now().Add(time.Second*m))
|
||||
heap.Push(h, n)
|
||||
h.push(n)
|
||||
}
|
||||
|
||||
min := time.Now()
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
iNode := heap.Pop(h)
|
||||
node, _ := iNode.(*Node)
|
||||
node := h.pop()
|
||||
if node.ExpireTime.Before(min) {
|
||||
t.Fatal("heap sort wrong!")
|
||||
}
|
||||
@ -45,7 +44,7 @@ func TestHeapUpdate(t *testing.T) {
|
||||
m := time.Duration(10 - i)
|
||||
n = newKV(nil, path, path, 0, 0, nil, "", time.Now().Add(time.Second*m))
|
||||
kvs[i] = n
|
||||
heap.Push(h, n)
|
||||
h.push(n)
|
||||
}
|
||||
|
||||
// Path 7
|
||||
@ -60,8 +59,7 @@ func TestHeapUpdate(t *testing.T) {
|
||||
min := time.Now()
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
iNode := heap.Pop(h)
|
||||
node, _ := iNode.(*Node)
|
||||
node := h.pop()
|
||||
if node.ExpireTime.Before(min) {
|
||||
t.Fatal("heap sort wrong!")
|
||||
}
|
||||
|
@ -48,6 +48,16 @@ func (h *TTLKeyHeap) Pop() interface{} {
|
||||
return x
|
||||
}
|
||||
|
||||
func (h *TTLKeyHeap) pop() *Node {
|
||||
x := heap.Pop(h)
|
||||
n, _ := x.(*Node)
|
||||
return n
|
||||
}
|
||||
|
||||
func (h *TTLKeyHeap) push(x interface{}) {
|
||||
heap.Push(h, x)
|
||||
}
|
||||
|
||||
func (h *TTLKeyHeap) update(n *Node) {
|
||||
index := h.Map[n]
|
||||
heap.Remove(h, index)
|
||||
|
Loading…
x
Reference in New Issue
Block a user