Skip to content

Commit 0d60f20

Browse files
committed
Introduce simplifyCount to summarize counts in magnitudes of 10^3
All sizes are still simplified with `simplifySize`. All offsets are not simplified.
1 parent 6884a92 commit 0d60f20

2 files changed

Lines changed: 27 additions & 7 deletions

File tree

lib/cmd_metadata.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ func CmdMetadata(f CmdMetadataFlags, args []string, printHelp func()) error {
131131
printline("Binary Format", binaryFmt, "")
132132
printline("Database Type", mdFromLib.DatabaseType, "")
133133
printline("IP Version", strconv.Itoa(int(mdFromLib.IPVersion)), "")
134-
printline("Record Size", strconv.Itoa(int(mdFromLib.RecordSize)), simplifySize(int64(mdFromLib.RecordSize)))
135-
printline("Node Count", strconv.Itoa(int(mdFromLib.NodeCount)), "")
134+
printline("Record Size", strconv.Itoa(int(mdFromLib.RecordSize)), "")
135+
printline("Node Count", strconv.Itoa(int(mdFromLib.NodeCount)), simplifyCount(int64(mdFromLib.NodeCount)))
136136
printline("Tree Size", strconv.Itoa(treeSize), simplifySize(int64(treeSize)))
137137
printline("Data Section Size", strconv.Itoa(dataSectionSize), simplifySize(int64(dataSectionSize)))
138138
if f.DataTypes {
@@ -146,13 +146,13 @@ func CmdMetadata(f CmdMetadataFlags, args []string, printHelp func()) error {
146146
typeSizePrintline("Signed 32-bit Integer Size", strconv.Itoa(int(typeSizes.Signed32bitIntSize)), simplifySize(typeSizes.Signed32bitIntSize))
147147
typeSizePrintline("Unsigned 64-bit Integer Size", strconv.Itoa(int(typeSizes.Unsigned64bitIntSize)), simplifySize(typeSizes.Unsigned64bitIntSize))
148148
typeSizePrintline("Unsigned 128-bit Integer Size", strconv.Itoa(int(typeSizes.Unsigned128bitIntSize)), simplifySize(typeSizes.Unsigned128bitIntSize))
149-
typeSizePrintline("Map Key-Value Pair Count", strconv.Itoa(int(typeSizes.MapKeyValueCount)), simplifySize(typeSizes.MapKeyValueCount))
150-
typeSizePrintline("Array Length", strconv.Itoa(int(typeSizes.ArrayLength)), simplifySize(typeSizes.ArrayLength))
149+
typeSizePrintline("Map Key-Value Pair Count", strconv.Itoa(int(typeSizes.MapKeyValueCount)), simplifyCount(typeSizes.MapKeyValueCount))
150+
typeSizePrintline("Array Length", strconv.Itoa(int(typeSizes.ArrayLength)), simplifyCount(typeSizes.ArrayLength))
151151
typeSizePrintline("Float Size", strconv.Itoa(int(typeSizes.FloatSize)), simplifySize(typeSizes.FloatSize))
152152
}
153-
printline("Data Section Start Offset", strconv.Itoa(dataSectionStartOffset), simplifySize(int64(dataSectionStartOffset)))
154-
printline("Data Section End Offset", strconv.Itoa(dataSectionEndOffset), simplifySize(int64(dataSectionEndOffset)))
155-
printline("Metadata Section Start Offset", strconv.Itoa(metadataSectionStartOffset), simplifySize(int64(metadataSectionStartOffset)))
153+
printline("Data Section Start Offset", strconv.Itoa(dataSectionStartOffset), "")
154+
printline("Data Section End Offset", strconv.Itoa(dataSectionEndOffset), "")
155+
printline("Metadata Section Start Offset", strconv.Itoa(metadataSectionStartOffset), "")
156156
printline("Description", "", "")
157157
descKeys, descVals := sortedMapKeysAndVals(mdFromLib.Description)
158158
longestDescKeyLen := strconv.Itoa(len(longestStrInStringSlice(descKeys)))

lib/utils.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,27 @@ func simplifySize(size int64) string {
112112
} else {
113113
return ""
114114
}
115+
}
116+
117+
func simplifyCount(size int64) string {
118+
const (
119+
K = 1e3
120+
M = 1e6
121+
G = 1e9
122+
T = 1e12
123+
)
115124

125+
if size >= T {
126+
return fmt.Sprintf("(%.2f T)", float64(size)/float64(T))
127+
} else if size >= G {
128+
return fmt.Sprintf("(%.2f G)", float64(size)/float64(G))
129+
} else if size >= M {
130+
return fmt.Sprintf("(%.2f M)", float64(size)/float64(M))
131+
} else if size >= K {
132+
return fmt.Sprintf("(%.2f K)", float64(size)/float64(K))
133+
} else {
134+
return ""
135+
}
116136
}
117137

118138
type TypeSizes struct {

0 commit comments

Comments
 (0)