UpdateBarPriority
Vladimir Bauer
8 years ago
| 28 | 28 | |
| 29 | 29 | // Bar represents a progress Bar |
| 30 | 30 | type Bar struct { |
| 31 | priority int | |
| 32 | index int | |
| 31 | 33 | // quit channel to request b.server to quit |
| 32 | 34 | quit chan struct{} |
| 33 | 35 | // done channel is receiveable after b.server has been quit |
| 34 | done chan struct{} | |
| 35 | ops chan func(*bState) | |
| 36 | ||
| 37 | // following are used after b.done is receiveable | |
| 36 | done chan struct{} | |
| 37 | operateState chan func(*bState) | |
| 38 | ||
| 39 | // cacheState is used after b.done is receiveable | |
| 38 | 40 | cacheState *bState |
| 39 | 41 | |
| 40 | 42 | once sync.Once |
| 71 | 73 | } |
| 72 | 74 | bufReader struct { |
| 73 | 75 | io.Reader |
| 74 | complete bool | |
| 76 | completed bool | |
| 75 | 77 | } |
| 76 | 78 | ) |
| 77 | 79 | |
| 95 | 97 | s.bufA = bytes.NewBuffer(make([]byte, 0, s.width/2)) |
| 96 | 98 | |
| 97 | 99 | b := &Bar{ |
| 98 | quit: make(chan struct{}), | |
| 99 | done: make(chan struct{}), | |
| 100 | ops: make(chan func(*bState)), | |
| 101 | } | |
| 102 | ||
| 103 | go b.server(s, wg, cancel) | |
| 100 | priority: id, | |
| 101 | quit: make(chan struct{}), | |
| 102 | done: make(chan struct{}), | |
| 103 | operateState: make(chan func(*bState)), | |
| 104 | } | |
| 105 | ||
| 106 | go b.serve(s, wg, cancel) | |
| 104 | 107 | return b |
| 105 | 108 | } |
| 106 | 109 | |
| 107 | 110 | // RemoveAllPrependers removes all prepend functions |
| 108 | 111 | func (b *Bar) RemoveAllPrependers() { |
| 109 | 112 | select { |
| 110 | case b.ops <- func(s *bState) { | |
| 113 | case b.operateState <- func(s *bState) { | |
| 111 | 114 | s.prependFuncs = nil |
| 112 | 115 | }: |
| 113 | 116 | case <-b.quit: |
| 117 | 120 | // RemoveAllAppenders removes all append functions |
| 118 | 121 | func (b *Bar) RemoveAllAppenders() { |
| 119 | 122 | select { |
| 120 | case b.ops <- func(s *bState) { | |
| 123 | case b.operateState <- func(s *bState) { | |
| 121 | 124 | s.appendFuncs = nil |
| 122 | 125 | }: |
| 123 | 126 | case <-b.quit: |
| 140 | 143 | return |
| 141 | 144 | } |
| 142 | 145 | select { |
| 143 | case b.ops <- func(s *bState) { | |
| 146 | case b.operateState <- func(s *bState) { | |
| 144 | 147 | next := time.Now() |
| 145 | 148 | if s.current == 0 { |
| 146 | 149 | s.startTime = next |
| 172 | 175 | return |
| 173 | 176 | } |
| 174 | 177 | select { |
| 175 | case b.ops <- func(s *bState) { | |
| 178 | case b.operateState <- func(s *bState) { | |
| 176 | 179 | s.refill = &refill{r, till} |
| 177 | 180 | }: |
| 178 | 181 | case <-b.quit: |
| 183 | 186 | func (b *Bar) NumOfAppenders() int { |
| 184 | 187 | result := make(chan int, 1) |
| 185 | 188 | select { |
| 186 | case b.ops <- func(s *bState) { result <- len(s.appendFuncs) }: | |
| 189 | case b.operateState <- func(s *bState) { result <- len(s.appendFuncs) }: | |
| 187 | 190 | return <-result |
| 188 | 191 | case <-b.done: |
| 189 | 192 | return len(b.cacheState.appendFuncs) |
| 194 | 197 | func (b *Bar) NumOfPrependers() int { |
| 195 | 198 | result := make(chan int, 1) |
| 196 | 199 | select { |
| 197 | case b.ops <- func(s *bState) { result <- len(s.prependFuncs) }: | |
| 200 | case b.operateState <- func(s *bState) { result <- len(s.prependFuncs) }: | |
| 198 | 201 | return <-result |
| 199 | 202 | case <-b.done: |
| 200 | 203 | return len(b.cacheState.prependFuncs) |
| 205 | 208 | func (b *Bar) ID() int { |
| 206 | 209 | result := make(chan int, 1) |
| 207 | 210 | select { |
| 208 | case b.ops <- func(s *bState) { result <- s.id }: | |
| 211 | case b.operateState <- func(s *bState) { result <- s.id }: | |
| 209 | 212 | return <-result |
| 210 | 213 | case <-b.done: |
| 211 | 214 | return b.cacheState.id |
| 216 | 219 | func (b *Bar) Current() int64 { |
| 217 | 220 | result := make(chan int64, 1) |
| 218 | 221 | select { |
| 219 | case b.ops <- func(s *bState) { result <- s.current }: | |
| 222 | case b.operateState <- func(s *bState) { result <- s.current }: | |
| 220 | 223 | return <-result |
| 221 | 224 | case <-b.done: |
| 222 | 225 | return b.cacheState.current |
| 227 | 230 | func (b *Bar) Total() int64 { |
| 228 | 231 | result := make(chan int64, 1) |
| 229 | 232 | select { |
| 230 | case b.ops <- func(s *bState) { result <- s.total }: | |
| 233 | case b.operateState <- func(s *bState) { result <- s.total }: | |
| 231 | 234 | return <-result |
| 232 | 235 | case <-b.done: |
| 233 | 236 | return b.cacheState.total |
| 238 | 241 | // in other words you should set it to true when total is determined. |
| 239 | 242 | func (b *Bar) SetTotal(total int64, final bool) { |
| 240 | 243 | select { |
| 241 | case b.ops <- func(s *bState) { | |
| 244 | case b.operateState <- func(s *bState) { | |
| 242 | 245 | s.total = total |
| 243 | 246 | s.dynamic = !final |
| 244 | 247 | }: |
| 269 | 272 | close(b.quit) |
| 270 | 273 | } |
| 271 | 274 | |
| 272 | func (b *Bar) server(s *bState, wg *sync.WaitGroup, cancel <-chan struct{}) { | |
| 275 | func (b *Bar) serve(s *bState, wg *sync.WaitGroup, cancel <-chan struct{}) { | |
| 273 | 276 | defer func() { |
| 274 | 277 | b.cacheState = s |
| 275 | 278 | close(b.done) |
| 278 | 281 | |
| 279 | 282 | for { |
| 280 | 283 | select { |
| 281 | case op := <-b.ops: | |
| 284 | case op := <-b.operateState: | |
| 282 | 285 | op(s) |
| 283 | 286 | case <-cancel: |
| 284 | 287 | s.aborted = true |
| 295 | 298 | |
| 296 | 299 | go func() { |
| 297 | 300 | select { |
| 298 | case b.ops <- func(s *bState) { | |
| 301 | case b.operateState <- func(s *bState) { | |
| 299 | 302 | defer func() { |
| 300 | 303 | // recovering if external decorators panic |
| 301 | 304 | if p := recover(); p != nil { |
| 2 | 2 | import ( |
| 3 | 3 | "fmt" |
| 4 | 4 | "math/rand" |
| 5 | "sort" | |
| 6 | 5 | "sync" |
| 7 | 6 | "time" |
| 8 | 7 | |
| 14 | 13 | maxBlockSize = 12 |
| 15 | 14 | ) |
| 16 | 15 | |
| 17 | type barSlice []*mpb.Bar | |
| 18 | ||
| 19 | func (bs barSlice) Len() int { return len(bs) } | |
| 20 | ||
| 21 | func (bs barSlice) Less(i, j int) bool { | |
| 22 | ip := decor.CalcPercentage(bs[i].Total(), bs[i].Current(), 100) | |
| 23 | jp := decor.CalcPercentage(bs[j].Total(), bs[j].Current(), 100) | |
| 24 | return ip < jp | |
| 25 | } | |
| 26 | ||
| 27 | func (bs barSlice) Swap(i, j int) { bs[i], bs[j] = bs[j], bs[i] } | |
| 28 | ||
| 29 | func sortByProgressFunc() mpb.BeforeRender { | |
| 30 | return func(bars []*mpb.Bar) { | |
| 31 | sort.Sort(sort.Reverse(barSlice(bars))) | |
| 32 | } | |
| 33 | } | |
| 34 | ||
| 35 | 16 | func main() { |
| 36 | ||
| 37 | 17 | var wg sync.WaitGroup |
| 38 | p := mpb.New( | |
| 39 | mpb.WithWaitGroup(&wg), | |
| 40 | mpb.WithBeforeRenderFunc(sortByProgressFunc()), | |
| 41 | ) | |
| 18 | p := mpb.New(mpb.WithWaitGroup(&wg)) | |
| 42 | 19 | total := 100 |
| 43 | 20 | numBars := 3 |
| 44 | 21 | wg.Add(numBars) |
| 51 | 28 | b := p.AddBar(int64(total), |
| 52 | 29 | mpb.PrependDecorators( |
| 53 | 30 | decor.StaticName(name, 0, decor.DwidthSync), |
| 54 | decor.Counters("%d / %d", 0, 10, decor.DSyncSpace), | |
| 31 | decor.CountersNoUnit("%d / %d", 10, decor.DSyncSpace), | |
| 55 | 32 | ), |
| 56 | 33 | mpb.AppendDecorators( |
| 57 | 34 | decor.ETA(3, 0), |
| 59 | 36 | ) |
| 60 | 37 | go func() { |
| 61 | 38 | defer wg.Done() |
| 62 | blockSize := rand.Intn(maxBlockSize) + 1 | |
| 63 | for i := 0; i < total; i++ { | |
| 39 | for blockSize, i := 0, 0; i < total; i++ { | |
| 40 | blockSize = rand.Intn(maxBlockSize) + 1 | |
| 41 | if i&1 == 1 { | |
| 42 | priority := total - int(b.Current()) | |
| 43 | p.UpdateBarPriority(b, priority) | |
| 44 | } | |
| 45 | b.Increment() | |
| 64 | 46 | sleep(blockSize) |
| 65 | b.Incr(1) | |
| 66 | blockSize = rand.Intn(maxBlockSize) + 1 | |
| 67 | 47 | } |
| 68 | 48 | }() |
| 69 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | // WithBeforeRenderFunc provided BeforeRender func, | |
| 54 | // will be called before each render cycle. | |
| 55 | func WithBeforeRenderFunc(f BeforeRender) ProgressOption { | |
| 56 | return func(s *pState) { | |
| 57 | s.beforeRender = f | |
| 58 | } | |
| 59 | } | |
| 60 | ||
| 61 | 53 | // WithCancel provide your cancel channel, |
| 62 | 54 | // which you plan to close at some point. |
| 63 | 55 | func WithCancel(ch <-chan struct{}) ProgressOption { |
| 0 | package mpb | |
| 1 | ||
| 2 | import "container/heap" | |
| 3 | ||
| 4 | // A priorityQueue implements heap.Interface and holds Items. | |
| 5 | type priorityQueue []*Bar | |
| 6 | ||
| 7 | func (pq priorityQueue) Len() int { return len(pq) } | |
| 8 | ||
| 9 | func (pq priorityQueue) Less(i, j int) bool { | |
| 10 | return pq[i].priority < pq[j].priority | |
| 11 | } | |
| 12 | ||
| 13 | func (pq priorityQueue) Swap(i, j int) { | |
| 14 | pq[i], pq[j] = pq[j], pq[i] | |
| 15 | pq[i].index = i | |
| 16 | pq[j].index = j | |
| 17 | } | |
| 18 | ||
| 19 | func (pq *priorityQueue) Push(x interface{}) { | |
| 20 | n := len(*pq) | |
| 21 | bar := x.(*Bar) | |
| 22 | bar.index = n | |
| 23 | *pq = append(*pq, bar) | |
| 24 | } | |
| 25 | ||
| 26 | func (pq *priorityQueue) Pop() interface{} { | |
| 27 | old := *pq | |
| 28 | n := len(old) | |
| 29 | bar := old[n-1] | |
| 30 | bar.index = -1 // for safety | |
| 31 | *pq = old[0 : n-1] | |
| 32 | return bar | |
| 33 | } | |
| 34 | ||
| 35 | // update modifies the priority of an Bar in the queue. | |
| 36 | func (pq *priorityQueue) update(bar *Bar, priority int) { | |
| 37 | bar.priority = priority | |
| 38 | heap.Fix(pq, bar.index) | |
| 39 | } |
| 0 | 0 | package mpb |
| 1 | 1 | |
| 2 | 2 | import ( |
| 3 | "container/heap" | |
| 3 | 4 | "io" |
| 4 | 5 | "os" |
| 5 | 6 | "sync" |
| 6 | 7 | "time" |
| 7 | 8 | |
| 8 | 9 | "github.com/vbauerster/mpb/cwriter" |
| 9 | ) | |
| 10 | ||
| 11 | type ( | |
| 12 | // BeforeRender is a func, which gets called before each rendering cycle | |
| 13 | BeforeRender func([]*Bar) | |
| 14 | ||
| 15 | widthSync struct { | |
| 16 | Listen []chan int | |
| 17 | Result []chan int | |
| 18 | } | |
| 19 | ||
| 20 | // progress state, which may contain several bars | |
| 21 | pState struct { | |
| 22 | bars []*Bar | |
| 23 | ||
| 24 | idCounter int | |
| 25 | width int | |
| 26 | format string | |
| 27 | rr time.Duration | |
| 28 | ewg *sync.WaitGroup | |
| 29 | cw *cwriter.Writer | |
| 30 | ticker *time.Ticker | |
| 31 | beforeRender BeforeRender | |
| 32 | interceptors []func(io.Writer) | |
| 33 | ||
| 34 | shutdownNotifier chan struct{} | |
| 35 | cancel <-chan struct{} | |
| 36 | } | |
| 37 | 10 | ) |
| 38 | 11 | |
| 39 | 12 | const ( |
| 55 | 28 | // quit channel to request p.server to quit |
| 56 | 29 | quit chan struct{} |
| 57 | 30 | // done channel is receiveable after p.server has been quit |
| 58 | done chan struct{} | |
| 59 | ops chan func(*pState) | |
| 60 | } | |
| 31 | done chan struct{} | |
| 32 | operateState chan func(*pState) | |
| 33 | } | |
| 34 | ||
| 35 | type ( | |
| 36 | // progress state, which may contain several bars | |
| 37 | pState struct { | |
| 38 | bHeap *priorityQueue | |
| 39 | idCounter int | |
| 40 | width int | |
| 41 | format string | |
| 42 | rr time.Duration | |
| 43 | ewg *sync.WaitGroup | |
| 44 | cw *cwriter.Writer | |
| 45 | ticker *time.Ticker | |
| 46 | interceptors []func(io.Writer) | |
| 47 | ||
| 48 | shutdownNotifier chan struct{} | |
| 49 | cancel <-chan struct{} | |
| 50 | } | |
| 51 | widthSync struct { | |
| 52 | Listen []chan int | |
| 53 | Result []chan int | |
| 54 | } | |
| 55 | renderedBar struct { | |
| 56 | bar *Bar | |
| 57 | pipe <-chan *bufReader | |
| 58 | } | |
| 59 | ) | |
| 61 | 60 | |
| 62 | 61 | // New creates new Progress instance, which orchestrates bars rendering process. |
| 63 | 62 | // Accepts mpb.ProgressOption funcs for customization. |
| 64 | 63 | func New(options ...ProgressOption) *Progress { |
| 64 | pq := make(priorityQueue, 0) | |
| 65 | heap.Init(&pq) | |
| 65 | 66 | s := &pState{ |
| 66 | bars: make([]*Bar, 0, 3), | |
| 67 | bHeap: &pq, | |
| 67 | 68 | width: pwidth, |
| 68 | 69 | format: pformat, |
| 69 | 70 | cw: cwriter.New(os.Stdout), |
| 77 | 78 | } |
| 78 | 79 | |
| 79 | 80 | p := &Progress{ |
| 80 | ewg: s.ewg, | |
| 81 | wg: new(sync.WaitGroup), | |
| 82 | done: make(chan struct{}), | |
| 83 | ops: make(chan func(*pState)), | |
| 84 | quit: make(chan struct{}), | |
| 85 | } | |
| 86 | go p.server(s) | |
| 81 | ewg: s.ewg, | |
| 82 | wg: new(sync.WaitGroup), | |
| 83 | done: make(chan struct{}), | |
| 84 | operateState: make(chan func(*pState)), | |
| 85 | quit: make(chan struct{}), | |
| 86 | } | |
| 87 | go p.serve(s) | |
| 87 | 88 | return p |
| 88 | 89 | } |
| 89 | 90 | |
| 92 | 93 | p.wg.Add(1) |
| 93 | 94 | result := make(chan *Bar, 1) |
| 94 | 95 | select { |
| 95 | case p.ops <- func(s *pState) { | |
| 96 | case p.operateState <- func(s *pState) { | |
| 96 | 97 | options = append(options, barWidth(s.width), barFormat(s.format)) |
| 97 | 98 | b := newBar(s.idCounter, total, p.wg, s.cancel, options...) |
| 98 | s.bars = append(s.bars, b) | |
| 99 | heap.Push(s.bHeap, b) | |
| 99 | 100 | s.idCounter++ |
| 100 | 101 | result <- b |
| 101 | 102 | }: |
| 109 | 110 | func (p *Progress) RemoveBar(b *Bar) bool { |
| 110 | 111 | result := make(chan bool, 1) |
| 111 | 112 | select { |
| 112 | case p.ops <- func(s *pState) { | |
| 113 | var ok bool | |
| 114 | for i, bar := range s.bars { | |
| 115 | if bar == b { | |
| 116 | bar.Complete() | |
| 117 | s.bars = append(s.bars[:i], s.bars[i+1:]...) | |
| 118 | ok = true | |
| 119 | break | |
| 120 | } | |
| 121 | } | |
| 122 | result <- ok | |
| 113 | case p.operateState <- func(s *pState) { | |
| 114 | b.Complete() | |
| 115 | result <- heap.Remove(s.bHeap, b.index) != nil | |
| 123 | 116 | }: |
| 124 | 117 | return <-result |
| 125 | 118 | case <-p.quit: |
| 126 | 119 | return false |
| 120 | } | |
| 121 | } | |
| 122 | ||
| 123 | // UpdateBarPriority provides a way to change bar's order position. | |
| 124 | // Zero is highest priority, i.e. bar will be on top. | |
| 125 | func (p *Progress) UpdateBarPriority(b *Bar, priority int) { | |
| 126 | select { | |
| 127 | case p.operateState <- func(s *pState) { | |
| 128 | s.bHeap.update(b, priority) | |
| 129 | }: | |
| 130 | case <-p.quit: | |
| 127 | 131 | } |
| 128 | 132 | } |
| 129 | 133 | |
| 131 | 135 | func (p *Progress) BarCount() int { |
| 132 | 136 | result := make(chan int, 1) |
| 133 | 137 | select { |
| 134 | case p.ops <- func(s *pState) { | |
| 135 | result <- len(s.bars) | |
| 138 | case p.operateState <- func(s *pState) { | |
| 139 | result <- s.bHeap.Len() | |
| 136 | 140 | }: |
| 137 | 141 | return <-result |
| 138 | 142 | case <-p.quit: |
| 210 | 214 | if numP < 0 && numA < 0 { |
| 211 | 215 | return |
| 212 | 216 | } |
| 213 | if s.beforeRender != nil { | |
| 214 | s.beforeRender(s.bars) | |
| 215 | } | |
| 216 | 217 | |
| 217 | 218 | wSyncTimeout := make(chan struct{}) |
| 218 | 219 | time.AfterFunc(s.rr, func() { |
| 219 | 220 | close(wSyncTimeout) |
| 220 | 221 | }) |
| 221 | 222 | |
| 222 | prependWs := newWidthSync(wSyncTimeout, len(s.bars), numP) | |
| 223 | appendWs := newWidthSync(wSyncTimeout, len(s.bars), numA) | |
| 224 | ||
| 225 | sequence := make([]<-chan *bufReader, len(s.bars)) | |
| 226 | for i, b := range s.bars { | |
| 227 | sequence[i] = b.render(tw, prependWs, appendWs) | |
| 228 | } | |
| 229 | ||
| 230 | var i int | |
| 231 | for r := range fanIn(sequence...) { | |
| 223 | prependWs := newWidthSync(wSyncTimeout, s.bHeap.Len(), numP) | |
| 224 | appendWs := newWidthSync(wSyncTimeout, s.bHeap.Len(), numA) | |
| 225 | ||
| 226 | for _, b := range s.renderByPriority(tw, prependWs, appendWs) { | |
| 227 | r := <-b.pipe | |
| 232 | 228 | _, err = s.cw.ReadFrom(r) |
| 233 | defer func(bar *Bar, complete bool) { | |
| 234 | if complete { | |
| 235 | bar.Complete() | |
| 236 | } | |
| 237 | }(s.bars[i], r.complete) | |
| 238 | i++ | |
| 229 | if r.completed { | |
| 230 | b.bar.Complete() | |
| 231 | } | |
| 239 | 232 | } |
| 240 | 233 | |
| 241 | 234 | for _, interceptor := range s.interceptors { |
| 248 | 241 | return |
| 249 | 242 | } |
| 250 | 243 | |
| 251 | func fanIn(inputs ...<-chan *bufReader) <-chan *bufReader { | |
| 252 | ch := make(chan *bufReader) | |
| 253 | ||
| 254 | go func() { | |
| 255 | defer close(ch) | |
| 256 | for _, input := range inputs { | |
| 257 | ch <- <-input | |
| 258 | } | |
| 259 | }() | |
| 260 | ||
| 261 | return ch | |
| 244 | func (s *pState) renderByPriority(tw int, prependWs, appendWs *widthSync) []*renderedBar { | |
| 245 | slice := make([]*renderedBar, 0, s.bHeap.Len()) | |
| 246 | for s.bHeap.Len() > 0 { | |
| 247 | b := heap.Pop(s.bHeap).(*Bar) | |
| 248 | defer heap.Push(s.bHeap, b) | |
| 249 | slice = append(slice, &renderedBar{ | |
| 250 | bar: b, | |
| 251 | pipe: b.render(tw, prependWs, appendWs), | |
| 252 | }) | |
| 253 | } | |
| 254 | return slice | |
| 262 | 255 | } |
| 263 | 256 | |
| 264 | 257 | func max(slice []int) int { |
| 12 | 12 | "github.com/vbauerster/mpb/cwriter" |
| 13 | 13 | ) |
| 14 | 14 | |
| 15 | func (p *Progress) server(s *pState) { | |
| 15 | func (p *Progress) serve(s *pState) { | |
| 16 | 16 | winch := make(chan os.Signal, 1) |
| 17 | 17 | signal.Notify(winch, syscall.SIGWINCH) |
| 18 | 18 | |
| 32 | 32 | |
| 33 | 33 | for { |
| 34 | 34 | select { |
| 35 | case op := <-p.ops: | |
| 35 | case op := <-p.operateState: | |
| 36 | 36 | op(s) |
| 37 | 37 | case <-s.ticker.C: |
| 38 | if len(s.bars) == 0 { | |
| 38 | if s.bHeap.Len() == 0 { | |
| 39 | 39 | runtime.Gosched() |
| 40 | 40 | break |
| 41 | 41 | } |
| 42 | b0 := s.bars[0] | |
| 42 | b0 := (*s.bHeap)[0] | |
| 43 | 43 | if numP == -1 { |
| 44 | 44 | numP = b0.NumOfPrependers() |
| 45 | 45 | } |
| 9 | 9 | "github.com/vbauerster/mpb/cwriter" |
| 10 | 10 | ) |
| 11 | 11 | |
| 12 | func (p *Progress) server(s *pState) { | |
| 12 | func (p *Progress) serve(s *pState) { | |
| 13 | 13 | defer func() { |
| 14 | 14 | if s.shutdownNotifier != nil { |
| 15 | 15 | close(s.shutdownNotifier) |
| 21 | 21 | |
| 22 | 22 | for { |
| 23 | 23 | select { |
| 24 | case op := <-p.ops: | |
| 24 | case op := <-p.operateState: | |
| 25 | 25 | op(s) |
| 26 | 26 | case <-s.ticker.C: |
| 27 | if len(s.bars) == 0 { | |
| 27 | if s.bHeap.Len() == 0 { | |
| 28 | 28 | runtime.Gosched() |
| 29 | 29 | break |
| 30 | 30 | } |
| 31 | b0 := s.bars[0] | |
| 31 | b0 := (*s.bHeap)[0] | |
| 32 | 32 | if numP == -1 { |
| 33 | 33 | numP = b0.NumOfPrependers() |
| 34 | 34 | } |