2015-02-03 05:17:15 +03:00
|
|
|
// Copyright (c) 2012, Suryandaru Triandana <syndtr@gmail.com>
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
package leveldb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"sort"
|
|
|
|
|
|
|
|
"github.com/syndtr/goleveldb/leveldb/storage"
|
|
|
|
)
|
|
|
|
|
|
|
|
func shorten(str string) string {
|
|
|
|
if len(str) <= 8 {
|
|
|
|
return str
|
|
|
|
}
|
|
|
|
return str[:3] + ".." + str[len(str)-3:]
|
|
|
|
}
|
|
|
|
|
|
|
|
var bunits = [...]string{"", "Ki", "Mi", "Gi"}
|
|
|
|
|
|
|
|
func shortenb(bytes int) string {
|
|
|
|
i := 0
|
|
|
|
for ; bytes > 1024 && i < 4; i++ {
|
|
|
|
bytes /= 1024
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%d%sB", bytes, bunits[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
func sshortenb(bytes int) string {
|
|
|
|
if bytes == 0 {
|
|
|
|
return "~"
|
|
|
|
}
|
|
|
|
sign := "+"
|
|
|
|
if bytes < 0 {
|
|
|
|
sign = "-"
|
|
|
|
bytes *= -1
|
|
|
|
}
|
|
|
|
i := 0
|
|
|
|
for ; bytes > 1024 && i < 4; i++ {
|
|
|
|
bytes /= 1024
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%s%d%sB", sign, bytes, bunits[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
func sint(x int) string {
|
|
|
|
if x == 0 {
|
|
|
|
return "~"
|
|
|
|
}
|
|
|
|
sign := "+"
|
|
|
|
if x < 0 {
|
|
|
|
sign = "-"
|
|
|
|
x *= -1
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%s%d", sign, x)
|
|
|
|
}
|
|
|
|
|
|
|
|
func minInt(a, b int) int {
|
|
|
|
if a < b {
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
func maxInt(a, b int) int {
|
|
|
|
if a > b {
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
2016-05-01 18:33:02 +03:00
|
|
|
type fdSorter []storage.FileDesc
|
2015-02-03 05:17:15 +03:00
|
|
|
|
2016-05-01 18:33:02 +03:00
|
|
|
func (p fdSorter) Len() int {
|
2015-02-03 05:17:15 +03:00
|
|
|
return len(p)
|
|
|
|
}
|
|
|
|
|
2016-05-01 18:33:02 +03:00
|
|
|
func (p fdSorter) Less(i, j int) bool {
|
|
|
|
return p[i].Num < p[j].Num
|
2015-02-03 05:17:15 +03:00
|
|
|
}
|
|
|
|
|
2016-05-01 18:33:02 +03:00
|
|
|
func (p fdSorter) Swap(i, j int) {
|
2015-02-03 05:17:15 +03:00
|
|
|
p[i], p[j] = p[j], p[i]
|
|
|
|
}
|
|
|
|
|
2016-05-01 18:33:02 +03:00
|
|
|
func sortFds(fds []storage.FileDesc) {
|
|
|
|
sort.Sort(fdSorter(fds))
|
2015-02-03 05:17:15 +03:00
|
|
|
}
|