forked from mirror/buntdb
Minor update and new comments
This commit is contained in:
parent
04bc915abd
commit
f7014795e8
16
buntdb.go
16
buntdb.go
|
@ -1263,12 +1263,15 @@ type dbItem struct {
|
|||
keyless bool // keyless item for scanning
|
||||
}
|
||||
|
||||
// estIntSize returns the string representions size.
|
||||
// Has the same result as len(strconv.Itoa(x)).
|
||||
func estIntSize(x int) int {
|
||||
if x == 0 {
|
||||
return 1
|
||||
n := 1
|
||||
if x < 0 {
|
||||
n++
|
||||
x *= -1
|
||||
}
|
||||
var n int
|
||||
for x > 0 {
|
||||
for x >= 10 {
|
||||
n++
|
||||
x /= 10
|
||||
}
|
||||
|
@ -1283,7 +1286,10 @@ func estBulkStringSize(s string) int {
|
|||
return 1 + estIntSize(len(s)) + 2 + len(s) + 2
|
||||
}
|
||||
|
||||
func (dbi *dbItem) estAOFSetSize() (n int) {
|
||||
// estAOFSetSize returns an estimated number of bytes that this item will use
|
||||
// when stored in the aof file.
|
||||
func (dbi *dbItem) estAOFSetSize() int {
|
||||
var n int
|
||||
if dbi.opts != nil && dbi.opts.ex {
|
||||
n += estArraySize(5)
|
||||
n += estBulkStringSize("set")
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/tidwall/assert"
|
||||
"github.com/tidwall/lotsa"
|
||||
)
|
||||
|
||||
|
@ -2886,3 +2887,25 @@ func TestReloadNotInvalid(t *testing.T) {
|
|||
ii++
|
||||
}
|
||||
}
|
||||
|
||||
func TestEstSize(t *testing.T) {
|
||||
t.Run("estIntSize", func(t *testing.T) {
|
||||
assert.Assert(estIntSize(0) == 1)
|
||||
assert.Assert(estIntSize(1) == 1)
|
||||
assert.Assert(estIntSize(9) == 1)
|
||||
assert.Assert(estIntSize(10) == 2)
|
||||
assert.Assert(estIntSize(11) == 2)
|
||||
assert.Assert(estIntSize(19) == 2)
|
||||
assert.Assert(estIntSize(20) == 2)
|
||||
assert.Assert(estIntSize(113) == 3)
|
||||
assert.Assert(estIntSize(3822) == 4)
|
||||
assert.Assert(estIntSize(-1) == 2)
|
||||
assert.Assert(estIntSize(-12) == 3)
|
||||
assert.Assert(estIntSize(-124) == 4)
|
||||
})
|
||||
// t.Run("estI
|
||||
// // dbi := dbItem{
|
||||
// // key: "hello",
|
||||
// // value: "
|
||||
// // }
|
||||
}
|
||||
|
|
1
go.mod
1
go.mod
|
@ -3,6 +3,7 @@ module github.com/tidwall/buntdb
|
|||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/tidwall/assert v0.1.0
|
||||
github.com/tidwall/btree v0.6.0
|
||||
github.com/tidwall/gjson v1.8.0
|
||||
github.com/tidwall/grect v0.1.2
|
||||
|
|
2
go.sum
2
go.sum
|
@ -1,3 +1,5 @@
|
|||
github.com/tidwall/assert v0.1.0 h1:aWcKyRBUAdLoVebxo95N7+YZVTFF/ASTr7BN4sLP6XI=
|
||||
github.com/tidwall/assert v0.1.0/go.mod h1:QLYtGyeqse53vuELQheYl9dngGCJQ+mTtlxcktb+Kj8=
|
||||
github.com/tidwall/btree v0.6.0 h1:JLYAFGV+1gjyFi3iQbO/fupBin+Ooh7dxqVV0twJ1Bo=
|
||||
github.com/tidwall/btree v0.6.0/go.mod h1:TzIRzen6yHbibdSfK6t8QimqbUnoxUSrZfeW7Uob0q4=
|
||||
github.com/tidwall/gjson v1.8.0 h1:Qt+orfosKn0rbNTZqHYDqBrmm3UDA4KRkv70fDzG+PQ=
|
||||
|
|
Loading…
Reference in New Issue