mirror of https://github.com/tidwall/tile38.git
Update btree and minor optz
This commit is contained in:
parent
ac0f170477
commit
40dddd2620
2
go.mod
2
go.mod
|
@ -17,7 +17,7 @@ require (
|
||||||
github.com/prometheus/client_golang v1.12.1
|
github.com/prometheus/client_golang v1.12.1
|
||||||
github.com/streadway/amqp v1.0.0
|
github.com/streadway/amqp v1.0.0
|
||||||
github.com/tidwall/assert v0.1.0
|
github.com/tidwall/assert v0.1.0
|
||||||
github.com/tidwall/btree v1.4.3
|
github.com/tidwall/btree v1.4.4
|
||||||
github.com/tidwall/buntdb v1.2.9
|
github.com/tidwall/buntdb v1.2.9
|
||||||
github.com/tidwall/geojson v1.3.6
|
github.com/tidwall/geojson v1.3.6
|
||||||
github.com/tidwall/gjson v1.14.3
|
github.com/tidwall/gjson v1.14.3
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -350,8 +350,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
|
||||||
github.com/tidwall/assert v0.1.0 h1:aWcKyRBUAdLoVebxo95N7+YZVTFF/ASTr7BN4sLP6XI=
|
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/assert v0.1.0/go.mod h1:QLYtGyeqse53vuELQheYl9dngGCJQ+mTtlxcktb+Kj8=
|
||||||
github.com/tidwall/btree v1.1.0/go.mod h1:TzIRzen6yHbibdSfK6t8QimqbUnoxUSrZfeW7Uob0q4=
|
github.com/tidwall/btree v1.1.0/go.mod h1:TzIRzen6yHbibdSfK6t8QimqbUnoxUSrZfeW7Uob0q4=
|
||||||
github.com/tidwall/btree v1.4.3 h1:Lf5U/66bk0ftNppOBjVoy/AIPBrLMkheBp4NnSNiYOo=
|
github.com/tidwall/btree v1.4.4 h1:tOsRz2Upq6BEJz8T++C6THzNh9xGWymBOOSfA7ffNXY=
|
||||||
github.com/tidwall/btree v1.4.3/go.mod h1:LGm8L/DZjPLmeWGjv5kFrY8dL4uVhMmzmmLYmsObdKE=
|
github.com/tidwall/btree v1.4.4/go.mod h1:LGm8L/DZjPLmeWGjv5kFrY8dL4uVhMmzmmLYmsObdKE=
|
||||||
github.com/tidwall/buntdb v1.2.9 h1:XVz684P7X6HCTrdr385yDZWB1zt/n20ZNG3M1iGyFm4=
|
github.com/tidwall/buntdb v1.2.9 h1:XVz684P7X6HCTrdr385yDZWB1zt/n20ZNG3M1iGyFm4=
|
||||||
github.com/tidwall/buntdb v1.2.9/go.mod h1:IwyGSvvDg6hnKSIhtdZ0AqhCZGH8ukdtCAzaP8fI1X4=
|
github.com/tidwall/buntdb v1.2.9/go.mod h1:IwyGSvvDg6hnKSIhtdZ0AqhCZGH8ukdtCAzaP8fI1X4=
|
||||||
github.com/tidwall/cities v0.1.0 h1:CVNkmMf7NEC9Bvokf5GoSsArHCKRMTgLuubRTHnH0mE=
|
github.com/tidwall/cities v0.1.0 h1:CVNkmMf7NEC9Bvokf5GoSsArHCKRMTgLuubRTHnH0mE=
|
||||||
|
|
|
@ -63,24 +63,18 @@ func varint(s string) (int64, int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Object) ID() string {
|
func (o *Object) ID() string {
|
||||||
if o == nil {
|
if o.head[1] == 0 {
|
||||||
return ""
|
return o.head[2:]
|
||||||
}
|
}
|
||||||
_, n := varint(o.head[1:])
|
_, n := varint(o.head[1:])
|
||||||
return o.head[1+n:]
|
return o.head[1+n:]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Object) Fields() field.List {
|
func (o *Object) Fields() field.List {
|
||||||
if o == nil {
|
|
||||||
return field.List{}
|
|
||||||
}
|
|
||||||
return o.fields
|
return o.fields
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Object) Expires() int64 {
|
func (o *Object) Expires() int64 {
|
||||||
if o == nil {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
ex, _ := varint(o.head[1:])
|
ex, _ := varint(o.head[1:])
|
||||||
return ex
|
return ex
|
||||||
}
|
}
|
||||||
|
@ -111,15 +105,15 @@ func (o *Object) IsSpatial() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Object) Weight() int {
|
func (o *Object) Weight() int {
|
||||||
if o == nil {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
var weight int
|
var weight int
|
||||||
weight += len(o.ID())
|
weight += len(o.ID())
|
||||||
|
ogeo := o.geo()
|
||||||
|
if ogeo != nil {
|
||||||
if o.IsSpatial() {
|
if o.IsSpatial() {
|
||||||
weight += o.Geo().NumPoints() * 16
|
weight += ogeo.NumPoints() * 16
|
||||||
} else {
|
} else {
|
||||||
weight += len(o.Geo().String())
|
weight += len(ogeo.String())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
weight += o.Fields().Weight()
|
weight += o.Fields().Weight()
|
||||||
return weight
|
return weight
|
||||||
|
@ -127,7 +121,10 @@ func (o *Object) Weight() int {
|
||||||
|
|
||||||
func makeHead(kind byte, id string, expires int64) string {
|
func makeHead(kind byte, id string, expires int64) string {
|
||||||
var exb [20]byte
|
var exb [20]byte
|
||||||
exn := binary.PutVarint(exb[:], expires)
|
exn := 1
|
||||||
|
if expires != 0 {
|
||||||
|
exn = binary.PutVarint(exb[:], expires)
|
||||||
|
}
|
||||||
n := 1 + exn + len(id)
|
n := 1 + exn + len(id)
|
||||||
head := make([]byte, n)
|
head := make([]byte, n)
|
||||||
head[0] = kind
|
head[0] = kind
|
||||||
|
|
Loading…
Reference in New Issue