[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 return h.baseHeap[i].height > h.baseHeap[j].height
} }
// BlockHeap represents a mutable heap of Blocks, sorted by their height // blockHeap represents a mutable heap of Blocks, sorted by their height
type BlockHeap struct { type blockHeap struct {
impl heap.Interface impl heap.Interface
} }
// NewDownHeap initializes and returns a new BlockHeap // newDownHeap initializes and returns a new blockHeap
func NewDownHeap() BlockHeap { func newDownHeap() blockHeap {
h := BlockHeap{impl: &downHeap{}} h := blockHeap{impl: &downHeap{}}
heap.Init(h.impl) heap.Init(h.impl)
return h return h
} }
// NewUpHeap initializes and returns a new BlockHeap // newUpHeap initializes and returns a new blockHeap
func NewUpHeap() BlockHeap { func newUpHeap() blockHeap {
h := BlockHeap{impl: &upHeap{}} h := blockHeap{impl: &upHeap{}}
heap.Init(h.impl) heap.Init(h.impl)
return h return h
} }
// pop removes the block with lowest height from this heap and returns it // 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) return heap.Pop(bh.impl).(*blockNode)
} }
// Push pushes the block onto the heap // Push pushes the block onto the heap
func (bh BlockHeap) Push(block *blockNode) { func (bh blockHeap) Push(block *blockNode) {
heap.Push(bh.impl, block) heap.Push(bh.impl, block)
} }
// pushSet pushes a blockset to the heap. // pushSet pushes a blockset to the heap.
func (bh BlockHeap) pushSet(bs blockSet) { func (bh blockHeap) pushSet(bs blockSet) {
for _, block := range bs { for _, block := range bs {
heap.Push(bh.impl, block) heap.Push(bh.impl, block)
} }
} }
// Len returns the length of this heap // Len returns the length of this heap
func (bh BlockHeap) Len() int { func (bh blockHeap) Len() int {
return bh.impl.Len() return bh.impl.Len()
} }

View File

@ -81,7 +81,7 @@ func TestBlockHeap(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
dHeap := NewDownHeap() dHeap := newDownHeap()
for _, block := range test.toPush { for _, block := range test.toPush {
dHeap.Push(block) dHeap.Push(block)
} }
@ -99,7 +99,7 @@ func TestBlockHeap(t *testing.T) {
"Expected: %v, got: %v", test.name, test.expectedPopDown, poppedBlock) "Expected: %v, got: %v", test.name, test.expectedPopDown, poppedBlock)
} }
uHeap := NewUpHeap() uHeap := newUpHeap()
for _, block := range test.toPush { for _, block := range test.toPush {
uHeap.Push(block) uHeap.Push(block)
} }

View File

@ -1439,7 +1439,7 @@ func (dag *BlockDAG) locateBlockNodes(locator BlockLocator, hashStop *daghash.Ha
// Populate and return the found nodes. // Populate and return the found nodes.
nodes := make([]*blockNode, 0, estimatedEntries) nodes := make([]*blockNode, 0, estimatedEntries)
queue := NewUpHeap() queue := newUpHeap()
queue.pushSet(node.children) queue.pushSet(node.children)
visited := newSet() visited := newSet()
@ -1506,7 +1506,7 @@ func (dag *BlockDAG) GetTopHeaders(startHash *daghash.Hash) ([]*wire.BlockHeader
} }
} }
headers := make([]*wire.BlockHeader, 0, startNode.blueScore) headers := make([]*wire.BlockHeader, 0, startNode.blueScore)
queue := NewDownHeap() queue := newDownHeap()
queue.pushSet(startNode.parents) queue.pushSet(startNode.parents)
visited := newSet() visited := newSet()

View File

@ -77,7 +77,7 @@ func blueCandidates(chainStart *blockNode) blockSet {
func traverseCandidates(newBlock *blockNode, candidates blockSet, selectedParent *blockNode) []*blockNode { func traverseCandidates(newBlock *blockNode, candidates blockSet, selectedParent *blockNode) []*blockNode {
blues := []*blockNode{} blues := []*blockNode{}
selectedParentPast := newSet() selectedParentPast := newSet()
queue := NewDownHeap() queue := newDownHeap()
visited := newSet() visited := newSet()
for _, parent := range newBlock.parents { 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 // validateParents validates that no parent is an ancestor of another parent
func validateParents(blockHeader *wire.BlockHeader, parents blockSet) error { func validateParents(blockHeader *wire.BlockHeader, parents blockSet) error {
minHeight := int32(math.MaxInt32) minHeight := int32(math.MaxInt32)
queue := NewDownHeap() queue := newDownHeap()
visited := newSet() visited := newSet()
for _, parent := range parents { for _, parent := range parents {
if parent.height < minHeight { if parent.height < minHeight {