From c05df9e3f5ef37e401a959a13e7b25955cd1d15e Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Mon, 4 Nov 2013 20:31:24 -0800 Subject: [PATCH] refactor add newTTLKeyHeap function --- store/heap_test.go | 3 +-- store/ttl_key_heap.go | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/store/heap_test.go b/store/heap_test.go index 2ae573724..1da81d312 100644 --- a/store/heap_test.go +++ b/store/heap_test.go @@ -8,8 +8,7 @@ import ( ) func TestHeapPushPop(t *testing.T) { - h := &TTLKeyHeap{Map: make(map[*Node]int)} - heap.Init(h) + h := newTTLKeyHeap() // add from older expire time to earlier expire time // the path is equal to ttl from now diff --git a/store/ttl_key_heap.go b/store/ttl_key_heap.go index abb12fede..23a9997f0 100644 --- a/store/ttl_key_heap.go +++ b/store/ttl_key_heap.go @@ -10,6 +10,12 @@ type TTLKeyHeap struct { Map map[*Node]int } +func newTTLKeyHeap() *TTLKeyHeap { + h := &TTLKeyHeap{Map: make(map[*Node]int)} + heap.Init(h) + return h +} + func (h TTLKeyHeap) Len() int { return len(h.Array) }