mirror of https://github.com/tidwall/tile38.git
Update tidwall dependencies
This commit is contained in:
parent
694ad1fb62
commit
17ab07bd3e
12
go.mod
12
go.mod
|
@ -17,16 +17,16 @@ require (
|
|||
github.com/streadway/amqp v1.0.0
|
||||
github.com/tidwall/btree v0.6.0
|
||||
github.com/tidwall/buntdb v1.2.5
|
||||
github.com/tidwall/geoindex v1.4.3
|
||||
github.com/tidwall/geojson v1.2.7
|
||||
github.com/tidwall/gjson v1.8.0
|
||||
github.com/tidwall/geoindex v1.4.4
|
||||
github.com/tidwall/geojson v1.3.0
|
||||
github.com/tidwall/gjson v1.8.1
|
||||
github.com/tidwall/match v1.0.3
|
||||
github.com/tidwall/pretty v1.1.0
|
||||
github.com/tidwall/pretty v1.2.0
|
||||
github.com/tidwall/redbench v0.1.0
|
||||
github.com/tidwall/redcon v1.4.1
|
||||
github.com/tidwall/resp v0.1.0
|
||||
github.com/tidwall/rtree v1.2.7
|
||||
github.com/tidwall/sjson v1.1.6
|
||||
github.com/tidwall/rtree v1.3.1
|
||||
github.com/tidwall/sjson v1.1.7
|
||||
github.com/xdg/scram v1.0.3
|
||||
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110
|
||||
|
|
19
go.sum
19
go.sum
|
@ -416,13 +416,15 @@ github.com/tidwall/buntdb v1.2.5 h1:eRLLh0pJkoSu/6bALIzGH7VPxhFcrWNId6FSHgi8yfc=
|
|||
github.com/tidwall/buntdb v1.2.5/go.mod h1:zpXqlA5D2772I4cTqV3ifr2AZihDgi8FV7xAQu6edfc=
|
||||
github.com/tidwall/cities v0.1.0 h1:CVNkmMf7NEC9Bvokf5GoSsArHCKRMTgLuubRTHnH0mE=
|
||||
github.com/tidwall/cities v0.1.0/go.mod h1:lV/HDp2gCcRcHJWqgt6Di54GiDrTZwh1aG2ZUPNbqa4=
|
||||
github.com/tidwall/geoindex v1.4.3 h1:zowx7LtzibIE6JPbL6CRgVgw9qp13dJ8Pzfa4/f+4us=
|
||||
github.com/tidwall/geoindex v1.4.3/go.mod h1:NQJQszWCH4+KlD0wY+mgQ2hK/GdSH+9+ZRknDY8bOHc=
|
||||
github.com/tidwall/geojson v1.2.7 h1:AyJ8LrkS2kWEr7bi+Hzu1FsD0YjXinraO7i/6MKl1gs=
|
||||
github.com/tidwall/geojson v1.2.7/go.mod h1:pt8JcRqaBGmX3N/1a2fP/a5GmOKPX4Yx+ejlDGEMtyI=
|
||||
github.com/tidwall/geoindex v1.4.4 h1:hdwzy5qNtK75i7nus59Ibr+SwcH4F2v65bw4txrLJ9M=
|
||||
github.com/tidwall/geoindex v1.4.4/go.mod h1:rvVVNEFfkJVWGUdEfU8QaoOg/9zFX0h9ofWzA60mz1I=
|
||||
github.com/tidwall/geojson v1.3.0 h1:6kvjjETPKq0IImD2ign/SdNmowRilCaUopuFr06ivAY=
|
||||
github.com/tidwall/geojson v1.3.0/go.mod h1:pt8JcRqaBGmX3N/1a2fP/a5GmOKPX4Yx+ejlDGEMtyI=
|
||||
github.com/tidwall/gjson v1.7.4/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk=
|
||||
github.com/tidwall/gjson v1.8.0 h1:Qt+orfosKn0rbNTZqHYDqBrmm3UDA4KRkv70fDzG+PQ=
|
||||
github.com/tidwall/gjson v1.8.0/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk=
|
||||
github.com/tidwall/gjson v1.8.1 h1:8j5EE9Hrh3l9Od1OIEDAb7IpezNA20UdRngNAj5N0WU=
|
||||
github.com/tidwall/gjson v1.8.1/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk=
|
||||
github.com/tidwall/grect v0.1.2 h1:wKVeQVZhjaFCKTTlpkDe3Ex4ko3cMGW3MRKawRe8uQ4=
|
||||
github.com/tidwall/grect v0.1.2/go.mod h1:v+n4ewstPGduVJebcp5Eh2WXBJBumNzyhK8GZt4gHNw=
|
||||
github.com/tidwall/lotsa v1.0.1/go.mod h1:X6NiU+4yHA3fE3Puvpnn1XMDrFZrE9JO2/w+UMuqgR8=
|
||||
|
@ -430,8 +432,9 @@ github.com/tidwall/lotsa v1.0.2 h1:dNVBH5MErdaQ/xd9s769R31/n2dXavsQ0Yf4TMEHHw8=
|
|||
github.com/tidwall/lotsa v1.0.2/go.mod h1:X6NiU+4yHA3fE3Puvpnn1XMDrFZrE9JO2/w+UMuqgR8=
|
||||
github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
|
||||
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||
github.com/tidwall/pretty v1.1.0 h1:K3hMW5epkdAVwibsQEfR/7Zj0Qgt4DxtNumTq/VloO8=
|
||||
github.com/tidwall/pretty v1.1.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
|
||||
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
|
||||
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||
github.com/tidwall/redbench v0.1.0 h1:UZYUMhwMMObQRq5xU4SA3lmlJRztXzqtushDii+AmPo=
|
||||
github.com/tidwall/redbench v0.1.0/go.mod h1:zxcRGCq/JcqV48YjK9WxBNJL7JSpMzbLXaHvMcnanKQ=
|
||||
github.com/tidwall/redcon v1.4.1 h1:oupK+lM1FeSGNhhZn85KvofEpboQReM1eIKNWTmD3K8=
|
||||
|
@ -440,10 +443,12 @@ github.com/tidwall/resp v0.1.0 h1:zZ6Hq+2cY4QqhZ4LqrV05T5yLOSPspj+l+DgAoJ25Ak=
|
|||
github.com/tidwall/resp v0.1.0/go.mod h1:18xEj855iMY2bK6tNF2A4x+nZy5gWO1iO7OOl3jETKw=
|
||||
github.com/tidwall/rtred v0.1.2 h1:exmoQtOLvDoO8ud++6LwVsAMTu0KPzLTUrMln8u1yu8=
|
||||
github.com/tidwall/rtred v0.1.2/go.mod h1:hd69WNXQ5RP9vHd7dqekAz+RIdtfBogmglkZSRxCHFQ=
|
||||
github.com/tidwall/rtree v1.2.7 h1:FlhF5kip3H8BSE4zjiZQYlk9sWvk6q/IU6p4vuPl9kc=
|
||||
github.com/tidwall/rtree v1.2.7/go.mod h1:BzeDd0d/48mLxN0uEJgaU1H8WX3w8pePiLV/244rHuc=
|
||||
github.com/tidwall/sjson v1.1.6 h1:8fDdlahON04OZBlTQCIatW8FstSFJz8oxidj5h0rmSQ=
|
||||
github.com/tidwall/rtree v1.3.1 h1:xu3vJPKJrmGce7YJcFUCoqLrp9DTUEJBnVgdPSXHgHs=
|
||||
github.com/tidwall/rtree v1.3.1/go.mod h1:S+JSsqPTI8LfWA4xHBo5eXzie8WJLVFeppAutSegl6M=
|
||||
github.com/tidwall/sjson v1.1.6/go.mod h1:KN3FZ7odvXIHPbJdhNorK/M9lWweVUbXsXXhrJ/kGOA=
|
||||
github.com/tidwall/sjson v1.1.7 h1:sgVPwu/yygHJ2m1pJDLgGM/h+1F5odx5Q9ljG3imRm8=
|
||||
github.com/tidwall/sjson v1.1.7/go.mod h1:w/yG+ezBeTdUxiKs5NcPicO9diP38nk96QBAbIIGeFs=
|
||||
github.com/tidwall/tinyqueue v0.1.1 h1:SpNEvEggbpyN5DIReaJ2/1ndroY8iyEGxPYxoSaymYE=
|
||||
github.com/tidwall/tinyqueue v0.1.1/go.mod h1:O/QNHwrnjqr6IHItYrzoHAKYhBkLI67Q096fQP5zMYw=
|
||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
||||
|
|
|
@ -4,5 +4,5 @@ go 1.15
|
|||
|
||||
require (
|
||||
github.com/tidwall/cities v0.1.0
|
||||
github.com/tidwall/lotsa v1.0.1
|
||||
github.com/tidwall/lotsa v1.0.2
|
||||
)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
github.com/tidwall/cities v0.1.0 h1:CVNkmMf7NEC9Bvokf5GoSsArHCKRMTgLuubRTHnH0mE=
|
||||
github.com/tidwall/cities v0.1.0/go.mod h1:lV/HDp2gCcRcHJWqgt6Di54GiDrTZwh1aG2ZUPNbqa4=
|
||||
github.com/tidwall/lotsa v1.0.1 h1:w4gpDvI7RdkgbMC0q5ndKqG2ffrwCgerUY/gM2TYkH4=
|
||||
github.com/tidwall/lotsa v1.0.1/go.mod h1:X6NiU+4yHA3fE3Puvpnn1XMDrFZrE9JO2/w+UMuqgR8=
|
||||
github.com/tidwall/lotsa v1.0.2 h1:dNVBH5MErdaQ/xd9s769R31/n2dXavsQ0Yf4TMEHHw8=
|
||||
github.com/tidwall/lotsa v1.0.2/go.mod h1:X6NiU+4yHA3fE3Puvpnn1XMDrFZrE9JO2/w+UMuqgR8=
|
||||
|
|
|
@ -165,3 +165,11 @@ func RectFromCenter(lat, lon, meters float64) (
|
|||
return
|
||||
|
||||
}
|
||||
|
||||
func DegsToSemi(degs float64) int32 {
|
||||
return int32(degs * (math.Pow(2, 31) / 180.0))
|
||||
}
|
||||
|
||||
func SemiToDegs(semi int32) float64 {
|
||||
return float64(semi) * (180.0 / math.Pow(2, 31))
|
||||
}
|
||||
|
|
|
@ -135,6 +135,37 @@ changed in v1.3.0 as to avoid confusion with the new [multipath](#multipaths)
|
|||
syntax. For backwards compatibility, `#[...]` will continue to work until the
|
||||
next major release.*
|
||||
|
||||
The `~` (tilde) operator will convert a value to a boolean before comparison.
|
||||
|
||||
For example, using the following JSON:
|
||||
|
||||
```json
|
||||
{
|
||||
"vals": [
|
||||
{ "a": 1, "b": true },
|
||||
{ "a": 2, "b": true },
|
||||
{ "a": 3, "b": false },
|
||||
{ "a": 4, "b": "0" },
|
||||
{ "a": 5, "b": 0 },
|
||||
{ "a": 6, "b": "1" },
|
||||
{ "a": 7, "b": 1 },
|
||||
{ "a": 8, "b": "true" },
|
||||
{ "a": 9, "b": false },
|
||||
{ "a": 10, "b": null },
|
||||
{ "a": 11 }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
You can now query for all true(ish) or false(ish) values:
|
||||
|
||||
```
|
||||
vals.#(b==~true)#.a >> [1,2,6,7,8]
|
||||
vals.#(b==~false)#.a >> [3,4,5,9,10,11]
|
||||
```
|
||||
|
||||
The last value which was non-existent is treated as `false`
|
||||
|
||||
### Dot vs Pipe
|
||||
|
||||
The `.` is standard separator, but it's also possible to use a `|`.
|
||||
|
|
|
@ -584,7 +584,7 @@ func tostr(json string) (raw string, str string) {
|
|||
continue
|
||||
}
|
||||
}
|
||||
break
|
||||
return json[:i+1], unescape(json[1:i])
|
||||
}
|
||||
}
|
||||
var ret string
|
||||
|
|
|
@ -79,46 +79,6 @@ Will format the json to:
|
|||
{"name":{"first":"Tom","last":"Anderson"},"age":37,"children":["Sara","Alex","Jack"],"fav.movie":"Deer Hunter","friends":[{"first":"Janet","last":"Murphy","age":44}]}```
|
||||
```
|
||||
|
||||
## Spec
|
||||
|
||||
Spec cleans comments and trailing commas from input JSON, converting it to
|
||||
valid JSON per the official spec: https://tools.ietf.org/html/rfc8259
|
||||
|
||||
The resulting JSON will always be the same length as the input and it will
|
||||
include all of the same line breaks at matching offsets. This is to ensure
|
||||
the result can be later processed by a external parser and that that
|
||||
parser will report messages or errors with the correct offsets.
|
||||
|
||||
The following example uses a JSON document that has comments and trailing
|
||||
commas and converts it prior to unmarshalling to using the standard Go
|
||||
JSON library.
|
||||
|
||||
```go
|
||||
|
||||
data := `
|
||||
{
|
||||
/* Dev Machine */
|
||||
"dbInfo": {
|
||||
"host": "localhost",
|
||||
"port": 5432, // use full email address
|
||||
"username": "josh",
|
||||
"password": "pass123", // use a hashed password
|
||||
}
|
||||
/* Only SMTP Allowed */
|
||||
"emailInfo": {
|
||||
"email": "josh@example.com",
|
||||
"password": "pass123",
|
||||
"smtp": "smpt.example.com",
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
err := json.Unmarshal(pretty.Spec(data), &config)
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Customized output
|
||||
|
||||
There's a `PrettyOptions(json, opts)` function which allows for customizing the output with the following options:
|
||||
|
@ -143,14 +103,15 @@ type Options struct {
|
|||
|
||||
Benchmarks of Pretty alongside the builtin `encoding/json` Indent/Compact methods.
|
||||
```
|
||||
BenchmarkPretty-8 1000000 1283 ns/op 720 B/op 2 allocs/op
|
||||
BenchmarkUgly-8 3000000 426 ns/op 240 B/op 1 allocs/op
|
||||
BenchmarkUglyInPlace-8 5000000 340 ns/op 0 B/op 0 allocs/op
|
||||
BenchmarkJSONIndent-8 300000 4628 ns/op 1069 B/op 4 allocs/op
|
||||
BenchmarkJSONCompact-8 1000000 2469 ns/op 758 B/op 4 allocs/op
|
||||
BenchmarkPretty-16 1000000 1034 ns/op 720 B/op 2 allocs/op
|
||||
BenchmarkPrettySortKeys-16 586797 1983 ns/op 2848 B/op 14 allocs/op
|
||||
BenchmarkUgly-16 4652365 254 ns/op 240 B/op 1 allocs/op
|
||||
BenchmarkUglyInPlace-16 6481233 183 ns/op 0 B/op 0 allocs/op
|
||||
BenchmarkJSONIndent-16 450654 2687 ns/op 1221 B/op 0 allocs/op
|
||||
BenchmarkJSONCompact-16 685111 1699 ns/op 442 B/op 0 allocs/op
|
||||
```
|
||||
|
||||
*These benchmarks were run on a MacBook Pro 15" 2.8 GHz Intel Core i7 using Go 1.7.*
|
||||
*These benchmarks were run on a MacBook Pro 2.4 GHz 8-Core Intel Core i9.*
|
||||
|
||||
## Contact
|
||||
Josh Baker [@tidwall](http://twitter.com/tidwall)
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
module github.com/tidwall/pretty
|
||||
|
||||
go 1.16
|
|
@ -1,7 +1,10 @@
|
|||
package pretty
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"sort"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Options is Pretty options
|
||||
|
@ -84,6 +87,14 @@ func ugly(dst, src []byte) []byte {
|
|||
return dst
|
||||
}
|
||||
|
||||
func isNaNOrInf(src []byte) bool {
|
||||
return src[0] == 'i' || //Inf
|
||||
src[0] == 'I' || // inf
|
||||
src[0] == '+' || // +Inf
|
||||
src[0] == 'N' || // Nan
|
||||
(src[0] == 'n' && len(src) > 1 && src[1] != 'u') // nan
|
||||
}
|
||||
|
||||
func appendPrettyAny(buf, json []byte, i int, pretty bool, width int, prefix, indent string, sortkeys bool, tabs, nl, max int) ([]byte, int, int, bool) {
|
||||
for ; i < len(json); i++ {
|
||||
if json[i] <= ' ' {
|
||||
|
@ -92,7 +103,8 @@ func appendPrettyAny(buf, json []byte, i int, pretty bool, width int, prefix, in
|
|||
if json[i] == '"' {
|
||||
return appendPrettyString(buf, json, i, nl)
|
||||
}
|
||||
if (json[i] >= '0' && json[i] <= '9') || json[i] == '-' {
|
||||
|
||||
if (json[i] >= '0' && json[i] <= '9') || json[i] == '-' || isNaNOrInf(json[i:]) {
|
||||
return appendPrettyNumber(buf, json, i, nl)
|
||||
}
|
||||
if json[i] == '{' {
|
||||
|
@ -121,6 +133,7 @@ type pair struct {
|
|||
type byKeyVal struct {
|
||||
sorted bool
|
||||
json []byte
|
||||
buf []byte
|
||||
pairs []pair
|
||||
}
|
||||
|
||||
|
@ -128,21 +141,110 @@ func (arr *byKeyVal) Len() int {
|
|||
return len(arr.pairs)
|
||||
}
|
||||
func (arr *byKeyVal) Less(i, j int) bool {
|
||||
key1 := arr.json[arr.pairs[i].kstart+1 : arr.pairs[i].kend-1]
|
||||
key2 := arr.json[arr.pairs[j].kstart+1 : arr.pairs[j].kend-1]
|
||||
if string(key1) < string(key2) {
|
||||
if arr.isLess(i, j, byKey) {
|
||||
return true
|
||||
}
|
||||
if string(key1) > string(key2) {
|
||||
if arr.isLess(j, i, byKey) {
|
||||
return false
|
||||
}
|
||||
return arr.pairs[i].vstart < arr.pairs[j].vstart
|
||||
return arr.isLess(i, j, byVal)
|
||||
}
|
||||
func (arr *byKeyVal) Swap(i, j int) {
|
||||
arr.pairs[i], arr.pairs[j] = arr.pairs[j], arr.pairs[i]
|
||||
arr.sorted = true
|
||||
}
|
||||
|
||||
type byKind int
|
||||
|
||||
const (
|
||||
byKey byKind = 0
|
||||
byVal byKind = 1
|
||||
)
|
||||
|
||||
type jtype int
|
||||
|
||||
const (
|
||||
jnull jtype = iota
|
||||
jfalse
|
||||
jnumber
|
||||
jstring
|
||||
jtrue
|
||||
jjson
|
||||
)
|
||||
|
||||
func getjtype(v []byte) jtype {
|
||||
if len(v) == 0 {
|
||||
return jnull
|
||||
}
|
||||
switch v[0] {
|
||||
case '"':
|
||||
return jstring
|
||||
case 'f':
|
||||
return jfalse
|
||||
case 't':
|
||||
return jtrue
|
||||
case 'n':
|
||||
return jnull
|
||||
case '[', '{':
|
||||
return jjson
|
||||
default:
|
||||
return jnumber
|
||||
}
|
||||
}
|
||||
|
||||
func (arr *byKeyVal) isLess(i, j int, kind byKind) bool {
|
||||
k1 := arr.json[arr.pairs[i].kstart:arr.pairs[i].kend]
|
||||
k2 := arr.json[arr.pairs[j].kstart:arr.pairs[j].kend]
|
||||
var v1, v2 []byte
|
||||
if kind == byKey {
|
||||
v1 = k1
|
||||
v2 = k2
|
||||
} else {
|
||||
v1 = bytes.TrimSpace(arr.buf[arr.pairs[i].vstart:arr.pairs[i].vend])
|
||||
v2 = bytes.TrimSpace(arr.buf[arr.pairs[j].vstart:arr.pairs[j].vend])
|
||||
if len(v1) >= len(k1)+1 {
|
||||
v1 = bytes.TrimSpace(v1[len(k1)+1:])
|
||||
}
|
||||
if len(v2) >= len(k2)+1 {
|
||||
v2 = bytes.TrimSpace(v2[len(k2)+1:])
|
||||
}
|
||||
}
|
||||
t1 := getjtype(v1)
|
||||
t2 := getjtype(v2)
|
||||
if t1 < t2 {
|
||||
return true
|
||||
}
|
||||
if t1 > t2 {
|
||||
return false
|
||||
}
|
||||
if t1 == jstring {
|
||||
s1 := parsestr(v1)
|
||||
s2 := parsestr(v2)
|
||||
return string(s1) < string(s2)
|
||||
}
|
||||
if t1 == jnumber {
|
||||
n1, _ := strconv.ParseFloat(string(v1), 64)
|
||||
n2, _ := strconv.ParseFloat(string(v2), 64)
|
||||
return n1 < n2
|
||||
}
|
||||
return string(v1) < string(v2)
|
||||
|
||||
}
|
||||
|
||||
func parsestr(s []byte) []byte {
|
||||
for i := 1; i < len(s); i++ {
|
||||
if s[i] == '\\' {
|
||||
var str string
|
||||
json.Unmarshal(s, &str)
|
||||
return []byte(str)
|
||||
}
|
||||
if s[i] == '"' {
|
||||
return s[1:i]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func appendPrettyObject(buf, json []byte, i int, open, close byte, pretty bool, width int, prefix, indent string, sortkeys bool, tabs, nl, max int) ([]byte, int, int, bool) {
|
||||
var ok bool
|
||||
if width > 0 {
|
||||
|
@ -249,7 +351,7 @@ func sortPairs(json, buf []byte, pairs []pair) []byte {
|
|||
}
|
||||
vstart := pairs[0].vstart
|
||||
vend := pairs[len(pairs)-1].vend
|
||||
arr := byKeyVal{false, json, pairs}
|
||||
arr := byKeyVal{false, json, buf, pairs}
|
||||
sort.Stable(&arr)
|
||||
if !arr.sorted {
|
||||
return buf
|
||||
|
@ -446,7 +548,7 @@ func Color(src []byte, style *Style) []byte {
|
|||
dst = apnd(dst, src[i])
|
||||
} else {
|
||||
var kind byte
|
||||
if (src[i] >= '0' && src[i] <= '9') || src[i] == '-' {
|
||||
if (src[i] >= '0' && src[i] <= '9') || src[i] == '-' || isNaNOrInf(src[i:]) {
|
||||
kind = '0'
|
||||
dst = append(dst, style.Number[0]...)
|
||||
} else if src[i] == 't' {
|
||||
|
|
|
@ -2,4 +2,4 @@ module github.com/tidwall/rtree
|
|||
|
||||
go 1.15
|
||||
|
||||
require github.com/tidwall/geoindex v1.4.3
|
||||
require github.com/tidwall/geoindex v1.4.4
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
github.com/tidwall/cities v0.1.0 h1:CVNkmMf7NEC9Bvokf5GoSsArHCKRMTgLuubRTHnH0mE=
|
||||
github.com/tidwall/cities v0.1.0/go.mod h1:lV/HDp2gCcRcHJWqgt6Di54GiDrTZwh1aG2ZUPNbqa4=
|
||||
github.com/tidwall/geoindex v1.4.3 h1:zowx7LtzibIE6JPbL6CRgVgw9qp13dJ8Pzfa4/f+4us=
|
||||
github.com/tidwall/geoindex v1.4.3/go.mod h1:NQJQszWCH4+KlD0wY+mgQ2hK/GdSH+9+ZRknDY8bOHc=
|
||||
github.com/tidwall/lotsa v1.0.1 h1:w4gpDvI7RdkgbMC0q5ndKqG2ffrwCgerUY/gM2TYkH4=
|
||||
github.com/tidwall/lotsa v1.0.1/go.mod h1:X6NiU+4yHA3fE3Puvpnn1XMDrFZrE9JO2/w+UMuqgR8=
|
||||
github.com/tidwall/geoindex v1.4.4 h1:hdwzy5qNtK75i7nus59Ibr+SwcH4F2v65bw4txrLJ9M=
|
||||
github.com/tidwall/geoindex v1.4.4/go.mod h1:rvVVNEFfkJVWGUdEfU8QaoOg/9zFX0h9ofWzA60mz1I=
|
||||
github.com/tidwall/lotsa v1.0.2 h1:dNVBH5MErdaQ/xd9s769R31/n2dXavsQ0Yf4TMEHHw8=
|
||||
github.com/tidwall/lotsa v1.0.2/go.mod h1:X6NiU+4yHA3fE3Puvpnn1XMDrFZrE9JO2/w+UMuqgR8=
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
package rtree
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
||||
"github.com/tidwall/geoindex/child"
|
||||
)
|
||||
|
||||
|
@ -20,7 +22,7 @@ type rect struct {
|
|||
|
||||
type node struct {
|
||||
count int
|
||||
rects [maxEntries + 1]rect
|
||||
rects [maxEntries]rect
|
||||
}
|
||||
|
||||
// RTree ...
|
||||
|
@ -50,74 +52,13 @@ func (r *rect) area() float64 {
|
|||
return (r.max[0] - r.min[0]) * (r.max[1] - r.min[1])
|
||||
}
|
||||
|
||||
func (r *rect) overlapArea(b *rect) float64 {
|
||||
area := 1.0
|
||||
var max, min float64
|
||||
if r.max[0] < b.max[0] {
|
||||
max = r.max[0]
|
||||
} else {
|
||||
max = b.max[0]
|
||||
}
|
||||
if r.min[0] > b.min[0] {
|
||||
min = r.min[0]
|
||||
} else {
|
||||
min = b.min[0]
|
||||
}
|
||||
if max > min {
|
||||
area *= max - min
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
if r.max[1] < b.max[1] {
|
||||
max = r.max[1]
|
||||
} else {
|
||||
max = b.max[1]
|
||||
}
|
||||
if r.min[1] > b.min[1] {
|
||||
min = r.min[1]
|
||||
} else {
|
||||
min = b.min[1]
|
||||
}
|
||||
if max > min {
|
||||
area *= max - min
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
return area
|
||||
// unionedArea returns the area of two rects expanded
|
||||
func (r *rect) unionedArea(b *rect) float64 {
|
||||
return (math.Max(r.max[0], b.max[0]) - math.Min(r.min[0], b.min[0])) *
|
||||
(math.Max(r.max[1], b.max[1]) - math.Min(r.min[1], b.min[1]))
|
||||
}
|
||||
|
||||
func (r *rect) enlargedArea(b *rect) float64 {
|
||||
area := 1.0
|
||||
if b.max[0] > r.max[0] {
|
||||
if b.min[0] < r.min[0] {
|
||||
area *= b.max[0] - b.min[0]
|
||||
} else {
|
||||
area *= b.max[0] - r.min[0]
|
||||
}
|
||||
} else {
|
||||
if b.min[0] < r.min[0] {
|
||||
area *= r.max[0] - b.min[0]
|
||||
} else {
|
||||
area *= r.max[0] - r.min[0]
|
||||
}
|
||||
}
|
||||
if b.max[1] > r.max[1] {
|
||||
if b.min[1] < r.min[1] {
|
||||
area *= b.max[1] - b.min[1]
|
||||
} else {
|
||||
area *= b.max[1] - r.min[1]
|
||||
}
|
||||
} else {
|
||||
if b.min[1] < r.min[1] {
|
||||
area *= r.max[1] - b.min[1]
|
||||
} else {
|
||||
area *= r.max[1] - r.min[1]
|
||||
}
|
||||
}
|
||||
return area
|
||||
}
|
||||
|
||||
// Insert inserts an item into the RTree
|
||||
// Insert data into tree
|
||||
func (tr *RTree) Insert(min, max [2]float64, value interface{}) {
|
||||
var item rect
|
||||
fit(min, max, value, &item)
|
||||
|
@ -132,7 +73,7 @@ func (tr *RTree) insert(item *rect) {
|
|||
if grown {
|
||||
tr.root.expand(item)
|
||||
}
|
||||
if tr.root.data.(*node).count == maxEntries+1 {
|
||||
if tr.root.data.(*node).count == maxEntries {
|
||||
newRoot := new(node)
|
||||
tr.root.splitLargestAxisEdgeSnap(&newRoot.rects[1])
|
||||
newRoot.rects[0] = tr.root
|
||||
|
@ -144,46 +85,14 @@ func (tr *RTree) insert(item *rect) {
|
|||
tr.count++
|
||||
}
|
||||
|
||||
const inlineEnlargedArea = true
|
||||
|
||||
func (r *rect) chooseLeastEnlargement(b *rect) (index int) {
|
||||
n := r.data.(*node)
|
||||
j, jenlargement, jarea := -1, 0.0, 0.0
|
||||
for i := 0; i < n.count; i++ {
|
||||
var earea float64
|
||||
if inlineEnlargedArea {
|
||||
earea = 1.0
|
||||
if b.max[0] > n.rects[i].max[0] {
|
||||
if b.min[0] < n.rects[i].min[0] {
|
||||
earea *= b.max[0] - b.min[0]
|
||||
} else {
|
||||
earea *= b.max[0] - n.rects[i].min[0]
|
||||
}
|
||||
} else {
|
||||
if b.min[0] < n.rects[i].min[0] {
|
||||
earea *= n.rects[i].max[0] - b.min[0]
|
||||
} else {
|
||||
earea *= n.rects[i].max[0] - n.rects[i].min[0]
|
||||
}
|
||||
}
|
||||
if b.max[1] > n.rects[i].max[1] {
|
||||
if b.min[1] < n.rects[i].min[1] {
|
||||
earea *= b.max[1] - b.min[1]
|
||||
} else {
|
||||
earea *= b.max[1] - n.rects[i].min[1]
|
||||
}
|
||||
} else {
|
||||
if b.min[1] < n.rects[i].min[1] {
|
||||
earea *= n.rects[i].max[1] - b.min[1]
|
||||
} else {
|
||||
earea *= n.rects[i].max[1] - n.rects[i].min[1]
|
||||
}
|
||||
}
|
||||
} else {
|
||||
earea = n.rects[i].enlargedArea(b)
|
||||
}
|
||||
// calculate the enlarged area
|
||||
uarea := n.rects[i].unionedArea(b)
|
||||
area := n.rects[i].area()
|
||||
enlargement := earea - area
|
||||
enlargement := uarea - area
|
||||
if j == -1 || enlargement < jenlargement ||
|
||||
(enlargement == jenlargement && area < jarea) {
|
||||
j, jenlargement, jarea = i, enlargement, area
|
||||
|
@ -293,7 +202,7 @@ func (r *rect) insert(item *rect, height int) (grown bool) {
|
|||
child.expand(item)
|
||||
grown = !r.contains(item)
|
||||
}
|
||||
if child.data.(*node).count == maxEntries+1 {
|
||||
if child.data.(*node).count == maxEntries {
|
||||
child.splitLargestAxisEdgeSnap(&n.rects[n.count])
|
||||
n.count++
|
||||
}
|
||||
|
@ -394,15 +303,18 @@ func (tr *RTree) Scan(iter func(min, max [2]float64, data interface{}) bool) {
|
|||
|
||||
// Delete data from tree
|
||||
func (tr *RTree) Delete(min, max [2]float64, data interface{}) {
|
||||
tr.deleteWithResult(min, max, data)
|
||||
}
|
||||
func (tr *RTree) deleteWithResult(min, max [2]float64, data interface{}) bool {
|
||||
var item rect
|
||||
fit(min, max, data, &item)
|
||||
if tr.root.data == nil || !tr.root.contains(&item) {
|
||||
return
|
||||
return false
|
||||
}
|
||||
var removed, recalced bool
|
||||
removed, recalced = tr.root.delete(tr, &item, tr.height)
|
||||
if !removed {
|
||||
return
|
||||
return false
|
||||
}
|
||||
tr.count -= len(tr.reinsert) + 1
|
||||
if tr.count == 0 {
|
||||
|
@ -425,6 +337,7 @@ func (tr *RTree) Delete(min, max [2]float64, data interface{}) {
|
|||
}
|
||||
tr.reinsert = tr.reinsert[:0]
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (r *rect) delete(tr *RTree, item *rect, height int,
|
||||
|
@ -553,12 +466,12 @@ func (tr *RTree) Children(
|
|||
}
|
||||
|
||||
// Replace an item.
|
||||
// This is effectively just a Delete followed by an Insert. Which means the
|
||||
// new item will always be inserted, whether or not the old item was deleted.
|
||||
// If the old item does not exist then the new item is not inserted.
|
||||
func (tr *RTree) Replace(
|
||||
oldMin, oldMax [2]float64, oldData interface{},
|
||||
newMin, newMax [2]float64, newData interface{},
|
||||
) {
|
||||
tr.Delete(oldMin, oldMax, oldData)
|
||||
if tr.deleteWithResult(oldMin, oldMax, oldData) {
|
||||
tr.Insert(newMin, newMax, newData)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,6 +113,7 @@ sjson.Set(`{"key":true}`, "key", false)
|
|||
sjson.Set(`{"key":true}`, "key", 1)
|
||||
sjson.Set(`{"key":true}`, "key", 10.5)
|
||||
sjson.Set(`{"key":true}`, "key", "hello")
|
||||
sjson.Set(`{"key":true}`, "key", []string{"hello", "world"})
|
||||
sjson.Set(`{"key":true}`, "key", map[string]interface{}{"hello":"world"})
|
||||
```
|
||||
|
||||
|
|
|
@ -3,6 +3,6 @@ module github.com/tidwall/sjson
|
|||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/tidwall/gjson v1.7.4
|
||||
github.com/tidwall/gjson v1.8.0
|
||||
github.com/tidwall/pretty v1.1.0
|
||||
)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
github.com/tidwall/gjson v1.7.4 h1:19cchw8FOxkG5mdLRkGf9jqIqEyqdZhPqW60XfyFxk8=
|
||||
github.com/tidwall/gjson v1.7.4/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk=
|
||||
github.com/tidwall/gjson v1.8.0 h1:Qt+orfosKn0rbNTZqHYDqBrmm3UDA4KRkv70fDzG+PQ=
|
||||
github.com/tidwall/gjson v1.8.0/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk=
|
||||
github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
|
||||
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||
github.com/tidwall/pretty v1.1.0 h1:K3hMW5epkdAVwibsQEfR/7Zj0Qgt4DxtNumTq/VloO8=
|
||||
|
|
|
@ -170,17 +170,17 @@ github.com/tidwall/btree
|
|||
github.com/tidwall/buntdb
|
||||
# github.com/tidwall/cities v0.1.0
|
||||
github.com/tidwall/cities
|
||||
# github.com/tidwall/geoindex v1.4.3
|
||||
# github.com/tidwall/geoindex v1.4.4
|
||||
## explicit
|
||||
github.com/tidwall/geoindex
|
||||
github.com/tidwall/geoindex/algo
|
||||
github.com/tidwall/geoindex/child
|
||||
# github.com/tidwall/geojson v1.2.7
|
||||
# github.com/tidwall/geojson v1.3.0
|
||||
## explicit
|
||||
github.com/tidwall/geojson
|
||||
github.com/tidwall/geojson/geo
|
||||
github.com/tidwall/geojson/geometry
|
||||
# github.com/tidwall/gjson v1.8.0
|
||||
# github.com/tidwall/gjson v1.8.1
|
||||
## explicit
|
||||
github.com/tidwall/gjson
|
||||
# github.com/tidwall/grect v0.1.2
|
||||
|
@ -190,7 +190,7 @@ github.com/tidwall/lotsa
|
|||
# github.com/tidwall/match v1.0.3
|
||||
## explicit
|
||||
github.com/tidwall/match
|
||||
# github.com/tidwall/pretty v1.1.0
|
||||
# github.com/tidwall/pretty v1.2.0
|
||||
## explicit
|
||||
github.com/tidwall/pretty
|
||||
# github.com/tidwall/redbench v0.1.0
|
||||
|
@ -205,10 +205,10 @@ github.com/tidwall/resp
|
|||
# github.com/tidwall/rtred v0.1.2
|
||||
github.com/tidwall/rtred
|
||||
github.com/tidwall/rtred/base
|
||||
# github.com/tidwall/rtree v1.2.7
|
||||
# github.com/tidwall/rtree v1.3.1
|
||||
## explicit
|
||||
github.com/tidwall/rtree
|
||||
# github.com/tidwall/sjson v1.1.6
|
||||
# github.com/tidwall/sjson v1.1.7
|
||||
## explicit
|
||||
github.com/tidwall/sjson
|
||||
# github.com/tidwall/tinyqueue v0.1.1
|
||||
|
|
Loading…
Reference in New Issue