1 // Copyright (c) 2012, Suryandaru Triandana <syndtr@gmail.com>
2 // All rights reserved.
4 // Use of this source code is governed by a BSD-style license that can be
5 // found in the LICENSE file.
13 "github.com/syndtr/goleveldb/leveldb/storage"
16 func shorten(str string) string {
20 return str[:3] + ".." + str[len(str)-3:]
23 var bunits = [...]string{"", "Ki", "Mi", "Gi"}
25 func shortenb(bytes int) string {
27 for ; bytes > 1024 && i < 4; i++ {
30 return fmt.Sprintf("%d%sB", bytes, bunits[i])
33 func sshortenb(bytes int) string {
43 for ; bytes > 1024 && i < 4; i++ {
46 return fmt.Sprintf("%s%d%sB", sign, bytes, bunits[i])
49 func sint(x int) string {
58 return fmt.Sprintf("%s%d", sign, x)
61 func minInt(a, b int) int {
68 func maxInt(a, b int) int {
75 type fdSorter []storage.FileDesc
77 func (p fdSorter) Len() int {
81 func (p fdSorter) Less(i, j int) bool {
82 return p[i].Num < p[j].Num
85 func (p fdSorter) Swap(i, j int) {
86 p[i], p[j] = p[j], p[i]
89 func sortFds(fds []storage.FileDesc) {
90 sort.Sort(fdSorter(fds))
93 func ensureBuffer(b []byte, n int) []byte {
95 return make([]byte, n)