Skip to content

Commit

Permalink
feat: mass
Browse files Browse the repository at this point in the history
  • Loading branch information
zenghur committed Aug 7, 2019
1 parent e58c730 commit a213a50
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions mass/mass.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package mass

import (
"math"
)

type Mass struct {
batchSize int
count int
currentCount int
times int
currentTimes int
}

func New(count, batchSize int) *Mass {
mass := new(Mass)

if count < 0 {
count = 0
}

if batchSize <= 0 {
batchSize = 1
}

mass.count = count
mass.batchSize = batchSize
mass.times = int(math.Ceil(float64(count) / float64(batchSize)))
return mass
}

func (mass *Mass) Iter(start, length *int) bool {
roundSize := mass.batchSize

if mass.currentTimes != 0 {
*start += *length
}

if *start+roundSize > mass.count {
roundSize = mass.count - *start
}

mass.currentCount += roundSize
*length = roundSize

mass.currentTimes++

return *start < mass.count

}

0 comments on commit a213a50

Please sign in to comment.