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
}
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)
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 err error
if client, err = common.NewRedisClient("tcp", tu.redisAddress); err != nil {
@ -184,7 +184,7 @@ func (tu *tileUpdater) doUpdates() {
for level := 7; level >= 0; level-- {
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)
go updatePyramidTiles(level, tu.mapDir, pJobs, &done)
}

View File

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

View File

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