From 5bbe2c3166141face1227fa33fe438a6f39165d0 Mon Sep 17 00:00:00 2001
From: tidwall
Date: Thu, 8 Jul 2021 06:36:41 -0700
Subject: [PATCH] Upgrade go.mod
---
go.mod | 14 +-
go.sum | 37 ++-
vendor/github.com/tidwall/btree/README.md | 41 +--
vendor/github.com/tidwall/btree/btree.go | 260 ++++++++++++------
vendor/github.com/tidwall/buntdb/buntdb.go | 103 ++++---
vendor/github.com/tidwall/buntdb/go.mod | 8 +-
vendor/github.com/tidwall/buntdb/go.sum | 17 +-
.../github.com/tidwall/geoindex/geoindex.go | 53 ++--
vendor/github.com/tidwall/geoindex/tests.go | 5 +-
vendor/github.com/tidwall/geojson/go.mod | 8 +-
vendor/github.com/tidwall/geojson/go.sum | 21 +-
vendor/github.com/tidwall/grect/go.mod | 2 +-
vendor/github.com/tidwall/grect/go.sum | 8 +-
vendor/github.com/tidwall/redcon/README.md | 4 +-
vendor/github.com/tidwall/redcon/go.mod | 4 +-
vendor/github.com/tidwall/redcon/go.sum | 8 +-
vendor/github.com/tidwall/redcon/redcon.go | 16 ++
vendor/github.com/tidwall/rtree/go.mod | 2 +-
vendor/github.com/tidwall/rtree/go.sum | 4 +-
vendor/github.com/tidwall/rtree/rtree.go | 4 +-
vendor/github.com/tidwall/sjson/README.md | 2 +-
vendor/github.com/tidwall/sjson/go.mod | 4 +-
vendor/github.com/tidwall/sjson/go.sum | 8 +-
vendor/modules.txt | 16 +-
24 files changed, 385 insertions(+), 264 deletions(-)
diff --git a/go.mod b/go.mod
index f85bd126..352fba82 100644
--- a/go.mod
+++ b/go.mod
@@ -14,20 +14,20 @@ require (
github.com/nats-io/nats.go v1.10.0
github.com/peterh/liner v1.2.1
github.com/streadway/amqp v1.0.0
- github.com/tidwall/btree v0.3.0
- github.com/tidwall/buntdb v1.2.0
- github.com/tidwall/geoindex v1.4.1
- github.com/tidwall/geojson v1.2.4
+ github.com/tidwall/btree v0.4.2
+ github.com/tidwall/buntdb v1.2.1
+ github.com/tidwall/geoindex v1.4.3
+ github.com/tidwall/geojson v1.2.7
github.com/tidwall/gjson v1.7.4
github.com/tidwall/lotsa v1.0.2 // indirect
github.com/tidwall/match v1.0.3
github.com/tidwall/pretty v1.1.0
github.com/tidwall/redbench v0.1.0
- github.com/tidwall/redcon v1.4.0
+ github.com/tidwall/redcon v1.4.1
github.com/tidwall/resp v0.1.0
github.com/tidwall/rhh v1.1.1
- github.com/tidwall/rtree v1.2.6
- github.com/tidwall/sjson v1.1.5
+ github.com/tidwall/rtree v1.2.7
+ github.com/tidwall/sjson v1.1.6
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
golang.org/x/net v0.0.0-20210119194325-5f4716e94777
diff --git a/go.sum b/go.sum
index 45adade8..910dc65c 100644
--- a/go.sum
+++ b/go.sum
@@ -182,46 +182,41 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
-github.com/tidwall/btree v0.2.2/go.mod h1:huei1BkDWJ3/sLXmO+bsCNELL+Bp2Kks9OLyQFkzvA8=
-github.com/tidwall/btree v0.3.0 h1:LcwmLI5kv+AaH/xnBgOuKfbu5eLBWVdWTpD2o+qSRdU=
-github.com/tidwall/btree v0.3.0/go.mod h1:huei1BkDWJ3/sLXmO+bsCNELL+Bp2Kks9OLyQFkzvA8=
-github.com/tidwall/buntdb v1.2.0 h1:8KOzf5Gg97DoCMSOgcwZjnM0FfROtq0fcZkPW54oGKU=
-github.com/tidwall/buntdb v1.2.0/go.mod h1:XLza/dhlwzO6dc5o/KWor4kfZSt3BP8QV+77ZMKfI58=
+github.com/tidwall/btree v0.4.2 h1:aLwwJlG+InuFzdAPuBf9YCAR1LvSQ9zhC5aorFPlIPs=
+github.com/tidwall/btree v0.4.2/go.mod h1:huei1BkDWJ3/sLXmO+bsCNELL+Bp2Kks9OLyQFkzvA8=
+github.com/tidwall/buntdb v1.2.1 h1:+s5TqjuAfo6IdMa8boDkCx5PzT2mlP5AwgNN4yxJba8=
+github.com/tidwall/buntdb v1.2.1/go.mod h1:4FUodsOaaFBuhPvQyTafaxVM5GFdQZnz98W3BaNmve4=
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.1 h1:dlhM+2isLqz8ndHn7vOCevD3IPH3XeO/BaFN4rLpimo=
-github.com/tidwall/geoindex v1.4.1/go.mod h1:NQJQszWCH4+KlD0wY+mgQ2hK/GdSH+9+ZRknDY8bOHc=
-github.com/tidwall/geojson v1.2.4 h1:INKsEJULXKiKSuFQZQ7Vy3v9zchg0VPtcQl2+KeTlvc=
-github.com/tidwall/geojson v1.2.4/go.mod h1:ZaA93utbJL8CLGaJ5L/M8gV/YC81lvW3ydzo5fI7yp0=
-github.com/tidwall/gjson v1.6.7/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
-github.com/tidwall/gjson v1.6.8/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
+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/gjson v1.7.4 h1:19cchw8FOxkG5mdLRkGf9jqIqEyqdZhPqW60XfyFxk8=
github.com/tidwall/gjson v1.7.4/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk=
-github.com/tidwall/grect v0.1.0 h1:ICcKWD5uu5A5fmxApGIa0QRvfGnSWKRd07POT08CQSA=
-github.com/tidwall/grect v0.1.0/go.mod h1:sa5O42oP6jWfTShL9ka6Sgmg3TgIK649veZe05B7+J8=
+github.com/tidwall/grect v0.1.1 h1:+kMEkxhoqB7rniVXzMEIA66XwU07STgINqxh+qVIndY=
+github.com/tidwall/grect v0.1.1/go.mod h1:CzvbGiFbWUwiJ1JohXLb28McpyBsI00TK9Y6pDWLGRQ=
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=
-github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
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.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
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/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.0 h1:y2PmDD55STRdy4S98qP/Dn+gZG+cPVvIDi9BJV2aOwA=
-github.com/tidwall/redcon v1.4.0/go.mod h1:IGzxyoKE3Ea5AWIXo/ZHP+hzY8sWXaMKr7KlFgcWSZU=
+github.com/tidwall/redcon v1.4.1 h1:oupK+lM1FeSGNhhZn85KvofEpboQReM1eIKNWTmD3K8=
+github.com/tidwall/redcon v1.4.1/go.mod h1:XwNPFbJ4ShWNNSA2Jazhbdje6jegTCcwFR6mfaADvHA=
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/rhh v1.1.1 h1:8zDpMKcK1pA1zU+Jyuo1UdzTFvME8pH3Sx/MdYgM5sE=
github.com/tidwall/rhh v1.1.1/go.mod h1:DmqiIRtSnlVEi5CSKqNaX6m3YTa3YNSYrGB4FlfdLUU=
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.6 h1:Q4FhJZId5k22IYsZ55Bz8nNo4Z9LyyOzWb+WIwc1vdM=
-github.com/tidwall/rtree v1.2.6/go.mod h1:fn56Cu3AyoR5U5LLQywyuTOCDF8Lq6GQCjLRSxnPAJI=
-github.com/tidwall/sjson v1.1.5 h1:wsUceI/XDyZk3J1FUvuuYlK62zJv2HO2Pzb8A5EWdUE=
-github.com/tidwall/sjson v1.1.5/go.mod h1:VuJzsZnTowhSxWdOgsAnb886i4AjEyTkk7tNtsL7EYE=
+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/sjson v1.1.6/go.mod h1:KN3FZ7odvXIHPbJdhNorK/M9lWweVUbXsXXhrJ/kGOA=
github.com/tidwall/tinyqueue v0.1.1 h1:SpNEvEggbpyN5DIReaJ2/1ndroY8iyEGxPYxoSaymYE=
github.com/tidwall/tinyqueue v0.1.1/go.mod h1:O/QNHwrnjqr6IHItYrzoHAKYhBkLI67Q096fQP5zMYw=
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I=
diff --git a/vendor/github.com/tidwall/btree/README.md b/vendor/github.com/tidwall/btree/README.md
index 0a3fa5dd..aa2c53a0 100644
--- a/vendor/github.com/tidwall/btree/README.md
+++ b/vendor/github.com/tidwall/btree/README.md
@@ -4,6 +4,13 @@
An [efficient](#performance) [B-tree](https://en.wikipedia.org/wiki/B-tree) implementation in Go.
+## Features
+
+- `Copy()` method with copy-on-write support.
+- Fast bulk loading for pre-ordered data using the `Load()` method.
+- All operations are thread-safe.
+- Path hinting optimization for operations with nearby keys.
+
## Installing
To start using btree, install Go and run `go get`:
@@ -150,33 +157,35 @@ This implementation was designed with performance in mind.
The following benchmarks were run on my 2019 Macbook Pro (2.4 GHz 8-Core Intel Core i9) using Go 1.15.3. The items are simple 8-byte ints.
-- `tidwall`: The [tidwall/btree](https://github.com/tidwall/btree) package
- `google`: The [google/btree](https://github.com/google/btree) package
+- `tidwall`: The [tidwall/btree](https://github.com/tidwall/btree) package
- `go-arr`: Just a simple Go array
```
** sequential set **
-tidwall: set-seq 1,000,000 ops in 143ms, 6,996,275/sec, 142 ns/op, 30.9 MB, 32 bytes/op
-tidwall: set-seq-hint 1,000,000 ops in 65ms, 15,441,082/sec, 64 ns/op, 30.9 MB, 32 bytes/op
-tidwall: load-seq 1,000,000 ops in 19ms, 53,242,398/sec, 18 ns/op, 30.9 MB, 32 bytes/op
-google: set-seq 1,000,000 ops in 175ms, 5,700,922/sec, 175 ns/op, 33.1 MB, 34 bytes/op
-go-arr: append 1,000,000 ops in 52ms, 19,153,714/sec, 52 ns/op, 41.3 MB, 43 bytes/op
+google: set-seq 1,000,000 ops in 160ms, 6,262,097/sec, 159 ns/op, 31.0 MB, 32 bytes/op
+tidwall: set-seq 1,000,000 ops in 142ms, 7,020,721/sec, 142 ns/op, 36.6 MB, 38 bytes/op
+tidwall: set-seq-hint 1,000,000 ops in 87ms, 11,503,315/sec, 86 ns/op, 36.6 MB, 38 bytes/op
+tidwall: load-seq 1,000,000 ops in 37ms, 27,177,242/sec, 36 ns/op, 36.6 MB, 38 bytes/op
+go-arr: append 1,000,000 ops in 49ms, 20,574,760/sec, 48 ns/op
** random set **
-tidwall: set-rand 1,000,000 ops in 589ms, 1,697,471/sec, 589 ns/op, 22.5 MB, 23 bytes/op
-tidwall: set-rand-hint 1,000,000 ops in 592ms, 1,688,184/sec, 592 ns/op, 22.2 MB, 23 bytes/op
-tidwall: load-rand 1,000,000 ops in 578ms, 1,728,932/sec, 578 ns/op, 22.3 MB, 23 bytes/op
-google: set-rand 1,000,000 ops in 662ms, 1,509,924/sec, 662 ns/op, 32.1 MB, 33 bytes/op
+google: set-rand 1,000,000 ops in 606ms, 1,649,921/sec, 606 ns/op, 21.5 MB, 22 bytes/op
+tidwall: set-rand 1,000,000 ops in 543ms, 1,841,590/sec, 543 ns/op, 26.7 MB, 27 bytes/op
+tidwall: set-rand-hint 1,000,000 ops in 573ms, 1,745,624/sec, 572 ns/op, 26.4 MB, 27 bytes/op
+tidwall: set-again 1,000,000 ops in 452ms, 2,212,581/sec, 451 ns/op, 27.1 MB, 28 bytes/op
+tidwall: set-after-copy 1,000,000 ops in 472ms, 2,117,457/sec, 472 ns/op, 27.9 MB, 29 bytes/op
+tidwall: load-rand 1,000,000 ops in 551ms, 1,816,498/sec, 550 ns/op, 26.1 MB, 27 bytes/op
** sequential get **
-tidwall: get-seq 1,000,000 ops in 111ms, 8,995,090/sec, 111 ns/op
-tidwall: get-seq-hint 1,000,000 ops in 56ms, 18,017,397/sec, 55 ns/op
-google: get-seq 1,000,000 ops in 135ms, 7,414,046/sec, 134 ns/op
+google: get-seq 1,000,000 ops in 133ms, 7,497,604/sec, 133 ns/op
+tidwall: get-seq 1,000,000 ops in 110ms, 9,082,972/sec, 110 ns/op
+tidwall: get-seq-hint 1,000,000 ops in 55ms, 18,289,945/sec, 54 ns/op
** random get **
-tidwall: get-rand 1,000,000 ops in 139ms, 7,214,017/sec, 138 ns/op
-tidwall: get-rand-hint 1,000,000 ops in 191ms, 5,243,833/sec, 190 ns/op
-google: get-rand 1,000,000 ops in 161ms, 6,199,818/sec, 161 ns/op
+google: get-rand 1,000,000 ops in 149ms, 6,704,337/sec, 149 ns/op
+tidwall: get-rand 1,000,000 ops in 131ms, 7,616,296/sec, 131 ns/op
+tidwall: get-rand-hint 1,000,000 ops in 216ms, 4,632,532/sec, 215 ns/op
```
*You can find the benchmark utility at [tidwall/btree-benchmark](https://github.com/tidwall/btree-benchmark)*
diff --git a/vendor/github.com/tidwall/btree/btree.go b/vendor/github.com/tidwall/btree/btree.go
index 86895317..9a2f2968 100644
--- a/vendor/github.com/tidwall/btree/btree.go
+++ b/vendor/github.com/tidwall/btree/btree.go
@@ -4,37 +4,39 @@
package btree
-//tinygen:T interface{}
+import "sync"
const maxItems = 255
const minItems = maxItems * 40 / 100
+type cow struct {
+ _ int // it cannot be an empty struct
+}
+
type node struct {
+ cow *cow
leaf bool
numItems int16
items [maxItems]interface{}
children *[maxItems + 1]*node
}
-type justaLeaf struct {
- leaf bool
- numItems int16
- items [maxItems]interface{}
-}
-
// BTree is an ordered set items
type BTree struct {
+ mu *sync.RWMutex
+ cow *cow
root *node
length int
less func(a, b interface{}) bool
lnode *node
}
-func newNode(leaf bool) *node {
+func (tr *BTree) newNode(leaf bool) *node {
n := &node{leaf: leaf}
if !leaf {
n.children = new([maxItems + 1]*node)
}
+ n.cow = tr.cow
return n
}
@@ -50,6 +52,7 @@ func New(less func(a, b interface{}) bool) *BTree {
panic("nil less")
}
tr := new(BTree)
+ tr.mu = new(sync.RWMutex)
tr.less = less
return tr
}
@@ -87,8 +90,7 @@ func (n *node) find(key interface{}, less func(a, b interface{}) bool,
high = mid - 1
}
}
- if low > 0 && !less(n.items[low-1], key) &&
- !less(key, n.items[low-1]) {
+ if low > 0 && !less(n.items[low-1], key) {
index = low - 1
found = true
} else {
@@ -111,22 +113,29 @@ func (tr *BTree) SetHint(item interface{}, hint *PathHint) (prev interface{}) {
if item == nil {
panic("nil item")
}
+ tr.mu.Lock()
+ prev = tr.setHint(item, hint)
+ tr.mu.Unlock()
+ return prev
+}
+
+func (tr *BTree) setHint(item interface{}, hint *PathHint) (prev interface{}) {
if tr.root == nil {
- tr.root = newNode(true)
+ tr.root = tr.newNode(true)
tr.root.items[0] = item
tr.root.numItems = 1
tr.length = 1
return
}
- prev = tr.root.set(item, tr.less, hint, 0)
+ prev = tr.nodeSet(&tr.root, item, tr.less, hint, 0)
if prev != nil {
return prev
}
tr.lnode = nil
if tr.root.numItems == maxItems {
- n := tr.root
- right, median := n.split()
- tr.root = newNode(false)
+ n := tr.cowLoad(&tr.root)
+ right, median := tr.nodeSplit(n)
+ tr.root = tr.newNode(false)
tr.root.children[0] = n
tr.root.items[0] = median
tr.root.children[1] = right
@@ -141,8 +150,8 @@ func (tr *BTree) Set(item interface{}) (prev interface{}) {
return tr.SetHint(item, nil)
}
-func (n *node) split() (right *node, median interface{}) {
- right = newNode(n.leaf)
+func (tr *BTree) nodeSplit(n *node) (right *node, median interface{}) {
+ right = tr.newNode(n.leaf)
median = n.items[maxItems/2]
copy(right.items[:maxItems/2], n.items[maxItems/2+1:])
if !n.leaf {
@@ -161,9 +170,30 @@ func (n *node) split() (right *node, median interface{}) {
return right, median
}
-func (n *node) set(item interface{}, less func(a, b interface{}) bool,
- hint *PathHint, depth int,
+//go:noinline
+func (tr *BTree) copy(n *node) *node {
+ n2 := *n
+ n2.cow = tr.cow
+ copy(n2.items[:], n.items[:])
+ if n.children != nil {
+ n2.children = new([maxItems + 1]*node)
+ copy(n2.children[:], n.children[:])
+ }
+ return &n2
+}
+
+// cowLoad loaded the provide node and, if needed, performs a copy-on-write.
+func (tr *BTree) cowLoad(cn **node) *node {
+ if (*cn).cow != tr.cow {
+ *cn = tr.copy(*cn)
+ }
+ return *cn
+}
+
+func (tr *BTree) nodeSet(cn **node, item interface{},
+ less func(a, b interface{}) bool, hint *PathHint, depth int,
) (prev interface{}) {
+ n := tr.cowLoad(cn)
i, found := n.find(item, less, hint, depth)
if found {
prev = n.items[i]
@@ -176,12 +206,12 @@ func (n *node) set(item interface{}, less func(a, b interface{}) bool,
n.numItems++
return nil
}
- prev = n.children[i].set(item, less, hint, depth+1)
+ prev = tr.nodeSet(&n.children[i], item, less, hint, depth+1)
if prev != nil {
return prev
}
if n.children[i].numItems == maxItems {
- right, median := n.children[i].split()
+ right, median := tr.nodeSplit(n.children[i])
copy(n.children[i+1:], n.children[i:])
copy(n.items[i+1:], n.items[i:])
n.items[i] = median
@@ -218,6 +248,8 @@ func (tr *BTree) Get(key interface{}) interface{} {
// GetHint gets a value for key using a path hint
func (tr *BTree) GetHint(key interface{}, hint *PathHint) interface{} {
+ tr.mu.RLock()
+ defer tr.mu.RUnlock()
if tr.root == nil || key == nil {
return nil
}
@@ -248,10 +280,17 @@ func (tr *BTree) Delete(key interface{}) interface{} {
// DeleteHint deletes a value for a key using a path hint
func (tr *BTree) DeleteHint(key interface{}, hint *PathHint) interface{} {
+ tr.mu.Lock()
+ prev := tr.deleteHint(key, hint)
+ tr.mu.Unlock()
+ return prev
+}
+
+func (tr *BTree) deleteHint(key interface{}, hint *PathHint) interface{} {
if tr.root == nil || key == nil {
return nil
}
- prev := tr.root.delete(false, key, tr.less, hint, 0)
+ prev := tr.delete(&tr.root, false, key, tr.less, hint, 0)
if prev == nil {
return nil
}
@@ -266,9 +305,10 @@ func (tr *BTree) DeleteHint(key interface{}, hint *PathHint) interface{} {
return prev
}
-func (n *node) delete(max bool, key interface{},
+func (tr *BTree) delete(cn **node, max bool, key interface{},
less func(a, b interface{}) bool, hint *PathHint, depth int,
) interface{} {
+ n := tr.cowLoad(cn)
var i int16
var found bool
if max {
@@ -292,74 +332,79 @@ func (n *node) delete(max bool, key interface{},
if found {
if max {
i++
- prev = n.children[i].delete(true, "", less, nil, 0)
+ prev = tr.delete(&n.children[i], true, "", less, nil, 0)
} else {
prev = n.items[i]
- maxItem := n.children[i].delete(true, "", less, nil, 0)
+ maxItem := tr.delete(&n.children[i], true, "", less, nil, 0)
n.items[i] = maxItem
}
} else {
- prev = n.children[i].delete(max, key, less, hint, depth+1)
+ prev = tr.delete(&n.children[i], max, key, less, hint, depth+1)
}
if prev == nil {
return nil
}
- if n.children[i].numItems < minItems {
- if i == n.numItems {
- i--
+ if n.children[i].numItems >= minItems {
+ return prev
+ }
+
+ // merge / rebalance nodes
+ if i == n.numItems {
+ i--
+ }
+ n.children[i] = tr.cowLoad(&n.children[i])
+ n.children[i+1] = tr.cowLoad(&n.children[i+1])
+ if n.children[i].numItems+n.children[i+1].numItems+1 < maxItems {
+ // merge left + item + right
+ n.children[i].items[n.children[i].numItems] = n.items[i]
+ copy(n.children[i].items[n.children[i].numItems+1:],
+ n.children[i+1].items[:n.children[i+1].numItems])
+ if !n.children[0].leaf {
+ copy(n.children[i].children[n.children[i].numItems+1:],
+ n.children[i+1].children[:n.children[i+1].numItems+1])
}
- if n.children[i].numItems+n.children[i+1].numItems+1 < maxItems {
- // merge left + item + right
- n.children[i].items[n.children[i].numItems] = n.items[i]
- copy(n.children[i].items[n.children[i].numItems+1:],
- n.children[i+1].items[:n.children[i+1].numItems])
- if !n.children[0].leaf {
- copy(n.children[i].children[n.children[i].numItems+1:],
- n.children[i+1].children[:n.children[i+1].numItems+1])
- }
- n.children[i].numItems += n.children[i+1].numItems + 1
- copy(n.items[i:], n.items[i+1:n.numItems])
- copy(n.children[i+1:], n.children[i+2:n.numItems+1])
- n.items[n.numItems] = nil
- n.children[n.numItems+1] = nil
- n.numItems--
- } else if n.children[i].numItems > n.children[i+1].numItems {
- // move left -> right
- copy(n.children[i+1].items[1:],
- n.children[i+1].items[:n.children[i+1].numItems])
- if !n.children[0].leaf {
- copy(n.children[i+1].children[1:],
- n.children[i+1].children[:n.children[i+1].numItems+1])
- }
- n.children[i+1].items[0] = n.items[i]
- if !n.children[0].leaf {
- n.children[i+1].children[0] =
- n.children[i].children[n.children[i].numItems]
- }
- n.children[i+1].numItems++
- n.items[i] = n.children[i].items[n.children[i].numItems-1]
- n.children[i].items[n.children[i].numItems-1] = nil
- if !n.children[0].leaf {
- n.children[i].children[n.children[i].numItems] = nil
- }
- n.children[i].numItems--
- } else {
- // move right -> left
- n.children[i].items[n.children[i].numItems] = n.items[i]
- if !n.children[0].leaf {
- n.children[i].children[n.children[i].numItems+1] =
- n.children[i+1].children[0]
- }
- n.children[i].numItems++
- n.items[i] = n.children[i+1].items[0]
- copy(n.children[i+1].items[:],
- n.children[i+1].items[1:n.children[i+1].numItems])
- if !n.children[0].leaf {
- copy(n.children[i+1].children[:],
- n.children[i+1].children[1:n.children[i+1].numItems+1])
- }
- n.children[i+1].numItems--
+ n.children[i].numItems += n.children[i+1].numItems + 1
+ copy(n.items[i:], n.items[i+1:n.numItems])
+ copy(n.children[i+1:], n.children[i+2:n.numItems+1])
+ n.items[n.numItems] = nil
+ n.children[n.numItems+1] = nil
+ n.numItems--
+ } else if n.children[i].numItems > n.children[i+1].numItems {
+ // move left -> right
+ copy(n.children[i+1].items[1:],
+ n.children[i+1].items[:n.children[i+1].numItems])
+ if !n.children[0].leaf {
+ copy(n.children[i+1].children[1:],
+ n.children[i+1].children[:n.children[i+1].numItems+1])
}
+ n.children[i+1].items[0] = n.items[i]
+ if !n.children[0].leaf {
+ n.children[i+1].children[0] =
+ n.children[i].children[n.children[i].numItems]
+ }
+ n.children[i+1].numItems++
+ n.items[i] = n.children[i].items[n.children[i].numItems-1]
+ n.children[i].items[n.children[i].numItems-1] = nil
+ if !n.children[0].leaf {
+ n.children[i].children[n.children[i].numItems] = nil
+ }
+ n.children[i].numItems--
+ } else {
+ // move right -> left
+ n.children[i].items[n.children[i].numItems] = n.items[i]
+ if !n.children[0].leaf {
+ n.children[i].children[n.children[i].numItems+1] =
+ n.children[i+1].children[0]
+ }
+ n.children[i].numItems++
+ n.items[i] = n.children[i+1].items[0]
+ copy(n.children[i+1].items[:],
+ n.children[i+1].items[1:n.children[i+1].numItems])
+ if !n.children[0].leaf {
+ copy(n.children[i+1].children[:],
+ n.children[i+1].children[1:n.children[i+1].numItems+1])
+ }
+ n.children[i+1].numItems--
}
return prev
}
@@ -368,6 +413,8 @@ func (n *node) delete(max bool, key interface{},
// Pass nil for pivot to scan all item in ascending order
// Return false to stop iterating
func (tr *BTree) Ascend(pivot interface{}, iter func(item interface{}) bool) {
+ tr.mu.RLock()
+ defer tr.mu.RUnlock()
if tr.root == nil {
return
}
@@ -429,6 +476,8 @@ func (n *node) reverse(iter func(item interface{}) bool) bool {
// Pass nil for pivot to scan all item in descending order
// Return false to stop iterating
func (tr *BTree) Descend(pivot interface{}, iter func(item interface{}) bool) {
+ tr.mu.RLock()
+ defer tr.mu.RUnlock()
if tr.root == nil {
return
}
@@ -469,6 +518,12 @@ func (tr *BTree) Load(item interface{}) interface{} {
if item == nil {
panic("nil item")
}
+ tr.mu.Lock()
+ defer tr.mu.Unlock()
+
+ // Load does not need a cowGrid because the Copy operation sets the
+ // lnode to nil.
+
if tr.lnode != nil && tr.lnode.numItems < maxItems-2 {
if tr.less(tr.lnode.items[tr.lnode.numItems-1], item) {
tr.lnode.items[tr.lnode.numItems] = item
@@ -477,7 +532,7 @@ func (tr *BTree) Load(item interface{}) interface{} {
return nil
}
}
- prev := tr.Set(item)
+ prev := tr.setHint(item, nil)
if prev != nil {
return prev
}
@@ -495,6 +550,8 @@ func (tr *BTree) Load(item interface{}) interface{} {
// Min returns the minimum item in tree.
// Returns nil if the tree has no items.
func (tr *BTree) Min() interface{} {
+ tr.mu.RLock()
+ defer tr.mu.RUnlock()
if tr.root == nil {
return nil
}
@@ -510,6 +567,8 @@ func (tr *BTree) Min() interface{} {
// Max returns the maximum item in tree.
// Returns nil if the tree has no items.
func (tr *BTree) Max() interface{} {
+ tr.mu.RLock()
+ defer tr.mu.RUnlock()
if tr.root == nil {
return nil
}
@@ -525,53 +584,65 @@ func (tr *BTree) Max() interface{} {
// PopMin removes the minimum item in tree and returns it.
// Returns nil if the tree has no items.
func (tr *BTree) PopMin() interface{} {
+ tr.mu.Lock()
+ defer tr.mu.Unlock()
if tr.root == nil {
return nil
}
tr.lnode = nil
- n := tr.root
+ n := tr.cowLoad(&tr.root)
for {
if n.leaf {
item := n.items[0]
if n.numItems == minItems {
- return tr.Delete(item)
+ return tr.deleteHint(item, nil)
}
copy(n.items[:], n.items[1:])
n.items[n.numItems-1] = nil
n.numItems--
tr.length--
+ if tr.length == 0 {
+ tr.root = nil
+ }
return item
}
- n = n.children[0]
+ n = tr.cowLoad(&n.children[0])
}
}
// PopMax removes the minimum item in tree and returns it.
// Returns nil if the tree has no items.
func (tr *BTree) PopMax() interface{} {
+ tr.mu.Lock()
+ defer tr.mu.Unlock()
if tr.root == nil {
return nil
}
tr.lnode = nil
- n := tr.root
+ n := tr.cowLoad(&tr.root)
for {
if n.leaf {
item := n.items[n.numItems-1]
if n.numItems == minItems {
- return tr.Delete(item)
+ return tr.deleteHint(item, nil)
}
n.items[n.numItems-1] = nil
n.numItems--
tr.length--
+ if tr.length == 0 {
+ tr.root = nil
+ }
return item
}
- n = n.children[n.numItems]
+ n = tr.cowLoad(&n.children[n.numItems])
}
}
// Height returns the height of the tree.
// Returns zero if tree has no items.
func (tr *BTree) Height() int {
+ tr.mu.RLock()
+ defer tr.mu.RUnlock()
var height int
if tr.root != nil {
n := tr.root
@@ -589,6 +660,8 @@ func (tr *BTree) Height() int {
// Walk iterates over all items in tree, in order.
// The items param will contain one or more items.
func (tr *BTree) Walk(iter func(item []interface{})) {
+ tr.mu.RLock()
+ defer tr.mu.RUnlock()
if tr.root != nil {
tr.root.walk(iter)
}
@@ -605,3 +678,16 @@ func (n *node) walk(iter func(item []interface{})) {
n.children[n.numItems].walk(iter)
}
}
+
+// Copy the tree. This operation is very fast because it only performs a
+// shadowed copy.
+func (tr *BTree) Copy() *BTree {
+ tr.mu.Lock()
+ tr.lnode = nil
+ tr.cow = new(cow)
+ tr2 := *tr
+ tr2.mu = new(sync.RWMutex)
+ tr2.cow = new(cow)
+ tr.mu.Unlock()
+ return &tr2
+}
diff --git a/vendor/github.com/tidwall/buntdb/buntdb.go b/vendor/github.com/tidwall/buntdb/buntdb.go
index c47c3a0e..243e873a 100644
--- a/vendor/github.com/tidwall/buntdb/buntdb.go
+++ b/vendor/github.com/tidwall/buntdb/buntdb.go
@@ -69,7 +69,6 @@ type DB struct {
keys *btree.BTree // a tree of all item ordered by key
exps *btree.BTree // a tree of items ordered by expiration
idxs map[string]*index // the index trees.
- exmgr bool // indicates that expires manager is running.
flushes int // a count of the number of disk flushes
closed bool // set when the database has been closed
config Config // the database configuration
@@ -135,9 +134,6 @@ type exctx struct {
db *DB
}
-// Default number of btree degrees
-const btreeDegrees = 64
-
// Open opens a database at the provided path.
// If the file does not exist then it will be created automatically.
func Open(path string) (*DB, error) {
@@ -241,7 +237,8 @@ func (db *DB) Load(rd io.Reader) error {
// cannot load into databases that persist to disk
return ErrPersistenceActive
}
- return db.readLoad(rd, time.Now())
+ _, err := db.readLoad(rd, time.Now())
+ return err
}
// index represents a b-tree or r-tree index and also acts as the
@@ -755,46 +752,65 @@ func (db *DB) Shrink() error {
}()
}
-var errValidEOF = errors.New("valid eof")
-
// readLoad reads from the reader and loads commands into the database.
// modTime is the modified time of the reader, should be no greater than
// the current time.Now().
-func (db *DB) readLoad(rd io.Reader, modTime time.Time) error {
+// Returns the number of bytes of the last command read and the error if any.
+func (db *DB) readLoad(rd io.Reader, modTime time.Time) (n int64, err error) {
+ defer func() {
+ if err == io.EOF {
+ err = io.ErrUnexpectedEOF
+ }
+ }()
+ totalSize := int64(0)
data := make([]byte, 4096)
parts := make([]string, 0, 8)
r := bufio.NewReader(rd)
for {
+ // peek at the first byte. If it's a 'nul' control character then
+ // ignore it and move to the next byte.
+ c, err := r.ReadByte()
+ if err != nil {
+ if err == io.EOF {
+ err = nil
+ }
+ return totalSize, err
+ }
+ if c == 0 {
+ // ignore nul control characters
+ n += 1
+ continue
+ }
+ if err := r.UnreadByte(); err != nil {
+ return totalSize, err
+ }
+
// read a single command.
// first we should read the number of parts that the of the command
+ cmdByteSize := int64(0)
line, err := r.ReadBytes('\n')
if err != nil {
- if len(line) > 0 {
- // got an eof but also data. this should be an unexpected eof.
- return io.ErrUnexpectedEOF
- }
- if err == io.EOF {
- break
- }
- return err
+ return totalSize, err
}
if line[0] != '*' {
- return ErrInvalid
+ return totalSize, ErrInvalid
}
+ cmdByteSize += int64(len(line))
+
// convert the string number to and int
var n int
if len(line) == 4 && line[len(line)-2] == '\r' {
if line[1] < '0' || line[1] > '9' {
- return ErrInvalid
+ return totalSize, ErrInvalid
}
n = int(line[1] - '0')
} else {
if len(line) < 5 || line[len(line)-2] != '\r' {
- return ErrInvalid
+ return totalSize, ErrInvalid
}
for i := 1; i < len(line)-2; i++ {
if line[i] < '0' || line[i] > '9' {
- return ErrInvalid
+ return totalSize, ErrInvalid
}
n = n*10 + int(line[i]-'0')
}
@@ -805,25 +821,26 @@ func (db *DB) readLoad(rd io.Reader, modTime time.Time) error {
// read the number of bytes of the part.
line, err := r.ReadBytes('\n')
if err != nil {
- return err
+ return totalSize, err
}
if line[0] != '$' {
- return ErrInvalid
+ return totalSize, ErrInvalid
}
+ cmdByteSize += int64(len(line))
// convert the string number to and int
var n int
if len(line) == 4 && line[len(line)-2] == '\r' {
if line[1] < '0' || line[1] > '9' {
- return ErrInvalid
+ return totalSize, ErrInvalid
}
n = int(line[1] - '0')
} else {
if len(line) < 5 || line[len(line)-2] != '\r' {
- return ErrInvalid
+ return totalSize, ErrInvalid
}
for i := 1; i < len(line)-2; i++ {
if line[i] < '0' || line[i] > '9' {
- return ErrInvalid
+ return totalSize, ErrInvalid
}
n = n*10 + int(line[i]-'0')
}
@@ -837,10 +854,10 @@ func (db *DB) readLoad(rd io.Reader, modTime time.Time) error {
data = make([]byte, dataln)
}
if _, err = io.ReadFull(r, data[:n+2]); err != nil {
- return err
+ return totalSize, err
}
if data[n] != '\r' || data[n+1] != '\n' {
- return ErrInvalid
+ return totalSize, ErrInvalid
}
// copy string
parts = append(parts, string(data[:n]))
@@ -855,15 +872,15 @@ func (db *DB) readLoad(rd io.Reader, modTime time.Time) error {
(parts[0][2] == 't' || parts[0][2] == 'T') {
// SET
if len(parts) < 3 || len(parts) == 4 || len(parts) > 5 {
- return ErrInvalid
+ return totalSize, ErrInvalid
}
if len(parts) == 5 {
if strings.ToLower(parts[3]) != "ex" {
- return ErrInvalid
+ return totalSize, ErrInvalid
}
ex, err := strconv.ParseUint(parts[4], 10, 64)
if err != nil {
- return err
+ return totalSize, err
}
now := time.Now()
dur := (time.Duration(ex) * time.Second) - now.Sub(modTime)
@@ -885,7 +902,7 @@ func (db *DB) readLoad(rd io.Reader, modTime time.Time) error {
(parts[0][2] == 'l' || parts[0][2] == 'L') {
// DEL
if len(parts) != 2 {
- return ErrInvalid
+ return totalSize, ErrInvalid
}
db.deleteFromDatabase(&dbItem{key: parts[1]})
} else if (parts[0][0] == 'f' || parts[0][0] == 'F') &&
@@ -894,10 +911,10 @@ func (db *DB) readLoad(rd io.Reader, modTime time.Time) error {
db.exps = btree.New(lessCtx(&exctx{db}))
db.idxs = make(map[string]*index)
} else {
- return ErrInvalid
+ return totalSize, ErrInvalid
}
+ totalSize += cmdByteSize
}
- return nil
}
// load reads entries from the append only database file and fills the database.
@@ -910,10 +927,20 @@ func (db *DB) load() error {
if err != nil {
return err
}
- if err := db.readLoad(db.file, fi.ModTime()); err != nil {
- return err
+ n, err := db.readLoad(db.file, fi.ModTime())
+ if err != nil {
+ if err == io.ErrUnexpectedEOF {
+ // The db file has ended mid-command, which is allowed but the
+ // data file should be truncated to the end of the last valid
+ // command
+ if err := db.file.Truncate(n); err != nil {
+ return err
+ }
+ } else {
+ return err
+ }
}
- pos, err := db.file.Seek(0, 2)
+ pos, err := db.file.Seek(n, 0)
if err != nil {
return err
}
@@ -1216,7 +1243,7 @@ func appendBulkString(buf []byte, s string) []byte {
// writeSetTo writes an item as a single SET record to the a bufio Writer.
func (dbi *dbItem) writeSetTo(buf []byte) []byte {
if dbi.opts != nil && dbi.opts.ex {
- ex := dbi.opts.exat.Sub(time.Now()) / time.Second
+ ex := time.Until(dbi.opts.exat) / time.Second
buf = appendArray(buf, 5)
buf = appendBulkString(buf, "set")
buf = appendBulkString(buf, dbi.key)
@@ -1483,7 +1510,7 @@ func (tx *Tx) TTL(key string) (time.Duration, error) {
} else if item.opts == nil || !item.opts.ex {
return -1, nil
}
- dur := item.opts.exat.Sub(time.Now())
+ dur := time.Until(item.opts.exat)
if dur < 0 {
return 0, ErrNotFound
}
diff --git a/vendor/github.com/tidwall/buntdb/go.mod b/vendor/github.com/tidwall/buntdb/go.mod
index cc39e696..85a2d8ec 100644
--- a/vendor/github.com/tidwall/buntdb/go.mod
+++ b/vendor/github.com/tidwall/buntdb/go.mod
@@ -1,11 +1,11 @@
module github.com/tidwall/buntdb
-go 1.15
+go 1.16
require (
- github.com/tidwall/btree v0.3.0
- github.com/tidwall/gjson v1.6.8
- github.com/tidwall/grect v0.1.0
+ github.com/tidwall/btree v0.4.2
+ github.com/tidwall/gjson v1.7.4
+ github.com/tidwall/grect v0.1.1
github.com/tidwall/match v1.0.3
github.com/tidwall/rtred v0.1.2
)
diff --git a/vendor/github.com/tidwall/buntdb/go.sum b/vendor/github.com/tidwall/buntdb/go.sum
index d00c00d0..38dd895f 100644
--- a/vendor/github.com/tidwall/buntdb/go.sum
+++ b/vendor/github.com/tidwall/buntdb/go.sum
@@ -1,14 +1,13 @@
-github.com/tidwall/btree v0.3.0 h1:LcwmLI5kv+AaH/xnBgOuKfbu5eLBWVdWTpD2o+qSRdU=
-github.com/tidwall/btree v0.3.0/go.mod h1:huei1BkDWJ3/sLXmO+bsCNELL+Bp2Kks9OLyQFkzvA8=
-github.com/tidwall/gjson v1.6.7/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
-github.com/tidwall/gjson v1.6.8 h1:CTmXMClGYPAmln7652e69B7OLXfTi5ABcPPwjIWUv7w=
-github.com/tidwall/gjson v1.6.8/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
-github.com/tidwall/grect v0.1.0 h1:ICcKWD5uu5A5fmxApGIa0QRvfGnSWKRd07POT08CQSA=
-github.com/tidwall/grect v0.1.0/go.mod h1:sa5O42oP6jWfTShL9ka6Sgmg3TgIK649veZe05B7+J8=
+github.com/tidwall/btree v0.4.2 h1:aLwwJlG+InuFzdAPuBf9YCAR1LvSQ9zhC5aorFPlIPs=
+github.com/tidwall/btree v0.4.2/go.mod h1:huei1BkDWJ3/sLXmO+bsCNELL+Bp2Kks9OLyQFkzvA8=
+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/grect v0.1.1 h1:+kMEkxhoqB7rniVXzMEIA66XwU07STgINqxh+qVIndY=
+github.com/tidwall/grect v0.1.1/go.mod h1:CzvbGiFbWUwiJ1JohXLb28McpyBsI00TK9Y6pDWLGRQ=
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.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
-github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
+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/rtred v0.1.2 h1:exmoQtOLvDoO8ud++6LwVsAMTu0KPzLTUrMln8u1yu8=
github.com/tidwall/rtred v0.1.2/go.mod h1:hd69WNXQ5RP9vHd7dqekAz+RIdtfBogmglkZSRxCHFQ=
github.com/tidwall/tinyqueue v0.1.1 h1:SpNEvEggbpyN5DIReaJ2/1ndroY8iyEGxPYxoSaymYE=
diff --git a/vendor/github.com/tidwall/geoindex/geoindex.go b/vendor/github.com/tidwall/geoindex/geoindex.go
index e811a9d6..9ce5a7ac 100644
--- a/vendor/github.com/tidwall/geoindex/geoindex.go
+++ b/vendor/github.com/tidwall/geoindex/geoindex.go
@@ -40,7 +40,7 @@ type Interface interface {
// Index is a wrapper around Interface that provides extra features like a
// Nearby (kNN) function.
// This can be created like such:
-// var tree = rbang.New()
+// var tree = &rtree.RTree{}
// var index = index.Index{tree}
// Now you can use `index` just like tree but with the extra features.
type Index struct {
@@ -143,47 +143,36 @@ func (index *Index) Scan(
func (index *Index) svg(child child.Child, height int) []byte {
var out []byte
- point := true
- for i := 0; i < 2; i++ {
- if child.Min[i] != child.Max[i] {
- point = false
- break
- }
- }
- if point { // is point
- out = append(out, fmt.Sprintf(
- "\n",
- (child.Min[0])*svgScale,
- (child.Min[1])*svgScale,
- (child.Max[0]-child.Min[0]+1/svgScale)*svgScale,
- (child.Max[1]-child.Min[1]+1/svgScale)*svgScale,
- strokes[height%len(strokes)])...)
- } else { // is rect
- out = append(out, fmt.Sprintf(
- "\n",
- (child.Min[0])*svgScale,
- (child.Min[1])*svgScale,
- (child.Max[0]-child.Min[0]+1/svgScale)*svgScale,
- (child.Max[1]-child.Min[1]+1/svgScale)*svgScale,
- strokes[height%len(strokes)])...)
- }
+
if !child.Item {
+ out = append(out, fmt.Sprintf(
+ "\n",
+ (child.Min[0])*svgScale,
+ (child.Min[1])*svgScale,
+ (child.Max[0]-child.Min[0]+1/svgScale)*svgScale,
+ (child.Max[1]-child.Min[1]+1/svgScale)*svgScale,
+ strokes[height%len(strokes)])...)
children := index.tree.Children(child.Data, nil)
for _, child := range children {
out = append(out, index.svg(child, height+1)...)
}
+ } else {
+ out = append(out, fmt.Sprintf(
+ "\n",
+ (child.Min[0])*svgScale,
+ (child.Min[1])*svgScale,
+ (child.Max[0]-child.Min[0]+1/svgScale)*svgScale,
+ (child.Max[1]-child.Min[1]+1/svgScale)*svgScale,
+ strokes[len(strokes)-1])...)
}
return out
}
-const svgScale = 4.0
+const svgScale = 5.0
-var strokes = [...]string{"black", "#cccc00", "green", "red", "purple"}
+var strokes = [...]string{"purple", "red", "#009900", "#cccc00", "black"}
// SVG prints 2D rtree in wgs84 coordinate space
func (index *Index) SVG() string {
diff --git a/vendor/github.com/tidwall/geoindex/tests.go b/vendor/github.com/tidwall/geoindex/tests.go
index 782586db..76fdf786 100644
--- a/vendor/github.com/tidwall/geoindex/tests.go
+++ b/vendor/github.com/tidwall/geoindex/tests.go
@@ -7,7 +7,6 @@ import (
"os"
"sort"
"testing"
- "time"
"github.com/tidwall/cities"
"github.com/tidwall/geoindex/algo"
@@ -133,7 +132,6 @@ func benchVariousKind(t *testing.T, tr Interface, numPointOrRects int,
kind byte,
) {
N := numPointOrRects
- rand.Seed(time.Now().UnixNano())
rects := make([]rect, N)
for i := 0; i < N; i++ {
rects[i] = randRect(kind)
@@ -445,7 +443,8 @@ func benchmarkRandomInsert(b *testing.B, tr Interface) {
func testCitiesSVG(t *testing.T, tr Interface) {
index := Wrap(tr)
- for _, city := range cities.Cities {
+ for _, i := range rand.Perm(len(cities.Cities)) {
+ city := cities.Cities[i]
p := [2]float64{city.Longitude, city.Latitude}
index.Insert(p, p, &city)
}
diff --git a/vendor/github.com/tidwall/geojson/go.mod b/vendor/github.com/tidwall/geojson/go.mod
index 0c5cd67a..34237622 100644
--- a/vendor/github.com/tidwall/geojson/go.mod
+++ b/vendor/github.com/tidwall/geojson/go.mod
@@ -3,9 +3,9 @@ module github.com/tidwall/geojson
go 1.15
require (
- github.com/tidwall/gjson v1.6.8
+ github.com/tidwall/gjson v1.7.4
github.com/tidwall/lotsa v1.0.1
- github.com/tidwall/pretty v1.0.2
- github.com/tidwall/rtree v1.2.6
- github.com/tidwall/sjson v1.1.5
+ github.com/tidwall/pretty v1.1.0
+ github.com/tidwall/rtree v1.2.7
+ github.com/tidwall/sjson v1.1.6
)
diff --git a/vendor/github.com/tidwall/geojson/go.sum b/vendor/github.com/tidwall/geojson/go.sum
index ddd169ce..88430413 100644
--- a/vendor/github.com/tidwall/geojson/go.sum
+++ b/vendor/github.com/tidwall/geojson/go.sum
@@ -1,15 +1,16 @@
+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.1 h1:dlhM+2isLqz8ndHn7vOCevD3IPH3XeO/BaFN4rLpimo=
-github.com/tidwall/geoindex v1.4.1/go.mod h1:NQJQszWCH4+KlD0wY+mgQ2hK/GdSH+9+ZRknDY8bOHc=
-github.com/tidwall/gjson v1.6.8 h1:CTmXMClGYPAmln7652e69B7OLXfTi5ABcPPwjIWUv7w=
-github.com/tidwall/gjson v1.6.8/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
+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/gjson v1.7.4 h1:19cchw8FOxkG5mdLRkGf9jqIqEyqdZhPqW60XfyFxk8=
+github.com/tidwall/gjson v1.7.4/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk=
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/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
-github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
-github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
-github.com/tidwall/rtree v1.2.6 h1:Q4FhJZId5k22IYsZ55Bz8nNo4Z9LyyOzWb+WIwc1vdM=
-github.com/tidwall/rtree v1.2.6/go.mod h1:fn56Cu3AyoR5U5LLQywyuTOCDF8Lq6GQCjLRSxnPAJI=
-github.com/tidwall/sjson v1.1.5 h1:wsUceI/XDyZk3J1FUvuuYlK62zJv2HO2Pzb8A5EWdUE=
-github.com/tidwall/sjson v1.1.5/go.mod h1:VuJzsZnTowhSxWdOgsAnb886i4AjEyTkk7tNtsL7EYE=
+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/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/sjson v1.1.6/go.mod h1:KN3FZ7odvXIHPbJdhNorK/M9lWweVUbXsXXhrJ/kGOA=
diff --git a/vendor/github.com/tidwall/grect/go.mod b/vendor/github.com/tidwall/grect/go.mod
index f34a5aa3..9399750d 100644
--- a/vendor/github.com/tidwall/grect/go.mod
+++ b/vendor/github.com/tidwall/grect/go.mod
@@ -2,4 +2,4 @@ module github.com/tidwall/grect
go 1.15
-require github.com/tidwall/gjson v1.6.7
+require github.com/tidwall/gjson v1.7.4
diff --git a/vendor/github.com/tidwall/grect/go.sum b/vendor/github.com/tidwall/grect/go.sum
index a665a35c..7dd8de53 100644
--- a/vendor/github.com/tidwall/grect/go.sum
+++ b/vendor/github.com/tidwall/grect/go.sum
@@ -1,6 +1,6 @@
-github.com/tidwall/gjson v1.6.7 h1:Mb1M9HZCRWEcXQ8ieJo7auYyyiSux6w9XN3AdTpxJrE=
-github.com/tidwall/gjson v1.6.7/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
+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/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
-github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
-github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
+github.com/tidwall/pretty v1.1.0 h1:K3hMW5epkdAVwibsQEfR/7Zj0Qgt4DxtNumTq/VloO8=
+github.com/tidwall/pretty v1.1.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
diff --git a/vendor/github.com/tidwall/redcon/README.md b/vendor/github.com/tidwall/redcon/README.md
index 2c991a7b..d6acf35b 100644
--- a/vendor/github.com/tidwall/redcon/README.md
+++ b/vendor/github.com/tidwall/redcon/README.md
@@ -6,9 +6,7 @@
-Fast Redis compatible server framework for Go
-
-Redcon is a custom Redis server framework for Go that is fast and simple to use. The reason for this library it to give an efficient server front-end for the [BuntDB](https://github.com/tidwall/buntdb) and [Tile38](https://github.com/tidwall/tile38) projects.
+Redis compatible server framework for Go
Features
--------
diff --git a/vendor/github.com/tidwall/redcon/go.mod b/vendor/github.com/tidwall/redcon/go.mod
index bb6ad5a4..2b3dcada 100644
--- a/vendor/github.com/tidwall/redcon/go.mod
+++ b/vendor/github.com/tidwall/redcon/go.mod
@@ -3,6 +3,6 @@ module github.com/tidwall/redcon
go 1.15
require (
- github.com/tidwall/btree v0.2.2
- github.com/tidwall/match v1.0.1
+ github.com/tidwall/btree v0.4.2
+ github.com/tidwall/match v1.0.3
)
diff --git a/vendor/github.com/tidwall/redcon/go.sum b/vendor/github.com/tidwall/redcon/go.sum
index 34a771c7..7ff4f442 100644
--- a/vendor/github.com/tidwall/redcon/go.sum
+++ b/vendor/github.com/tidwall/redcon/go.sum
@@ -1,4 +1,4 @@
-github.com/tidwall/btree v0.2.2 h1:VVo0JW/tdidNdQzNsDR4wMbL3heaxA1DGleyzQ3/niY=
-github.com/tidwall/btree v0.2.2/go.mod h1:huei1BkDWJ3/sLXmO+bsCNELL+Bp2Kks9OLyQFkzvA8=
-github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
-github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
+github.com/tidwall/btree v0.4.2 h1:aLwwJlG+InuFzdAPuBf9YCAR1LvSQ9zhC5aorFPlIPs=
+github.com/tidwall/btree v0.4.2/go.mod h1:huei1BkDWJ3/sLXmO+bsCNELL+Bp2Kks9OLyQFkzvA8=
+github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
+github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
diff --git a/vendor/github.com/tidwall/redcon/redcon.go b/vendor/github.com/tidwall/redcon/redcon.go
index 63d497f7..46b7d654 100644
--- a/vendor/github.com/tidwall/redcon/redcon.go
+++ b/vendor/github.com/tidwall/redcon/redcon.go
@@ -924,6 +924,22 @@ func (rd *Reader) readCommands(leftover *int) ([]Command, error) {
return rd.readCommands(leftover)
}
+// ReadCommands reads the next pipeline commands.
+func (rd *Reader) ReadCommands() ([]Command, error) {
+ for {
+ if len(rd.cmds) > 0 {
+ cmds := rd.cmds
+ rd.cmds = nil
+ return cmds, nil
+ }
+ cmds, err := rd.readCommands(nil)
+ if err != nil {
+ return []Command{}, err
+ }
+ rd.cmds = cmds
+ }
+}
+
// ReadCommand reads the next command.
func (rd *Reader) ReadCommand() (Command, error) {
if len(rd.cmds) > 0 {
diff --git a/vendor/github.com/tidwall/rtree/go.mod b/vendor/github.com/tidwall/rtree/go.mod
index feef5de8..cab37c7d 100644
--- a/vendor/github.com/tidwall/rtree/go.mod
+++ b/vendor/github.com/tidwall/rtree/go.mod
@@ -2,4 +2,4 @@ module github.com/tidwall/rtree
go 1.15
-require github.com/tidwall/geoindex v1.4.1
+require github.com/tidwall/geoindex v1.4.3
diff --git a/vendor/github.com/tidwall/rtree/go.sum b/vendor/github.com/tidwall/rtree/go.sum
index 906e5d35..b67291e6 100644
--- a/vendor/github.com/tidwall/rtree/go.sum
+++ b/vendor/github.com/tidwall/rtree/go.sum
@@ -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.1 h1:dlhM+2isLqz8ndHn7vOCevD3IPH3XeO/BaFN4rLpimo=
-github.com/tidwall/geoindex v1.4.1/go.mod h1:NQJQszWCH4+KlD0wY+mgQ2hK/GdSH+9+ZRknDY8bOHc=
+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=
diff --git a/vendor/github.com/tidwall/rtree/rtree.go b/vendor/github.com/tidwall/rtree/rtree.go
index 9d458c79..efe1606c 100644
--- a/vendor/github.com/tidwall/rtree/rtree.go
+++ b/vendor/github.com/tidwall/rtree/rtree.go
@@ -4,7 +4,9 @@
package rtree
-import "github.com/tidwall/geoindex/child"
+import (
+ "github.com/tidwall/geoindex/child"
+)
const (
maxEntries = 32
diff --git a/vendor/github.com/tidwall/sjson/README.md b/vendor/github.com/tidwall/sjson/README.md
index 5ff00ee2..6b2e0920 100644
--- a/vendor/github.com/tidwall/sjson/README.md
+++ b/vendor/github.com/tidwall/sjson/README.md
@@ -8,7 +8,7 @@
set a json value quickly
-SJSON is a Go package that provides a [very fast](#performance) and simple way to set a value in a json document. The purpose for this library is to provide efficient json updating for the [SummitDB](https://github.com/tidwall/summitdb) project.
+SJSON is a Go package that provides a [very fast](#performance) and simple way to set a value in a json document.
For quickly retrieving json values check out [GJSON](https://github.com/tidwall/gjson).
For a command line interface check out [JJ](https://github.com/tidwall/jj).
diff --git a/vendor/github.com/tidwall/sjson/go.mod b/vendor/github.com/tidwall/sjson/go.mod
index db5ae05b..e7fcb9de 100644
--- a/vendor/github.com/tidwall/sjson/go.mod
+++ b/vendor/github.com/tidwall/sjson/go.mod
@@ -3,6 +3,6 @@ module github.com/tidwall/sjson
go 1.14
require (
- github.com/tidwall/gjson v1.6.8
- github.com/tidwall/pretty v1.0.2
+ github.com/tidwall/gjson v1.7.4
+ github.com/tidwall/pretty v1.1.0
)
diff --git a/vendor/github.com/tidwall/sjson/go.sum b/vendor/github.com/tidwall/sjson/go.sum
index bf323c2a..7dd8de53 100644
--- a/vendor/github.com/tidwall/sjson/go.sum
+++ b/vendor/github.com/tidwall/sjson/go.sum
@@ -1,6 +1,6 @@
-github.com/tidwall/gjson v1.6.8 h1:CTmXMClGYPAmln7652e69B7OLXfTi5ABcPPwjIWUv7w=
-github.com/tidwall/gjson v1.6.8/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
+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/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
-github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
-github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
+github.com/tidwall/pretty v1.1.0 h1:K3hMW5epkdAVwibsQEfR/7Zj0Qgt4DxtNumTq/VloO8=
+github.com/tidwall/pretty v1.1.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
diff --git a/vendor/modules.txt b/vendor/modules.txt
index 4031dc12..5d26ef08 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -114,20 +114,20 @@ github.com/rcrowley/go-metrics
# github.com/streadway/amqp v1.0.0
## explicit
github.com/streadway/amqp
-# github.com/tidwall/btree v0.3.0
+# github.com/tidwall/btree v0.4.2
## explicit
github.com/tidwall/btree
-# github.com/tidwall/buntdb v1.2.0
+# github.com/tidwall/buntdb v1.2.1
## explicit
github.com/tidwall/buntdb
# github.com/tidwall/cities v0.1.0
github.com/tidwall/cities
-# github.com/tidwall/geoindex v1.4.1
+# github.com/tidwall/geoindex v1.4.3
## explicit
github.com/tidwall/geoindex
github.com/tidwall/geoindex/algo
github.com/tidwall/geoindex/child
-# github.com/tidwall/geojson v1.2.4
+# github.com/tidwall/geojson v1.2.7
## explicit
github.com/tidwall/geojson
github.com/tidwall/geojson/geo
@@ -135,7 +135,7 @@ github.com/tidwall/geojson/geometry
# github.com/tidwall/gjson v1.7.4
## explicit
github.com/tidwall/gjson
-# github.com/tidwall/grect v0.1.0
+# github.com/tidwall/grect v0.1.1
github.com/tidwall/grect
# github.com/tidwall/lotsa v1.0.1
github.com/tidwall/lotsa
@@ -148,7 +148,7 @@ github.com/tidwall/pretty
# github.com/tidwall/redbench v0.1.0
## explicit
github.com/tidwall/redbench
-# github.com/tidwall/redcon v1.4.0
+# github.com/tidwall/redcon v1.4.1
## explicit
github.com/tidwall/redcon
# github.com/tidwall/resp v0.1.0
@@ -160,10 +160,10 @@ github.com/tidwall/rhh
# github.com/tidwall/rtred v0.1.2
github.com/tidwall/rtred
github.com/tidwall/rtred/base
-# github.com/tidwall/rtree v1.2.6
+# github.com/tidwall/rtree v1.2.7
## explicit
github.com/tidwall/rtree
-# github.com/tidwall/sjson v1.1.5
+# github.com/tidwall/sjson v1.1.6
## explicit
github.com/tidwall/sjson
# github.com/tidwall/tinyqueue v0.1.1