Update module github.com/vbauerster/mpb/v8 to v8.11.1

Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This commit is contained in:
renovate[bot]
2025-11-07 10:36:01 +00:00
committed by GitHub
parent 905721cae5
commit 6493343ddc
47 changed files with 2269 additions and 16492 deletions

View File

@@ -1,6 +1,11 @@
package mpb
import "container/heap"
import (
"container/heap"
"time"
"github.com/vbauerster/mpb/v8/decor"
)
type heapManager chan heapRequest
@@ -20,11 +25,7 @@ type heapRequest struct {
data interface{}
}
type iterData struct {
drop <-chan struct{}
iter chan<- *Bar
iterPop chan<- *Bar
}
type iterRequest chan (<-chan *Bar)
type pushData struct {
bar *Bar
@@ -38,63 +39,47 @@ type fixData struct {
}
func (m heapManager) run() {
var bHeap priorityQueue
var pMatrix, aMatrix map[int][]chan int
var bHeap barHeap
var pMatrix map[int][]*decor.Sync
var aMatrix map[int][]*decor.Sync
var l int
var sync bool
var prevLen int
for req := range m {
switch req.cmd {
case h_sync:
if sync || prevLen != bHeap.Len() {
pMatrix = make(map[int][]*decor.Sync)
aMatrix = make(map[int][]*decor.Sync)
for _, b := range bHeap {
table := b.wSyncTable()
for i, s := range table[0] {
pMatrix[i] = append(pMatrix[i], s)
}
for i, s := range table[1] {
aMatrix[i] = append(aMatrix[i], s)
}
}
sync, prevLen = false, bHeap.Len()
}
syncWidth(pMatrix)
syncWidth(aMatrix)
case h_push:
data := req.data.(pushData)
heap.Push(&bHeap, data.bar)
sync = sync || data.sync
case h_sync:
if sync || l != bHeap.Len() {
pMatrix = make(map[int][]chan int)
aMatrix = make(map[int][]chan int)
for _, b := range bHeap {
table := b.wSyncTable()
for i, ch := range table[0] {
pMatrix[i] = append(pMatrix[i], ch)
}
for i, ch := range table[1] {
aMatrix[i] = append(aMatrix[i], ch)
}
}
sync = false
l = bHeap.Len()
}
drop := req.data.(<-chan struct{})
syncWidth(pMatrix, drop)
syncWidth(aMatrix, drop)
case h_iter:
data := req.data.(iterData)
loop: // unordered iteration
for _, b := range bHeap {
select {
case data.iter <- b:
case <-data.drop:
data.iterPop = nil
break loop
for i, req := range req.data.([]iterRequest) {
ch := make(chan *Bar, bHeap.Len())
req <- ch
switch i {
case 0:
rangeOverSlice(bHeap, ch)
case 1:
popOverHeap(&bHeap, ch)
}
}
close(data.iter)
if data.iterPop == nil {
break
}
loop_pop: // ordered iteration
for bHeap.Len() != 0 {
bar := heap.Pop(&bHeap).(*Bar)
select {
case data.iterPop <- bar:
case <-data.drop:
heap.Push(&bHeap, bar)
break loop_pop
}
}
close(data.iterPop)
case h_fix:
data := req.data.(fixData)
if data.bar.index < 0 {
@@ -106,21 +91,24 @@ func (m heapManager) run() {
}
case h_state:
ch := req.data.(chan<- bool)
ch <- sync || l != bHeap.Len()
ch <- sync || prevLen != bHeap.Len()
case h_end:
ch := req.data.(chan<- interface{})
if ch != nil {
go func() {
ch <- []*Bar(bHeap)
select {
case ch <- []*Bar(bHeap):
case <-time.After(time.Second):
}
}()
}
close(m)
return
}
}
}
func (m heapManager) sync(drop <-chan struct{}) {
m <- heapRequest{cmd: h_sync, data: drop}
func (m heapManager) sync() {
m <- heapRequest{cmd: h_sync}
}
func (m heapManager) push(b *Bar, sync bool) {
@@ -135,9 +123,8 @@ func (m heapManager) push(b *Bar, sync bool) {
}
}
func (m heapManager) iter(drop <-chan struct{}, iter, iterPop chan<- *Bar) {
data := iterData{drop, iter, iterPop}
m <- heapRequest{cmd: h_iter, data: data}
func (m heapManager) iter(req ...iterRequest) {
m <- heapRequest{cmd: h_iter, data: req}
}
func (m heapManager) fix(b *Bar, priority int, lazy bool) {
@@ -153,25 +140,37 @@ func (m heapManager) end(ch chan<- interface{}) {
m <- heapRequest{cmd: h_end, data: ch}
}
func syncWidth(matrix map[int][]chan int, drop <-chan struct{}) {
func syncWidth(matrix map[int][]*decor.Sync) {
for _, column := range matrix {
go maxWidthDistributor(column, drop)
go maxWidthDistributor(column)
}
}
func maxWidthDistributor(column []chan int, drop <-chan struct{}) {
func maxWidthDistributor(column []*decor.Sync) {
var maxWidth int
for _, ch := range column {
select {
case w := <-ch:
if w > maxWidth {
maxWidth = w
}
case <-drop:
return
for _, s := range column {
w := <-s.Tx
if w > maxWidth {
maxWidth = w
}
}
for _, ch := range column {
ch <- maxWidth
for _, s := range column {
s.Rx <- maxWidth
}
}
// unordered iteration
func rangeOverSlice(s barHeap, dst chan<- *Bar) {
defer close(dst)
for _, b := range s {
dst <- b
}
}
// ordered iteration
func popOverHeap(h heap.Interface, dst chan<- *Bar) {
defer close(dst)
for h.Len() != 0 {
dst <- heap.Pop(h).(*Bar)
}
}