Bump github.com/blevesearch/bleve/v2 from 2.3.9 to 2.3.10
Bumps [github.com/blevesearch/bleve/v2](https://github.com/blevesearch/bleve) from 2.3.9 to 2.3.10. - [Release notes](https://github.com/blevesearch/bleve/releases) - [Commits](https://github.com/blevesearch/bleve/compare/v2.3.9...v2.3.10) --- updated-dependencies: - dependency-name: github.com/blevesearch/bleve/v2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
committed by
Ralf Haferkamp
parent
f051b9ef7d
commit
0f2838e525
+69
@@ -0,0 +1,69 @@
|
||||
// Copyright (c) 2023 Couchbase, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package s2
|
||||
|
||||
// GeoBufferPool represents a pool of buffers ranging from a given
|
||||
// max size to a min size in steps of 2. It uses a lazy approach only allocating
|
||||
// the buffers when it is needed.
|
||||
|
||||
type GeoBufferPool struct {
|
||||
buffers [][]byte
|
||||
maxSize int
|
||||
minSize int
|
||||
}
|
||||
|
||||
func NewGeoBufferPool(maxSize int, minSize int) *GeoBufferPool {
|
||||
// Calculating the number of buffers required. Assuming that
|
||||
// the value of minSize is correct, the buffers will be of size
|
||||
// minSize, 2 * minSize, 4 * minSize and so on till it is less
|
||||
// than or equal to the maxSize. If it is not equal to maxSize,
|
||||
// then a suitable value less than maxSize will be set as maxSize
|
||||
length := 0
|
||||
temp := minSize
|
||||
for temp <= maxSize {
|
||||
length = length + 1
|
||||
temp = temp * 2
|
||||
}
|
||||
maxSize = temp / 2
|
||||
|
||||
return &GeoBufferPool{
|
||||
buffers: make([][]byte, length),
|
||||
maxSize: maxSize,
|
||||
minSize: minSize,
|
||||
}
|
||||
}
|
||||
|
||||
func (b *GeoBufferPool) Get(size int) ([]byte) {
|
||||
if b == nil {
|
||||
// GeoBufferPool not setup
|
||||
return make([]byte, size)
|
||||
}
|
||||
|
||||
bufSize := b.minSize
|
||||
|
||||
for i := range b.buffers {
|
||||
if size <= bufSize || i == len(b.buffers) - 1 {
|
||||
if b.buffers[i] == nil {
|
||||
b.buffers[i] = make([]byte, bufSize)
|
||||
}
|
||||
|
||||
return b.buffers[i]
|
||||
}
|
||||
|
||||
bufSize = bufSize * 2
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
+14
@@ -222,3 +222,17 @@ func (d *decoder) readUvarint() (x uint64) {
|
||||
x, d.err = binary.ReadUvarint(d.r)
|
||||
return
|
||||
}
|
||||
|
||||
func (d *decoder) readFloat64Array(size int, buf []byte) int {
|
||||
if d.err != nil || buf == nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
if size >= len(buf) {
|
||||
_, d.err = io.ReadFull(d.r, buf)
|
||||
return len(buf)
|
||||
}
|
||||
|
||||
_, d.err = io.ReadFull(d.r, buf[0:size])
|
||||
return size
|
||||
}
|
||||
|
||||
+44
-4
@@ -15,9 +15,11 @@
|
||||
package s2
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"reflect"
|
||||
|
||||
"github.com/golang/geo/r1"
|
||||
"github.com/golang/geo/r3"
|
||||
@@ -66,6 +68,9 @@ type Loop struct {
|
||||
|
||||
// index is the spatial index for this Loop.
|
||||
index *ShapeIndex
|
||||
|
||||
// A buffer pool to be used while decoding the polygon
|
||||
BufPool *GeoBufferPool
|
||||
}
|
||||
|
||||
// LoopFromPoints constructs a loop from the given points.
|
||||
@@ -1258,6 +1263,15 @@ func (l Loop) encode(e *encoder) {
|
||||
l.bound.encode(e)
|
||||
}
|
||||
|
||||
func init() {
|
||||
var f64 float64
|
||||
sizeOfFloat64 = int(reflect.TypeOf(f64).Size())
|
||||
sizeOfVertex = 3 * sizeOfFloat64
|
||||
}
|
||||
|
||||
var sizeOfFloat64 int
|
||||
var sizeOfVertex int
|
||||
|
||||
// Decode decodes a loop.
|
||||
func (l *Loop) Decode(r io.Reader) error {
|
||||
*l = Loop{}
|
||||
@@ -1287,11 +1301,37 @@ func (l *Loop) decode(d *decoder) {
|
||||
return
|
||||
}
|
||||
l.vertices = make([]Point, nvertices)
|
||||
for i := range l.vertices {
|
||||
l.vertices[i].X = d.readFloat64()
|
||||
l.vertices[i].Y = d.readFloat64()
|
||||
l.vertices[i].Z = d.readFloat64()
|
||||
|
||||
// Each vertex requires 24 bytes of storage
|
||||
numBytesNeeded := int(nvertices) * sizeOfVertex
|
||||
|
||||
i := 0
|
||||
|
||||
for numBytesNeeded > 0 {
|
||||
arr := l.BufPool.Get(numBytesNeeded)
|
||||
numBytesRead := d.readFloat64Array(numBytesNeeded, arr)
|
||||
|
||||
if numBytesRead == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
numBytesNeeded -= numBytesRead
|
||||
|
||||
// Parsing one vertex at a time into the vertex array of the loop
|
||||
// by going through the buffer in steps of sizeOfVertex and converting
|
||||
// floatSize worth of bytes into the float values
|
||||
for j := 0; j < int(numBytesRead/sizeOfVertex); j++ {
|
||||
l.vertices[i+j].X = math.Float64frombits(
|
||||
binary.LittleEndian.Uint64(arr[sizeOfFloat64*(j*3) : sizeOfFloat64*(j*3+1)]))
|
||||
l.vertices[i+j].Y = math.Float64frombits(
|
||||
binary.LittleEndian.Uint64(arr[sizeOfFloat64*(j*3+1) : sizeOfFloat64*(j*3+2)]))
|
||||
l.vertices[i+j].Z = math.Float64frombits(
|
||||
binary.LittleEndian.Uint64(arr[sizeOfFloat64*(j*3+2) : sizeOfFloat64*(j*3+3)]))
|
||||
}
|
||||
|
||||
i += int(numBytesRead/sizeOfVertex)
|
||||
}
|
||||
|
||||
l.index = NewShapeIndex()
|
||||
l.originInside = d.readBool()
|
||||
l.depth = int(d.readUint32())
|
||||
|
||||
+5
-1
@@ -77,6 +77,9 @@ type Polygon struct {
|
||||
// preceding loops in the polygon. This field is used for polygons that
|
||||
// have a large number of loops, and may be empty for polygons with few loops.
|
||||
cumulativeEdges []int
|
||||
|
||||
// A buffer pool to be used while decoding the polygon
|
||||
BufPool *GeoBufferPool
|
||||
}
|
||||
|
||||
// PolygonFromLoops constructs a polygon from the given set of loops. The polygon
|
||||
@@ -1133,7 +1136,7 @@ func (p *Polygon) Decode(r io.Reader) error {
|
||||
const maxEncodedLoops = 10000000
|
||||
|
||||
func (p *Polygon) decode(d *decoder) {
|
||||
*p = Polygon{}
|
||||
*p = Polygon{BufPool: p.BufPool}
|
||||
d.readUint8() // Ignore irrelevant serialized owns_loops_ value.
|
||||
|
||||
p.hasHoles = d.readBool()
|
||||
@@ -1151,6 +1154,7 @@ func (p *Polygon) decode(d *decoder) {
|
||||
p.loops = make([]*Loop, nloops)
|
||||
for i := range p.loops {
|
||||
p.loops[i] = new(Loop)
|
||||
p.loops[i].BufPool = p.BufPool
|
||||
p.loops[i].decode(d)
|
||||
p.numVertices += len(p.loops[i].vertices)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user