diff --git a/blockdag/blockheap.go b/blockdag/blockheap.go index 5c79f3563..4bb28b0bb 100644 --- a/blockdag/blockheap.go +++ b/blockdag/blockheap.go @@ -46,43 +46,43 @@ func (h downHeap) Less(i, j int) bool { return h.baseHeap[i].height > h.baseHeap[j].height } -// BlockHeap represents a mutable heap of Blocks, sorted by their height -type BlockHeap struct { +// blockHeap represents a mutable heap of Blocks, sorted by their height +type blockHeap struct { impl heap.Interface } -// NewDownHeap initializes and returns a new BlockHeap -func NewDownHeap() BlockHeap { - h := BlockHeap{impl: &downHeap{}} +// newDownHeap initializes and returns a new blockHeap +func newDownHeap() blockHeap { + h := blockHeap{impl: &downHeap{}} heap.Init(h.impl) return h } -// NewUpHeap initializes and returns a new BlockHeap -func NewUpHeap() BlockHeap { - h := BlockHeap{impl: &upHeap{}} +// newUpHeap initializes and returns a new blockHeap +func newUpHeap() blockHeap { + h := blockHeap{impl: &upHeap{}} heap.Init(h.impl) return h } // pop removes the block with lowest height from this heap and returns it -func (bh BlockHeap) pop() *blockNode { +func (bh blockHeap) pop() *blockNode { return heap.Pop(bh.impl).(*blockNode) } // Push pushes the block onto the heap -func (bh BlockHeap) Push(block *blockNode) { +func (bh blockHeap) Push(block *blockNode) { heap.Push(bh.impl, block) } // pushSet pushes a blockset to the heap. -func (bh BlockHeap) pushSet(bs blockSet) { +func (bh blockHeap) pushSet(bs blockSet) { for _, block := range bs { heap.Push(bh.impl, block) } } // Len returns the length of this heap -func (bh BlockHeap) Len() int { +func (bh blockHeap) Len() int { return bh.impl.Len() } diff --git a/blockdag/blockheap_test.go b/blockdag/blockheap_test.go index 879cda046..5828bbb5a 100644 --- a/blockdag/blockheap_test.go +++ b/blockdag/blockheap_test.go @@ -81,7 +81,7 @@ func TestBlockHeap(t *testing.T) { } for _, test := range tests { - dHeap := NewDownHeap() + dHeap := newDownHeap() for _, block := range test.toPush { dHeap.Push(block) } @@ -99,7 +99,7 @@ func TestBlockHeap(t *testing.T) { "Expected: %v, got: %v", test.name, test.expectedPopDown, poppedBlock) } - uHeap := NewUpHeap() + uHeap := newUpHeap() for _, block := range test.toPush { uHeap.Push(block) } diff --git a/blockdag/dag.go b/blockdag/dag.go index 79a05489a..36857ac82 100644 --- a/blockdag/dag.go +++ b/blockdag/dag.go @@ -1439,7 +1439,7 @@ func (dag *BlockDAG) locateBlockNodes(locator BlockLocator, hashStop *daghash.Ha // Populate and return the found nodes. nodes := make([]*blockNode, 0, estimatedEntries) - queue := NewUpHeap() + queue := newUpHeap() queue.pushSet(node.children) visited := newSet() @@ -1506,7 +1506,7 @@ func (dag *BlockDAG) GetTopHeaders(startHash *daghash.Hash) ([]*wire.BlockHeader } } headers := make([]*wire.BlockHeader, 0, startNode.blueScore) - queue := NewDownHeap() + queue := newDownHeap() queue.pushSet(startNode.parents) visited := newSet() diff --git a/blockdag/phantom.go b/blockdag/phantom.go index c574eb5f7..63ffc156f 100644 --- a/blockdag/phantom.go +++ b/blockdag/phantom.go @@ -77,7 +77,7 @@ func blueCandidates(chainStart *blockNode) blockSet { func traverseCandidates(newBlock *blockNode, candidates blockSet, selectedParent *blockNode) []*blockNode { blues := []*blockNode{} selectedParentPast := newSet() - queue := NewDownHeap() + queue := newDownHeap() visited := newSet() for _, parent := range newBlock.parents { diff --git a/blockdag/validate.go b/blockdag/validate.go index 524b35543..043d3d6ae 100644 --- a/blockdag/validate.go +++ b/blockdag/validate.go @@ -754,7 +754,7 @@ func (dag *BlockDAG) validateDifficulty(header *wire.BlockHeader, bluestParent * // validateParents validates that no parent is an ancestor of another parent func validateParents(blockHeader *wire.BlockHeader, parents blockSet) error { minHeight := int32(math.MaxInt32) - queue := NewDownHeap() + queue := newDownHeap() visited := newSet() for _, parent := range parents { if parent.height < minHeight {