[NOD-67] Unexport blockheap (#257)

This commit is contained in:
Ori Newman 2019-04-18 17:19:10 +03:00 committed by stasatdaglabs
parent e99af346bf
commit b612426ead
5 changed files with 18 additions and 18 deletions

View File

@ -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()
}

View File

@ -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)
}

View File

@ -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()

View File

@ -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 {

View File

@ -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 {