Small cleanup. Moved min to common/math.

This commit is contained in:
Sascha L. Teichmann 2015-07-26 12:32:59 +02:00
parent e1eb03813f
commit becf017edc
4 changed files with 12 additions and 12 deletions

View File

@ -27,10 +27,3 @@ func ipsFromHosts(hosts string) ([]net.IP, error) {
return ips, nil return ips, nil
} }
func min(a, b int) int {
if a < b {
return a
}
return b
}

View File

@ -159,7 +159,7 @@ func (tu *tileUpdater) doUpdates() {
jobs := make(chan xz) jobs := make(chan xz)
var done sync.WaitGroup var done sync.WaitGroup
for i, n := 0, min(tu.workers, len(changes)); i < n; i++ { for i, n := 0, common.Min(tu.workers, len(changes)); i < n; i++ {
var client *common.RedisClient var client *common.RedisClient
var err error var err error
if client, err = common.NewRedisClient("tcp", tu.redisAddress); err != nil { if client, err = common.NewRedisClient("tcp", tu.redisAddress); err != nil {
@ -184,7 +184,7 @@ func (tu *tileUpdater) doUpdates() {
for level := 7; level >= 0; level-- { for level := 7; level >= 0; level-- {
pJobs := make(chan xzm) pJobs := make(chan xzm)
for i, n := 0, min(len(parentJobs), tu.workers); i < n; i++ { for i, n := 0, common.Min(len(parentJobs), tu.workers); i < n; i++ {
done.Add(1) done.Add(1)
go updatePyramidTiles(level, tu.mapDir, pJobs, &done) go updatePyramidTiles(level, tu.mapDir, pJobs, &done)
} }

View File

@ -1,12 +1,19 @@
package common package common
func max(a, b int) int { func Max(a, b int) int {
if a > b { if a > b {
return a return a
} }
return b return b
} }
func Min(a, b int) int {
if a < b {
return a
}
return b
}
func max32(a, b int32) int32 { func max32(a, b int32) int32 {
if a > b { if a > b {
return a return a

View File

@ -51,7 +51,7 @@ func (yo *YOrder) Reset() {
func copyData(data []byte) []byte { func copyData(data []byte) []byte {
l := len(data) l := len(data)
ndata := make([]byte, l, max(l, 8*1024)) ndata := make([]byte, l, Max(l, 8*1024))
copy(ndata, data) copy(ndata, data)
return ndata return ndata
} }
@ -70,7 +70,7 @@ func (yo *YOrder) RenderBlock(block *Block, colors *Colors) (err error) {
err = yo.Renderer.RenderBlock(oblock, colors) err = yo.Renderer.RenderBlock(oblock, colors)
l := len(block.Data) l := len(block.Data)
if cap(oblock.Data) < l { if cap(oblock.Data) < l {
oblock.Data = make([]byte, l, max(l, 8*1024)) oblock.Data = make([]byte, l, Max(l, 8*1024))
} else { } else {
oblock.Data = oblock.Data[0:l] oblock.Data = oblock.Data[0:l]
} }