Merge branch 'release/v0.7.3'

This commit is contained in:
eson 2019-12-23 02:50:34 +08:00
commit b0ab2396b4

View File

@ -4,27 +4,27 @@ import (
"github.com/474420502/focus/compare" "github.com/474420502/focus/compare"
) )
type Heap struct { type Tree struct {
size int size int
elements []interface{} elements []interface{}
Compare compare.Compare Compare compare.Compare
} }
func New(Compare compare.Compare) *Heap { func New(Compare compare.Compare) *Tree {
h := &Heap{Compare: Compare} h := &Tree{Compare: Compare}
h.elements = make([]interface{}, 16, 16) h.elements = make([]interface{}, 16, 16)
return h return h
} }
func (h *Heap) Size() int { func (h *Tree) Size() int {
return h.size return h.size
} }
func (h *Heap) Values() []interface{} { func (h *Tree) Values() []interface{} {
return h.elements[0:h.size] return h.elements[0:h.size]
} }
func (h *Heap) grow() { func (h *Tree) grow() {
ecap := len(h.elements) ecap := len(h.elements)
if h.size >= ecap { if h.size >= ecap {
ecap = ecap << 1 ecap = ecap << 1
@ -34,27 +34,27 @@ func (h *Heap) grow() {
} }
} }
func (h *Heap) Empty() bool { func (h *Tree) Empty() bool {
return h.size < 1 return h.size < 1
} }
func (h *Heap) Clear() { func (h *Tree) Clear() {
h.size = 0 h.size = 0
} }
func (h *Heap) Reborn() { func (h *Tree) Reborn() {
h.size = 0 h.size = 0
h.elements = make([]interface{}, 16, 16) h.elements = make([]interface{}, 16, 16)
} }
func (h *Heap) Top() (interface{}, bool) { func (h *Tree) Top() (interface{}, bool) {
if h.size != 0 { if h.size != 0 {
return h.elements[0], true return h.elements[0], true
} }
return nil, false return nil, false
} }
func (h *Heap) Put(v interface{}) { func (h *Tree) Put(v interface{}) {
if v == nil { if v == nil {
return return
} }
@ -77,7 +77,7 @@ func (h *Heap) Put(v interface{}) {
h.elements[curidx] = v h.elements[curidx] = v
} }
func (h *Heap) slimming() { func (h *Tree) slimming() {
elen := len(h.elements) elen := len(h.elements)
if elen >= 32 { if elen >= 32 {
@ -92,7 +92,7 @@ func (h *Heap) slimming() {
} }
func (h *Heap) Pop() (interface{}, bool) { func (h *Tree) Pop() (interface{}, bool) {
if h.size == 0 { if h.size == 0 {
return nil, false return nil, false