MM-42570: Update dependencies (#19901)
https://mattermost.atlassian.net/browse/MM-42570 ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
49e68bb230
Коммит
bc69069a83
14
vendor/github.com/blevesearch/bleve/v2/SECURITY.md
сгенерированный
поставляемый
Обычный файл
14
vendor/github.com/blevesearch/bleve/v2/SECURITY.md
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,14 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
We support the latest release (for example, bleve v2.3.x).
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
All security issues for this project should be reported by email to fts-team@couchbase.com. This mail will be delivered to the owners of this project.
|
||||
|
||||
- To ensure your report is NOT marked as spam, please include the word "security/vulnerability" along with the project name (blevesearch/bleve) in the subject of the email.
|
||||
- Please be as descriptive as possible while explaining the issue, and a testcase highlighting the issue is always welcome.
|
||||
|
||||
Your email will be acknowledged at the soonest possible.
|
||||
8
vendor/github.com/blevesearch/bleve/v2/go.mod
сгенерированный
поставляемый
8
vendor/github.com/blevesearch/bleve/v2/go.mod
сгенерированный
поставляемый
@@ -6,9 +6,13 @@ require (
|
||||
github.com/RoaringBitmap/roaring v0.9.4
|
||||
github.com/bits-and-blooms/bitset v1.2.0
|
||||
github.com/blevesearch/bleve_index_api v1.0.1
|
||||
github.com/blevesearch/go-metrics v0.0.0-20190826022208-cac0b30c2563
|
||||
github.com/blevesearch/go-porterstemmer v1.0.3
|
||||
github.com/blevesearch/goleveldb v1.0.1
|
||||
github.com/blevesearch/gtreap v0.1.1
|
||||
github.com/blevesearch/scorch_segment_api/v2 v2.1.0
|
||||
github.com/blevesearch/segment v0.9.0
|
||||
github.com/blevesearch/snowball v0.6.1
|
||||
github.com/blevesearch/snowballstem v0.9.0
|
||||
github.com/blevesearch/upsidedown_store_api v1.0.1
|
||||
github.com/blevesearch/vellum v1.0.7
|
||||
@@ -19,11 +23,7 @@ require (
|
||||
github.com/blevesearch/zapx/v15 v15.3.3
|
||||
github.com/couchbase/moss v0.2.0
|
||||
github.com/golang/protobuf v1.3.2
|
||||
github.com/kljensen/snowball v0.6.0
|
||||
github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563
|
||||
github.com/spf13/cobra v0.0.5
|
||||
github.com/steveyen/gtreap v0.1.0
|
||||
github.com/syndtr/goleveldb v1.0.0
|
||||
go.etcd.io/bbolt v1.3.5
|
||||
golang.org/x/text v0.3.7
|
||||
)
|
||||
|
||||
16
vendor/github.com/blevesearch/bleve/v2/go.sum
сгенерированный
поставляемый
16
vendor/github.com/blevesearch/bleve/v2/go.sum
сгенерированный
поставляемый
@@ -6,8 +6,14 @@ github.com/bits-and-blooms/bitset v1.2.0 h1:Kn4yilvwNtMACtf1eYDlG8H77R07mZSPbMjL
|
||||
github.com/bits-and-blooms/bitset v1.2.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA=
|
||||
github.com/blevesearch/bleve_index_api v1.0.1 h1:nx9++0hnyiGOHJwQQYfsUGzpRdEVE5LsylmmngQvaFk=
|
||||
github.com/blevesearch/bleve_index_api v1.0.1/go.mod h1:fiwKS0xLEm+gBRgv5mumf0dhgFr2mDgZah1pqv1c1M4=
|
||||
github.com/blevesearch/go-metrics v0.0.0-20190826022208-cac0b30c2563 h1:mQtHArdP4SdgdR2mY8i+W3u9ekCDWDxcM/3nwehEdiw=
|
||||
github.com/blevesearch/go-metrics v0.0.0-20190826022208-cac0b30c2563/go.mod h1:9eJDeqxJ3E7WnLebQUlPD7ZjSce7AnDb9vjGmMCbD0A=
|
||||
github.com/blevesearch/go-porterstemmer v1.0.3 h1:GtmsqID0aZdCSNiY8SkuPJ12pD4jI+DdXTAn4YRcHCo=
|
||||
github.com/blevesearch/go-porterstemmer v1.0.3/go.mod h1:angGc5Ht+k2xhJdZi511LtmxuEf0OVpvUUNrwmM1P7M=
|
||||
github.com/blevesearch/goleveldb v1.0.1 h1:iAtV2Cu5s0GD1lwUiekkFHe2gTMCCNVj2foPclDLIFI=
|
||||
github.com/blevesearch/goleveldb v1.0.1/go.mod h1:WrU8ltZbIp0wAoig/MHbrPCXSOLpe79nz5lv5nqfYrQ=
|
||||
github.com/blevesearch/gtreap v0.1.1 h1:2JWigFrzDMR+42WGIN/V2p0cUvn4UP3C4Q5nmaZGW8Y=
|
||||
github.com/blevesearch/gtreap v0.1.1/go.mod h1:QaQyDRAT51sotthUWAH4Sj08awFSSWzgYICSZ3w0tYk=
|
||||
github.com/blevesearch/mmap-go v1.0.2/go.mod h1:ol2qBqYaOUsGdm7aRMRrYGgPvnwLe6Y+7LMvAB5IbSA=
|
||||
github.com/blevesearch/mmap-go v1.0.3 h1:7QkALgFNooSq3a46AE+pWeKASAZc9SiNFJhDGF1NDx4=
|
||||
github.com/blevesearch/mmap-go v1.0.3/go.mod h1:pYvKl/grLQrBxuaRYgoTssa4rVujYYeenDp++2E+yvs=
|
||||
@@ -15,6 +21,8 @@ github.com/blevesearch/scorch_segment_api/v2 v2.1.0 h1:NFwteOpZEvJk5Vg0H6gD0hxup
|
||||
github.com/blevesearch/scorch_segment_api/v2 v2.1.0/go.mod h1:uch7xyyO/Alxkuxa+CGs79vw0QY8BENSBjg6Mw5L5DE=
|
||||
github.com/blevesearch/segment v0.9.0 h1:5lG7yBCx98or7gK2cHMKPukPZ/31Kag7nONpoBt22Ac=
|
||||
github.com/blevesearch/segment v0.9.0/go.mod h1:9PfHYUdQCgHktBgvtUOF4x+pc4/l8rdH0u5spnW85UQ=
|
||||
github.com/blevesearch/snowball v0.6.1 h1:cDYjn/NCH+wwt2UdehaLpr2e4BwLIjN4V/TdLsL+B5A=
|
||||
github.com/blevesearch/snowball v0.6.1/go.mod h1:ZF0IBg5vgpeoUhnMza2v0A/z8m1cWPlwhke08LpNusg=
|
||||
github.com/blevesearch/snowballstem v0.9.0 h1:lMQ189YspGP6sXvZQ4WZ+MLawfV8wOmPoD/iWeNXm8s=
|
||||
github.com/blevesearch/snowballstem v0.9.0/go.mod h1:PivSj3JMc8WuaFkTSRDW2SlrulNWPl4ABg1tC/hlgLs=
|
||||
github.com/blevesearch/upsidedown_store_api v1.0.1 h1:1SYRwyoFLwG3sj0ed89RLtM15amfX2pXlYbFOnF8zNU=
|
||||
@@ -55,8 +63,6 @@ github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
github.com/kljensen/snowball v0.6.0 h1:6DZLCcZeL0cLfodx+Md4/OLC6b/bfurWUOUGs1ydfOU=
|
||||
github.com/kljensen/snowball v0.6.0/go.mod h1:27N7E8fVU5H68RlUmnWwZCfxgt4POBJfENGMvNRhldw=
|
||||
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
@@ -70,8 +76,6 @@ github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa
|
||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563 h1:dY6ETXrvDG7Sa4vE8ZQG4yqWg6UnOcbqTAahkV813vQ=
|
||||
github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
||||
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
|
||||
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
|
||||
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
|
||||
@@ -81,14 +85,10 @@ github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb6
|
||||
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
|
||||
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
|
||||
github.com/steveyen/gtreap v0.1.0 h1:CjhzTa274PyJLJuMZwIzCO1PfC00oRa8d1Kc78bFXJM=
|
||||
github.com/steveyen/gtreap v0.1.0/go.mod h1:kl/5J7XbrOmlIbYIXdRHDDE5QxHqpk0cmkT7Z4dM9/Y=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
|
||||
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
|
||||
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
|
||||
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
|
||||
go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0=
|
||||
|
||||
22
vendor/github.com/blevesearch/bleve/v2/index/scorch/snapshot_index.go
сгенерированный
поставляемый
22
vendor/github.com/blevesearch/bleve/v2/index/scorch/snapshot_index.go
сгенерированный
поставляемый
@@ -51,6 +51,15 @@ type asynchSegmentResult struct {
|
||||
|
||||
var reflectStaticSizeIndexSnapshot int
|
||||
|
||||
// DefaultFieldTFRCacheThreshold limits the number of TermFieldReaders(TFR) for
|
||||
// a field in an index snapshot. Without this limit, when recycling TFRs, it is
|
||||
// possible that a very large number of TFRs may be added to the recycle
|
||||
// cache, which could eventually lead to significant memory consumption.
|
||||
// This threshold can be overwritten by users at the library level by changing the
|
||||
// exported variable, or at the index level by setting the FieldTFRCacheThreshold
|
||||
// in the kvConfig.
|
||||
var DefaultFieldTFRCacheThreshold uint64 = 10
|
||||
|
||||
func init() {
|
||||
var is interface{} = IndexSnapshot{}
|
||||
reflectStaticSizeIndexSnapshot = int(reflect.TypeOf(is).Size())
|
||||
@@ -558,6 +567,15 @@ func (i *IndexSnapshot) allocTermFieldReaderDicts(field string) (tfr *IndexSnaps
|
||||
}
|
||||
}
|
||||
|
||||
func (i *IndexSnapshot) getFieldTFRCacheThreshold() uint64 {
|
||||
if i.parent.config != nil {
|
||||
if _, ok := i.parent.config["FieldTFRCacheThreshold"]; ok {
|
||||
return i.parent.config["FieldTFRCacheThreshold"].(uint64)
|
||||
}
|
||||
}
|
||||
return DefaultFieldTFRCacheThreshold
|
||||
}
|
||||
|
||||
func (i *IndexSnapshot) recycleTermFieldReader(tfr *IndexSnapshotTermFieldReader) {
|
||||
if !tfr.recycle {
|
||||
// Do not recycle an optimized unadorned term field reader (used for
|
||||
@@ -579,7 +597,9 @@ func (i *IndexSnapshot) recycleTermFieldReader(tfr *IndexSnapshotTermFieldReader
|
||||
if i.fieldTFRs == nil {
|
||||
i.fieldTFRs = map[string][]*IndexSnapshotTermFieldReader{}
|
||||
}
|
||||
i.fieldTFRs[tfr.field] = append(i.fieldTFRs[tfr.field], tfr)
|
||||
if uint64(len(i.fieldTFRs[tfr.field])) < i.getFieldTFRCacheThreshold() {
|
||||
i.fieldTFRs[tfr.field] = append(i.fieldTFRs[tfr.field], tfr)
|
||||
}
|
||||
i.m2.Unlock()
|
||||
}
|
||||
|
||||
|
||||
2
vendor/github.com/blevesearch/bleve/v2/index/upsidedown/store/gtreap/iterator.go
сгенерированный
поставляемый
2
vendor/github.com/blevesearch/bleve/v2/index/upsidedown/store/gtreap/iterator.go
сгенерированный
поставляемый
@@ -21,7 +21,7 @@ import (
|
||||
"bytes"
|
||||
"sync"
|
||||
|
||||
"github.com/steveyen/gtreap"
|
||||
"github.com/blevesearch/gtreap"
|
||||
)
|
||||
|
||||
type Iterator struct {
|
||||
|
||||
2
vendor/github.com/blevesearch/bleve/v2/index/upsidedown/store/gtreap/reader.go
сгенерированный
поставляемый
2
vendor/github.com/blevesearch/bleve/v2/index/upsidedown/store/gtreap/reader.go
сгенерированный
поставляемый
@@ -20,7 +20,7 @@ package gtreap
|
||||
import (
|
||||
"github.com/blevesearch/upsidedown_store_api"
|
||||
|
||||
"github.com/steveyen/gtreap"
|
||||
"github.com/blevesearch/gtreap"
|
||||
)
|
||||
|
||||
type Reader struct {
|
||||
|
||||
2
vendor/github.com/blevesearch/bleve/v2/index/upsidedown/store/gtreap/store.go
сгенерированный
поставляемый
2
vendor/github.com/blevesearch/bleve/v2/index/upsidedown/store/gtreap/store.go
сгенерированный
поставляемый
@@ -26,7 +26,7 @@ import (
|
||||
|
||||
"github.com/blevesearch/bleve/v2/registry"
|
||||
"github.com/blevesearch/upsidedown_store_api"
|
||||
"github.com/steveyen/gtreap"
|
||||
"github.com/blevesearch/gtreap"
|
||||
)
|
||||
|
||||
const Name = "gtreap"
|
||||
|
||||
5
vendor/github.com/blevesearch/gtreap/.gitignore
сгенерированный
поставляемый
Обычный файл
5
vendor/github.com/blevesearch/gtreap/.gitignore
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,5 @@
|
||||
#*
|
||||
*~
|
||||
*.test
|
||||
tmp
|
||||
|
||||
20
vendor/github.com/blevesearch/gtreap/LICENSE
сгенерированный
поставляемый
Обычный файл
20
vendor/github.com/blevesearch/gtreap/LICENSE
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,20 @@
|
||||
Copyright (C) 2012 Steve Yen
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
90
vendor/github.com/blevesearch/gtreap/README.md
сгенерированный
поставляемый
Обычный файл
90
vendor/github.com/blevesearch/gtreap/README.md
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,90 @@
|
||||
gtreap
|
||||
------
|
||||
|
||||
gtreap is an immutable treap implementation in the Go Language
|
||||
|
||||
[](https://godoc.org/github.com/steveyen/gtreap) [](https://drone.io/github.com/steveyen/gtreap/latest) [](https://coveralls.io/r/steveyen/gtreap)
|
||||
|
||||
Overview
|
||||
========
|
||||
|
||||
gtreap implements an immutable treap data structure in golang.
|
||||
|
||||
By treap, this data structure is both a heap and a binary search tree.
|
||||
|
||||
By immutable, any updates/deletes to a treap will return a new treap
|
||||
which can share internal nodes with the previous treap. All nodes in
|
||||
this implementation are read-only after their creation. This allows
|
||||
concurrent readers to operate safely with concurrent writers as
|
||||
modifications only create new data structures and never modify
|
||||
existing data structures. This is a simple approach to achieving MVCC
|
||||
or multi-version concurrency control.
|
||||
|
||||
By heap, items in the treap follow the heap-priority property, where a
|
||||
parent node will have higher priority than its left and right children
|
||||
nodes.
|
||||
|
||||
By binary search tree, items are store lexigraphically, ordered by a
|
||||
user-supplied Compare function.
|
||||
|
||||
To get a probabilistic O(lg N) tree height, you should use a random
|
||||
priority number during the Upsert() operation.
|
||||
|
||||
LICENSE
|
||||
=======
|
||||
|
||||
MIT
|
||||
|
||||
Example
|
||||
=======
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"github.com/steveyen/gtreap"
|
||||
)
|
||||
|
||||
func stringCompare(a, b interface{}) int {
|
||||
return bytes.Compare([]byte(a.(string)), []byte(b.(string)))
|
||||
}
|
||||
|
||||
t := gtreap.NewTreap(stringCompare)
|
||||
t = t.Upsert("hi", rand.Int())
|
||||
t = t.Upsert("hola", rand.Int())
|
||||
t = t.Upsert("bye", rand.Int())
|
||||
t = t.Upsert("adios", rand.Int())
|
||||
|
||||
hi = t.Get("hi")
|
||||
bye = t.Get("bye")
|
||||
|
||||
// Some example Delete()'s...
|
||||
t = t.Delete("bye")
|
||||
nilValueHere = t.Get("bye")
|
||||
t2 = t.Delete("hi")
|
||||
nilValueHere2 = t2.Get("hi")
|
||||
|
||||
// Since we still hold onto treap t, we can still access "hi".
|
||||
hiStillExistsInTreapT = t.Get("hi")
|
||||
|
||||
t.VisitAscend("cya", func(i Item) bool {
|
||||
// This visitor callback will be invoked with every item
|
||||
// from "cya" onwards. So: "hi", "hola".
|
||||
// If we want to stop visiting, return false;
|
||||
// otherwise a true return result means keep visiting items.
|
||||
return true
|
||||
})
|
||||
|
||||
Tips
|
||||
====
|
||||
|
||||
The Upsert() method takes both an Item (an interface{}) and a heap
|
||||
priority. Usually, that priority should be a random int
|
||||
(math/rand.Int()) or perhaps even a hash of the item. However, if you
|
||||
want to shuffle more commonly accessed items nearer to the top of the
|
||||
treap for faster access, at the potential cost of not approaching a
|
||||
probabilistic O(lg N) tree height, then you might tweak the priority.
|
||||
|
||||
See also
|
||||
========
|
||||
|
||||
For a simple, ordered, key-value storage or persistence library built
|
||||
on immutable treaps, see: https://github.com/steveyen/gkvlite
|
||||
3
vendor/github.com/blevesearch/gtreap/go.mod
сгенерированный
поставляемый
Обычный файл
3
vendor/github.com/blevesearch/gtreap/go.mod
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,3 @@
|
||||
module github.com/blevesearch/gtreap
|
||||
|
||||
go 1.13
|
||||
207
vendor/github.com/blevesearch/gtreap/treap.go
сгенерированный
поставляемый
Обычный файл
207
vendor/github.com/blevesearch/gtreap/treap.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,207 @@
|
||||
package gtreap
|
||||
|
||||
type Treap struct {
|
||||
compare Compare
|
||||
root *node
|
||||
}
|
||||
|
||||
// Compare returns an integer comparing the two items
|
||||
// lexicographically. The result will be 0 if a==b, -1 if a < b, and
|
||||
// +1 if a > b.
|
||||
type Compare func(a, b interface{}) int
|
||||
|
||||
// Item can be anything.
|
||||
type Item interface{}
|
||||
|
||||
type node struct {
|
||||
item Item
|
||||
priority int
|
||||
left *node
|
||||
right *node
|
||||
}
|
||||
|
||||
func NewTreap(c Compare) *Treap {
|
||||
return &Treap{compare: c, root: nil}
|
||||
}
|
||||
|
||||
func (t *Treap) Min() Item {
|
||||
n := t.root
|
||||
if n == nil {
|
||||
return nil
|
||||
}
|
||||
for n.left != nil {
|
||||
n = n.left
|
||||
}
|
||||
return n.item
|
||||
}
|
||||
|
||||
func (t *Treap) Max() Item {
|
||||
n := t.root
|
||||
if n == nil {
|
||||
return nil
|
||||
}
|
||||
for n.right != nil {
|
||||
n = n.right
|
||||
}
|
||||
return n.item
|
||||
}
|
||||
|
||||
func (t *Treap) Get(target Item) Item {
|
||||
n := t.root
|
||||
for n != nil {
|
||||
c := t.compare(target, n.item)
|
||||
if c < 0 {
|
||||
n = n.left
|
||||
} else if c > 0 {
|
||||
n = n.right
|
||||
} else {
|
||||
return n.item
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Note: only the priority of the first insert of an item is used.
|
||||
// Priorities from future updates on already existing items are
|
||||
// ignored. To change the priority for an item, you need to do a
|
||||
// Delete then an Upsert.
|
||||
func (t *Treap) Upsert(item Item, itemPriority int) *Treap {
|
||||
r := t.union(t.root, &node{item: item, priority: itemPriority})
|
||||
return &Treap{compare: t.compare, root: r}
|
||||
}
|
||||
|
||||
func (t *Treap) union(this *node, that *node) *node {
|
||||
if this == nil {
|
||||
return that
|
||||
}
|
||||
if that == nil {
|
||||
return this
|
||||
}
|
||||
if this.priority > that.priority {
|
||||
left, middle, right := t.split(that, this.item)
|
||||
if middle == nil {
|
||||
return &node{
|
||||
item: this.item,
|
||||
priority: this.priority,
|
||||
left: t.union(this.left, left),
|
||||
right: t.union(this.right, right),
|
||||
}
|
||||
}
|
||||
return &node{
|
||||
item: middle.item,
|
||||
priority: this.priority,
|
||||
left: t.union(this.left, left),
|
||||
right: t.union(this.right, right),
|
||||
}
|
||||
}
|
||||
// We don't use middle because the "that" has precendence.
|
||||
left, _, right := t.split(this, that.item)
|
||||
return &node{
|
||||
item: that.item,
|
||||
priority: that.priority,
|
||||
left: t.union(left, that.left),
|
||||
right: t.union(right, that.right),
|
||||
}
|
||||
}
|
||||
|
||||
// Splits a treap into two treaps based on a split item "s".
|
||||
// The result tuple-3 means (left, X, right), where X is either...
|
||||
// nil - meaning the item s was not in the original treap.
|
||||
// non-nil - returning the node that had item s.
|
||||
// The tuple-3's left result treap has items < s,
|
||||
// and the tuple-3's right result treap has items > s.
|
||||
func (t *Treap) split(n *node, s Item) (*node, *node, *node) {
|
||||
if n == nil {
|
||||
return nil, nil, nil
|
||||
}
|
||||
c := t.compare(s, n.item)
|
||||
if c == 0 {
|
||||
return n.left, n, n.right
|
||||
}
|
||||
if c < 0 {
|
||||
left, middle, right := t.split(n.left, s)
|
||||
return left, middle, &node{
|
||||
item: n.item,
|
||||
priority: n.priority,
|
||||
left: right,
|
||||
right: n.right,
|
||||
}
|
||||
}
|
||||
left, middle, right := t.split(n.right, s)
|
||||
return &node{
|
||||
item: n.item,
|
||||
priority: n.priority,
|
||||
left: n.left,
|
||||
right: left,
|
||||
}, middle, right
|
||||
}
|
||||
|
||||
func (t *Treap) Delete(target Item) *Treap {
|
||||
left, _, right := t.split(t.root, target)
|
||||
return &Treap{compare: t.compare, root: t.join(left, right)}
|
||||
}
|
||||
|
||||
// All the items from this are < items from that.
|
||||
func (t *Treap) join(this *node, that *node) *node {
|
||||
if this == nil {
|
||||
return that
|
||||
}
|
||||
if that == nil {
|
||||
return this
|
||||
}
|
||||
if this.priority > that.priority {
|
||||
return &node{
|
||||
item: this.item,
|
||||
priority: this.priority,
|
||||
left: this.left,
|
||||
right: t.join(this.right, that),
|
||||
}
|
||||
}
|
||||
return &node{
|
||||
item: that.item,
|
||||
priority: that.priority,
|
||||
left: t.join(this, that.left),
|
||||
right: that.right,
|
||||
}
|
||||
}
|
||||
|
||||
// ItemVistor callback should return true to keep going on the visitation.
|
||||
type ItemVisitor func(i Item) bool
|
||||
|
||||
// Visit items greater-than-or-equal to the pivot, in ascending order.
|
||||
func (t *Treap) VisitAscend(pivot Item, visitor ItemVisitor) {
|
||||
t.visitAscend(t.root, pivot, visitor)
|
||||
}
|
||||
|
||||
func (t *Treap) visitAscend(n *node, pivot Item, visitor ItemVisitor) bool {
|
||||
if n == nil {
|
||||
return true
|
||||
}
|
||||
c := t.compare(pivot, n.item)
|
||||
if c < 0 && !t.visitAscend(n.left, pivot, visitor) {
|
||||
return false
|
||||
}
|
||||
if c <= 0 && !visitor(n.item) {
|
||||
return false
|
||||
}
|
||||
return t.visitAscend(n.right, pivot, visitor)
|
||||
}
|
||||
|
||||
// Visit items less-than-or-equal to the pivot, in descending order.
|
||||
func (t *Treap) VisitDescend(pivot Item, visitor ItemVisitor) {
|
||||
t.visitDescend(t.root, pivot, visitor)
|
||||
}
|
||||
|
||||
func (t *Treap) visitDescend(n *node, pivot Item, visitor ItemVisitor) bool {
|
||||
if n == nil {
|
||||
return true
|
||||
}
|
||||
c := t.compare(pivot, n.item)
|
||||
if c > 0 && !t.visitDescend(n.right, pivot, visitor) {
|
||||
return false
|
||||
}
|
||||
if c >= 0 && !visitor(n.item) {
|
||||
return false
|
||||
}
|
||||
return t.visitDescend(n.left, pivot, visitor)
|
||||
}
|
||||
Ссылка в новой задаче
Block a user