From b1370332e6a7cd34694585d1448a55faca840af0 Mon Sep 17 00:00:00 2001 From: tidwall Date: Tue, 23 Oct 2018 11:23:55 -0700 Subject: [PATCH] Always use compressed indexing --- Gopkg.lock | 4 +- internal/controller/controller.go | 4 -- .../geojson/geometry/pip_bench_test.go | 12 +---- .../geometry/{quadtree.go => qtree.go} | 6 ++- .../tidwall/geojson/geometry/series.go | 51 +++---------------- vendor/github.com/tidwall/geojson/object.go | 2 +- 6 files changed, 17 insertions(+), 62 deletions(-) rename vendor/github.com/tidwall/geojson/geometry/{quadtree.go => qtree.go} (99%) diff --git a/Gopkg.lock b/Gopkg.lock index 530c8d95..bf224bfa 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -227,7 +227,7 @@ [[projects]] branch = "master" - digest = "1:c0012e273a29ef7c490e8a4d28c23f2135b8aa9980121a65bdc032163d7cbfd5" + digest = "1:6fc1b77dedecd24d417a38c4ffc580c0c4de1540b60453efee44f1a41b205d27" name = "github.com/tidwall/geojson" packages = [ ".", @@ -235,7 +235,7 @@ "geometry", ] pruneopts = "" - revision = "a1db67ca0ab0c8e59a5fc9d03d0e1d88f87b6902" + revision = "581e33d25c96a70d4006cbeca5fcd716caad7766" [[projects]] digest = "1:3ddca2bd5496c6922a2a9e636530e178a43c2a534ea6634211acdc7d10222794" diff --git a/internal/controller/controller.go b/internal/controller/controller.go index 280f67d7..5430605d 100644 --- a/internal/controller/controller.go +++ b/internal/controller/controller.go @@ -184,12 +184,8 @@ func ListenAndServeEx(host string, port int, dir string, ln *net.Listener, http c.geomParseOpts.IndexGeometryKind = geometry.None case "RTree": c.geomParseOpts.IndexGeometryKind = geometry.RTree - case "RTreeCompressed": - c.geomParseOpts.IndexGeometryKind = geometry.RTreeCompressed case "QuadTree": c.geomParseOpts.IndexGeometryKind = geometry.QuadTree - case "QuadTreeCompressed": - c.geomParseOpts.IndexGeometryKind = geometry.QuadTreeCompressed } if c.geomParseOpts.IndexGeometryKind == geometry.None { log.Debugf("Geom indexing: %s", diff --git a/vendor/github.com/tidwall/geojson/geometry/pip_bench_test.go b/vendor/github.com/tidwall/geojson/geometry/pip_bench_test.go index f972da45..5b2005ba 100644 --- a/vendor/github.com/tidwall/geojson/geometry/pip_bench_test.go +++ b/vendor/github.com/tidwall/geojson/geometry/pip_bench_test.go @@ -24,12 +24,8 @@ func (kind IndexKind) shortString() string { return "none" case RTree: return "rtre" - case RTreeCompressed: - return "rtrc" case QuadTree: return "quad" - case QuadTreeCompressed: - return "quac" } } @@ -40,9 +36,7 @@ func testBig( opts := []IndexOptions{ IndexOptions{Kind: None, MinPoints: 64}, - IndexOptions{Kind: QuadTreeCompressed, MinPoints: 64}, IndexOptions{Kind: QuadTree, MinPoints: 64}, - IndexOptions{Kind: RTreeCompressed, MinPoints: 64}, IndexOptions{Kind: RTree, MinPoints: 64}, } for _, opts := range opts { @@ -79,8 +73,8 @@ func testBig( if os.Getenv("PIPBENCH") == "1" { fmt.Printf("%s/%s ", label, opts.Kind.shortString()) mem := ms2.Alloc - ms1.Alloc - fmt.Printf("created in %s using %d bytes\n", dur, mem) - + fmt.Printf("%d points created in %s using %d bytes\n", + ring.NumPoints(), dur, mem) lotsa.Output = os.Stdout fmt.Printf("%s/%s/in ", label, opts.Kind.shortString()) lotsa.Ops(N, T, func(_, _ int) { @@ -99,9 +93,7 @@ func testBig( ringContainsPoint(ring, randPoints[i], true) }) } - } - } func TestBigArizona(t *testing.T) { diff --git a/vendor/github.com/tidwall/geojson/geometry/quadtree.go b/vendor/github.com/tidwall/geojson/geometry/qtree.go similarity index 99% rename from vendor/github.com/tidwall/geojson/geometry/quadtree.go rename to vendor/github.com/tidwall/geojson/geometry/qtree.go index e4279fb9..b8c3a31c 100644 --- a/vendor/github.com/tidwall/geojson/geometry/quadtree.go +++ b/vendor/github.com/tidwall/geojson/geometry/qtree.go @@ -1,8 +1,10 @@ package geometry -import "encoding/binary" +import ( + "encoding/binary" +) -const qMaxItems = 16 +const qMaxItems = 32 const qMaxDepth = 16 type qNode struct { diff --git a/vendor/github.com/tidwall/geojson/geometry/series.go b/vendor/github.com/tidwall/geojson/geometry/series.go index 8fb099ad..319857dc 100644 --- a/vendor/github.com/tidwall/geojson/geometry/series.go +++ b/vendor/github.com/tidwall/geojson/geometry/series.go @@ -17,9 +17,7 @@ type IndexKind byte const ( None IndexKind = iota RTree - RTreeCompressed QuadTree - QuadTreeCompressed ) func (kind IndexKind) String() string { @@ -30,12 +28,8 @@ func (kind IndexKind) String() string { return "None" case RTree: return "RTree" - case RTreeCompressed: - return "RTreeCompressed" case QuadTree: return "QuadTree" - case QuadTreeCompressed: - return "QuadTreeCompressed" } } @@ -182,27 +176,6 @@ func (series *baseSeries) Search( } } } - case *rTree: - v.Search( - []float64{rect.Min.X, rect.Min.Y}, - []float64{rect.Max.X, rect.Max.Y}, - func(_, _ []float64, value interface{}) bool { - index := value.(int) - var seg Segment - seg.A = series.points[index] - if series.closed && index == len(series.points)-1 { - seg.B = series.points[0] - } else { - seg.B = series.points[index+1] - } - if !iter(seg, index) { - return false - } - return true - }, - ) - case *qNode: - v.search(series, series.rect, rect, iter) case *byte: // convert the byte pointer back to a valid slice data := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{ @@ -340,7 +313,7 @@ func (series *baseSeries) buildIndex() { return } switch series.indexKind { - case RTree, RTreeCompressed: + case RTree: tr := new(rTree) n := series.NumSegments() for i := 0; i < n; i++ { @@ -349,26 +322,18 @@ func (series *baseSeries) buildIndex() { []float64{rect.Min.X, rect.Min.Y}, []float64{rect.Max.X, rect.Max.Y}, i) } - if series.indexKind == RTreeCompressed { - series.setCompressed( - tr.compress([]byte{1, 0, 0, 0, 0}), - ) - } else { - series.index = tr - } - case QuadTree, QuadTreeCompressed: + series.setCompressed( + tr.compress([]byte{1, 0, 0, 0, 0}), + ) + case QuadTree: root := new(qNode) n := series.NumSegments() for i := 0; i < n; i++ { seg := series.SegmentAt(i) root.insert(series, series.rect, seg.Rect(), i, 0) } - if series.indexKind == QuadTreeCompressed { - series.setCompressed( - root.compress([]byte{2, 0, 0, 0, 0}, series.rect), - ) - } else { - series.index = root - } + series.setCompressed( + root.compress([]byte{2, 0, 0, 0, 0}, series.rect), + ) } } diff --git a/vendor/github.com/tidwall/geojson/object.go b/vendor/github.com/tidwall/geojson/object.go index eb041ae7..a05b3f98 100644 --- a/vendor/github.com/tidwall/geojson/object.go +++ b/vendor/github.com/tidwall/geojson/object.go @@ -93,7 +93,7 @@ type ParseOptions struct { var DefaultParseOptions = &ParseOptions{ IndexChildren: 64, IndexGeometry: 64, - IndexGeometryKind: geometry.QuadTreeCompressed, + IndexGeometryKind: geometry.QuadTree, } // Parse a GeoJSON object