refactor add newTTLKeyHeap function

This commit is contained in:
Xiang Li
2013-11-04 20:31:24 -08:00
parent b9593b80ec
commit c05df9e3f5
2 changed files with 7 additions and 2 deletions

View File

@ -8,8 +8,7 @@ import (
) )
func TestHeapPushPop(t *testing.T) { func TestHeapPushPop(t *testing.T) {
h := &TTLKeyHeap{Map: make(map[*Node]int)} h := newTTLKeyHeap()
heap.Init(h)
// add from older expire time to earlier expire time // add from older expire time to earlier expire time
// the path is equal to ttl from now // the path is equal to ttl from now

View File

@ -10,6 +10,12 @@ type TTLKeyHeap struct {
Map map[*Node]int Map map[*Node]int
} }
func newTTLKeyHeap() *TTLKeyHeap {
h := &TTLKeyHeap{Map: make(map[*Node]int)}
heap.Init(h)
return h
}
func (h TTLKeyHeap) Len() int { func (h TTLKeyHeap) Len() int {
return len(h.Array) return len(h.Array)
} }