diff --git a/go.mod b/go.mod index be52429edc..a5e1c0e2c2 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.4.1 github.com/CortexFoundation/inference v1.0.2-0.20230307032835-9197d586a4e8 github.com/CortexFoundation/statik v0.0.0-20210315012922-8bb8a7b5dc66 - github.com/CortexFoundation/torrentfs v1.0.53-0.20230815075557-4bffeba9600c + github.com/CortexFoundation/torrentfs v1.0.53-0.20230816125424-a7c2a24d3217 github.com/VictoriaMetrics/fastcache v1.12.1 github.com/arsham/figurine v1.3.0 github.com/aws/aws-sdk-go-v2 v1.19.0 @@ -91,7 +91,7 @@ require ( github.com/anacrolix/chansync v0.3.0 // indirect github.com/anacrolix/dht/v2 v2.20.0 // indirect github.com/anacrolix/envpprof v1.3.0 // indirect - github.com/anacrolix/generics v0.0.0-20230428105757-683593396d68 // indirect + github.com/anacrolix/generics v0.0.0-20230816103846-fe11fdc0e0e3 // indirect github.com/anacrolix/go-libutp v1.3.1 // indirect github.com/anacrolix/log v0.14.1 // indirect github.com/anacrolix/missinggo v1.3.0 // indirect @@ -101,7 +101,7 @@ require ( github.com/anacrolix/multiless v0.3.1-0.20221221005021-2d12701f83f7 // indirect github.com/anacrolix/stm v0.5.0 // indirect github.com/anacrolix/sync v0.4.0 // indirect - github.com/anacrolix/torrent v1.52.5 // indirect + github.com/anacrolix/torrent v1.52.6-0.20230816110201-613470861e67 // indirect github.com/anacrolix/upnp v0.1.3-0.20220123035249-922794e51c96 // indirect github.com/anacrolix/utp v0.2.0 // indirect github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect @@ -181,7 +181,6 @@ require ( github.com/labstack/echo/v4 v4.11.1 // indirect github.com/labstack/gommon v0.4.0 // indirect github.com/leodido/go-urn v1.2.4 // indirect - github.com/lispad/go-generics-tools v1.1.0 // indirect github.com/mattn/go-localereader v0.0.1 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect diff --git a/go.sum b/go.sum index 4a4010d1cb..d8cb02b0a9 100644 --- a/go.sum +++ b/go.sum @@ -66,8 +66,8 @@ github.com/CortexFoundation/statik v0.0.0-20210315012922-8bb8a7b5dc66/go.mod h1: github.com/CortexFoundation/torrentfs v1.0.13-0.20200623060705-ce027f43f2f8/go.mod h1:Ma+tGhPPvz4CEZHaqEJQMOEGOfHeQBiAoNd1zyc/w3Q= github.com/CortexFoundation/torrentfs v1.0.14-0.20200703071639-3fcabcabf274/go.mod h1:qnb3YlIJmuetVBtC6Lsejr0Xru+1DNmDCdTqnwy7lhk= github.com/CortexFoundation/torrentfs v1.0.20-0.20200810031954-d36d26f82fcc/go.mod h1:N5BsicP5ynjXIi/Npl/SRzlJ630n1PJV2sRj0Z0t2HA= -github.com/CortexFoundation/torrentfs v1.0.53-0.20230815075557-4bffeba9600c h1:IpR4F+FYD3ymMsVi/QlNuCBCFnjnV3a89girtaMF/WE= -github.com/CortexFoundation/torrentfs v1.0.53-0.20230815075557-4bffeba9600c/go.mod h1:2hLaFbgnS3rnJMqCG6HXcmk1iANzu0jSI3DjdZOwKCU= +github.com/CortexFoundation/torrentfs v1.0.53-0.20230816125424-a7c2a24d3217 h1:FCwFb2K3nRQRS4GlUg8T/z1R9poj719N3jWj/hfJeuM= +github.com/CortexFoundation/torrentfs v1.0.53-0.20230816125424-a7c2a24d3217/go.mod h1:f2SsyxIT3b/LnK0iKaH6YQ0Y83+c8Mz6ppp/IVUl60Q= github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= github.com/DataDog/zstd v1.5.6-0.20230622172052-ea68dcab66c0 h1:ye3LRgDs6Og7SKC1wBQH8oMaGczhCRpPpnU74l4rma8= github.com/DataDog/zstd v1.5.6-0.20230622172052-ea68dcab66c0/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= @@ -130,8 +130,8 @@ github.com/anacrolix/envpprof v1.0.1/go.mod h1:My7T5oSqVfEn4MD4Meczkw/f5lSIndGAK github.com/anacrolix/envpprof v1.1.0/go.mod h1:My7T5oSqVfEn4MD4Meczkw/f5lSIndGAKu/0SM/rkf4= github.com/anacrolix/envpprof v1.3.0 h1:WJt9bpuT7A/CDCxPOv/eeZqHWlle/Y0keJUvc6tcJDk= github.com/anacrolix/envpprof v1.3.0/go.mod h1:7QIG4CaX1uexQ3tqd5+BRa/9e2D02Wcertl6Yh0jCB0= -github.com/anacrolix/generics v0.0.0-20230428105757-683593396d68 h1:fyXlBfnlFzZSFckJ8QLb2lfmWfY++4RiUnae7ZMuv0A= -github.com/anacrolix/generics v0.0.0-20230428105757-683593396d68/go.mod h1:ff2rHB/joTV03aMSSn/AZNnaIpUw0h3njetGsaXcMy8= +github.com/anacrolix/generics v0.0.0-20230816103846-fe11fdc0e0e3 h1:O5xBrk97JnkTZdTsxsnQOBfD22/4L5rJXrBZrKUhJOY= +github.com/anacrolix/generics v0.0.0-20230816103846-fe11fdc0e0e3/go.mod h1:ff2rHB/joTV03aMSSn/AZNnaIpUw0h3njetGsaXcMy8= github.com/anacrolix/go-libutp v0.0.0-20180522111405-6baeb806518d/go.mod h1:beQSaSxwH2d9Eeu5ijrEnHei5Qhk+J6cDm1QkWFru4E= github.com/anacrolix/go-libutp v1.0.2/go.mod h1:uIH0A72V++j0D1nnmTjjZUiH/ujPkFxYWkxQ02+7S0U= github.com/anacrolix/go-libutp v1.0.3/go.mod h1:8vSGX5g0b4eebsDBNVQHUXSCwYaN18Lnkse0hUW8/5w= @@ -207,8 +207,8 @@ github.com/anacrolix/torrent v1.15.0/go.mod h1:MFc6KcbpAyfwGqOyRkdarUK9QnKA/FkVg github.com/anacrolix/torrent v1.15.1-0.20200504230043-cc5d2abe18e5/go.mod h1:QlOfgrCz5kbvhOz8M58dUwHY5SfZ9VbIvReZ0z0MdIk= github.com/anacrolix/torrent v1.15.1-0.20200619022403-dd51e99b88cc/go.mod h1:wuopQPC5+/M+zHYvhcA2vp5UCTm9rUc+VqjyBa882Q8= github.com/anacrolix/torrent v1.15.1-0.20200715061614-dd906f8fa72e/go.mod h1:XWo/fJN1oKgcjgxM+pUZpvalHfqHDs27BY5mBZjIQWo= -github.com/anacrolix/torrent v1.52.5 h1:jWowdx+EU6zFVfBwmnL0d3H4J6vTFEGOrHI35YdfIT8= -github.com/anacrolix/torrent v1.52.5/go.mod h1:CcM8oPMYye5J42cSqJrmUpqwRFgSsJQ1jCEHwygqnqQ= +github.com/anacrolix/torrent v1.52.6-0.20230816110201-613470861e67 h1:5ExouOJzDRpy5pXhSquvFsBdmjTAVDA5YQn6CWIuam4= +github.com/anacrolix/torrent v1.52.6-0.20230816110201-613470861e67/go.mod h1:dA7tlQGWx1oCogZcnvjTCU2pQaNOyY2YgyG2kumC1H0= github.com/anacrolix/upnp v0.1.1/go.mod h1:LXsbsp5h+WGN7YR+0A7iVXm5BL1LYryDev1zuJMWYQo= github.com/anacrolix/upnp v0.1.2-0.20200416075019-5e9378ed1425/go.mod h1:Pz94W3kl8rf+wxH3IbCa9Sq+DTJr8OSbV2Q3/y51vYs= github.com/anacrolix/upnp v0.1.3-0.20220123035249-922794e51c96 h1:QAVZ3pN/J4/UziniAhJR2OZ9Ox5kOY2053tBbbqUPYA= @@ -812,8 +812,6 @@ github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNa github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM= github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= -github.com/lispad/go-generics-tools v1.1.0 h1:mbSgcxdFVmpoyso1X/MJHXbSbSL3dD+qhRryyxk+/XY= -github.com/lispad/go-generics-tools v1.1.0/go.mod h1:2csd1EJljo/gy5qG4khXol7ivCPptNjG5Uv2X8MgK84= github.com/lucas-clemente/quic-go v0.7.1-0.20190401152353-907071221cf9/go.mod h1:PpMmPfPKO9nKJ/psF49ESTAGQSdfXxlg1otPbEB2nOw= github.com/lucas-clemente/quic-go v0.15.6/go.mod h1:Myi1OyS0FOjL3not4BxT7KN29bRkcMUV5JVVFLKtDp8= github.com/lucas-clemente/quic-go v0.15.7/go.mod h1:Myi1OyS0FOjL3not4BxT7KN29bRkcMUV5JVVFLKtDp8= diff --git a/vendor/github.com/CortexFoundation/torrentfs/README.md b/vendor/github.com/CortexFoundation/torrentfs/README.md index 703525b19b..d6837a3098 100644 --- a/vendor/github.com/CortexFoundation/torrentfs/README.md +++ b/vendor/github.com/CortexFoundation/torrentfs/README.md @@ -36,11 +36,11 @@ cp -r workspace/data/* mnt/9196320d998fdab966bcb3a08f3f087e1f993c12/data ``` #### How to test your network for torrent ? ``` -./build/bin/torrent download 'ih:6b75cc1354495ec763a6b295ee407ea864a0c292' -./build/bin/torrent download 'ih:b2f5b0036877be22c6101bdfa5f2c7927fc35ef8' -./build/bin/torrent download 'ih:5a49fed84aaf368cbf472cc06e42f93a93d92db5' -./build/bin/torrent download 'ih:1f1706fa53ce0723ba1c577418b222acbfa5a200' -./build/bin/torrent download 'ih:3f1f6c007e8da3e16f7c3378a20a746e70f1c2b0' +./build/bin/torrent download 'infohash:6b75cc1354495ec763a6b295ee407ea864a0c292' +./build/bin/torrent download 'infohash:b2f5b0036877be22c6101bdfa5f2c7927fc35ef8' +./build/bin/torrent download 'infohash:5a49fed84aaf368cbf472cc06e42f93a93d92db5' +./build/bin/torrent download 'infohash:1f1706fa53ce0723ba1c577418b222acbfa5a200' +./build/bin/torrent download 'infohash:3f1f6c007e8da3e16f7c3378a20a746e70f1c2b0' ``` downloaded ALL the torrents !!!!!!!!!!!!!!!!!!! ## Server running diff --git a/vendor/github.com/anacrolix/generics/heap/heap.go b/vendor/github.com/anacrolix/generics/heap/heap.go new file mode 100644 index 0000000000..2c69ac991b --- /dev/null +++ b/vendor/github.com/anacrolix/generics/heap/heap.go @@ -0,0 +1,118 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package heap provides heap operations for any type that implements +// heap.Interface. A heap is a tree with the property that each node is the +// minimum-valued node in its subtree. +// +// The minimum element in the tree is the root, at index 0. +// +// A heap is a common way to implement a priority queue. To build a priority +// queue, implement the Heap interface with the (negative) priority as the +// ordering for the Less method, so Push adds items while Pop removes the +// highest-priority item from the queue. The Examples include such an +// implementation; the file example_pq_test.go has the complete source. +package heap + +import "sort" + +// The Interface type describes the requirements +// for a type using the routines in this package. +// Any type that implements it may be used as a +// min-heap with the following invariants (established after +// Init has been called or if the data is empty or sorted): +// +// !h.Less(j, i) for 0 <= i < h.Len() and 2*i+1 <= j <= 2*i+2 and j < h.Len() +// +// Note that Push and Pop in this interface are for package heap's +// implementation to call. To add and remove things from the heap, +// use heap.Push and heap.Pop. +type Interface[T any] interface { + sort.Interface + Push(x T) // add x as element Len() + Pop() T // remove and return element Len() - 1. +} + +// Init establishes the heap invariants required by the other routines in this package. +// Init is idempotent with respect to the heap invariants +// and may be called whenever the heap invariants may have been invalidated. +// The complexity is O(n) where n = h.Len(). +func Init[T any](h Interface[T]) { + // heapify + n := h.Len() + for i := n/2 - 1; i >= 0; i-- { + down(h, i, n) + } +} + +// Push pushes the element x onto the heap. +// The complexity is O(log n) where n = h.Len(). +func Push[T any](h Interface[T], x T) { + h.Push(x) + up(h, h.Len()-1) +} + +// Pop removes and returns the minimum element (according to Less) from the heap. +// The complexity is O(log n) where n = h.Len(). +// Pop is equivalent to Remove(h, 0). +func Pop[T any](h Interface[T]) T { + n := h.Len() - 1 + h.Swap(0, n) + down(h, 0, n) + return h.Pop() +} + +// Remove removes and returns the element at index i from the heap. +// The complexity is O(log n) where n = h.Len(). +func Remove[T any](h Interface[T], i int) T { + n := h.Len() - 1 + if n != i { + h.Swap(i, n) + if !down(h, i, n) { + up(h, i) + } + } + return h.Pop() +} + +// Fix re-establishes the heap ordering after the element at index i has changed its value. +// Changing the value of the element at index i and then calling Fix is equivalent to, +// but less expensive than, calling Remove(h, i) followed by a Push of the new value. +// The complexity is O(log n) where n = h.Len(). +func Fix[T any](h Interface[T], i int) { + if !down(h, i, h.Len()) { + up(h, i) + } +} + +func up[T any](h Interface[T], j int) { + for { + i := (j - 1) / 2 // parent + if i == j || !h.Less(j, i) { + break + } + h.Swap(i, j) + j = i + } +} + +func down[T any](h Interface[T], i0, n int) bool { + i := i0 + for { + j1 := 2*i + 1 + if j1 >= n || j1 < 0 { // j1 < 0 after int overflow + break + } + j := j1 // left child + if j2 := j1 + 1; j2 < n && h.Less(j2, j1) { + j = j2 // = 2*i + 2 // right child + } + if !h.Less(j, i) { + break + } + h.Swap(i, j) + i = j + } + return i > i0 +} diff --git a/vendor/github.com/anacrolix/generics/heap/slice.go b/vendor/github.com/anacrolix/generics/heap/slice.go new file mode 100644 index 0000000000..4d7d6e7014 --- /dev/null +++ b/vendor/github.com/anacrolix/generics/heap/slice.go @@ -0,0 +1,39 @@ +package heap + +type sliceInterface[T any] struct { + slice *[]T + less func(T, T) bool +} + +func (me sliceInterface[T]) Less(i, j int) bool { + return me.less((*me.slice)[i], (*me.slice)[j]) +} + +func (me sliceInterface[T]) Swap(i, j int) { + s := *me.slice + s[i], s[j] = s[j], s[i] + *me.slice = s +} + +func (me sliceInterface[T]) Push(x T) { + *me.slice = append(*me.slice, x) +} + +func (me sliceInterface[T]) Pop() T { + s := *me.slice + n := len(s) + ret := s[n-1] + *me.slice = s[:n-1] + return ret +} + +func (me sliceInterface[T]) Len() int { + return len(*me.slice) +} + +func InterfaceForSlice[T any](sl *[]T, less func(T, T) bool) Interface[T] { + return sliceInterface[T]{ + slice: sl, + less: less, + } +} diff --git a/vendor/github.com/anacrolix/torrent/requesting.go b/vendor/github.com/anacrolix/torrent/requesting.go index f9b5424f00..46796bd29d 100644 --- a/vendor/github.com/anacrolix/torrent/requesting.go +++ b/vendor/github.com/anacrolix/torrent/requesting.go @@ -9,9 +9,9 @@ import ( "time" "unsafe" + "github.com/anacrolix/generics/heap" "github.com/anacrolix/log" "github.com/anacrolix/multiless" - "github.com/lispad/go-generics-tools/binheap" requestStrategy "github.com/anacrolix/torrent/request-strategy" typedRoaring "github.com/anacrolix/torrent/typed-roaring" @@ -80,14 +80,6 @@ type desiredPeerRequests struct { pieceStates []requestStrategy.PieceRequestOrderState } -func (p *desiredPeerRequests) Len() int { - return len(p.requestIndexes) -} - -func (p *desiredPeerRequests) Less(i, j int) bool { - return p.lessByValue(p.requestIndexes[i], p.requestIndexes[j]) -} - func (p *desiredPeerRequests) lessByValue(leftRequest, rightRequest RequestIndex) bool { t := p.peer.t leftPieceIndex := t.pieceIndexOfRequestIndex(leftRequest) @@ -168,21 +160,6 @@ func (p *desiredPeerRequests) lessByValue(leftRequest, rightRequest RequestIndex return ml.Less() } -func (p *desiredPeerRequests) Swap(i, j int) { - p.requestIndexes[i], p.requestIndexes[j] = p.requestIndexes[j], p.requestIndexes[i] -} - -func (p *desiredPeerRequests) Push(x interface{}) { - p.requestIndexes = append(p.requestIndexes, x.(RequestIndex)) -} - -func (p *desiredPeerRequests) Pop() interface{} { - last := len(p.requestIndexes) - 1 - x := p.requestIndexes[last] - p.requestIndexes = p.requestIndexes[:last] - return x -} - type desiredRequestState struct { Requests desiredPeerRequests Interested bool @@ -275,7 +252,9 @@ func (p *Peer) applyRequestState(next desiredRequestState) { return } more := true - requestHeap := binheap.FromSlice(next.Requests.requestIndexes, next.Requests.lessByValue) + requestHeap := heap.InterfaceForSlice(&next.Requests.requestIndexes, next.Requests.lessByValue) + heap.Init(requestHeap) + t := p.t originalRequestCount := current.Requests.GetCardinality() // We're either here on a timer, or because we ran out of requests. Both are valid reasons to diff --git a/vendor/github.com/lispad/go-generics-tools/LICENSE b/vendor/github.com/lispad/go-generics-tools/LICENSE deleted file mode 100644 index 30139379d8..0000000000 --- a/vendor/github.com/lispad/go-generics-tools/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 lispad.me - -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. diff --git a/vendor/github.com/lispad/go-generics-tools/binheap/README.md b/vendor/github.com/lispad/go-generics-tools/binheap/README.md deleted file mode 100644 index 5a4cd8c27a..0000000000 --- a/vendor/github.com/lispad/go-generics-tools/binheap/README.md +++ /dev/null @@ -1,83 +0,0 @@ -# Heap structure, using go generics -[![MIT License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE) - -Introduction ------------- - -The Heap package contains simple [binary heap](https://en.wikipedia.org/wiki/Binary_heap) implementation, using Golang -generics. There are several heap implementations - -- generic Heap implementation, that could be used for `any` type, -- `ComparableHeap` for [comparable](https://go.dev/ref/spec#Comparison_operators) types. Additional `Search` - and `Delete` are implemented, -- for [`constraints.Ordered`](https://pkg.go.dev/golang.org/x/exp/constraints#Ordered) there are - constructors for min, max heaps; - -Also use-cases provided: - -- `TopN` that allows getting N top elements from slice. - `TopN` swaps top N elements to first N elements of slice, no additional allocations are done. All slice elements are - kept, only order is changed. -- `TopNHeap` allows to get N top, pushing elements from stream without allocation slice for all elements. Only O(N) - memory is used. -- `TopNImmutable` allocated new slice for heap, input slice is not mutated. - -Both TopN and TopNImmutable has methods for creating min and max tops for `constraints.Ordered`. - -Usage Example ------------------ - - package main - - import ( - "fmt" - - "github.com/lispad/go-generics-tools/binheap" - ) - - func main() { - someData := []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0} - mins := binheap.MinN[float64](someData, 3) - fmt.Printf("--- top 3 min elements: %v\n", mins) - maxs := binheap.MaxN[float64](someData, 3) - fmt.Printf("--- top 3 max elements: %v\n\n", maxs) - - heap := binheap.EmptyMaxHeap[string]() - heap.Push("foo") - heap.Push("zzz") - heap.Push("bar") - heap.Push("baz") - heap.Push("foobar") - heap.Push("foobaz") - fmt.Printf("--- heap has %d elements, max element:\n%s\n\n", heap.Len(), heap.Peak()) - } - -A bit more examples could be found in `examples` directory - -Benchmark ------------------ -Theoretical complexity for getting TopN from slice with size M, N <= M: O(N*ln(M)). When N << M, the heap-based TopN -could be much faster than sorting slice and getting top. E.g. For top-3 from 10k elements approach is ln(10^5)/ln(3) ~= -8.38 times faster. - -#### Benchmark - - BenchmarkSortedMaxN-8 10303648 136.0 ns/op 0 B/op 0 allocs/op - BenchmarkMaxNImmutable-8 398996316 3.029 ns/op 0 B/op 0 allocs/op - BenchmarkMaxN-8 804041455 1.819 ns/op 0 B/op 0 allocs/op - -Compatibility -------------- -Minimal Golang version is 1.18. Generics and fuzz testing are used. - -Installation ----------------------- - -To install package, run: - - go get github.com/lispad/go-generics-tools/binheap - -License -------- - -The binheap package is licensed under the MIT license. Please see the LICENSE file for details. diff --git a/vendor/github.com/lispad/go-generics-tools/binheap/generic.go b/vendor/github.com/lispad/go-generics-tools/binheap/generic.go deleted file mode 100644 index 94dab850b0..0000000000 --- a/vendor/github.com/lispad/go-generics-tools/binheap/generic.go +++ /dev/null @@ -1,119 +0,0 @@ -// Package binheap provides implementation of binary heap for any type -// with use of golang generics, and top-N heap usecases. -package binheap - -// Heap provides basic methods: Push, Peak, Pop, Replace top element and PushPop. -type Heap[T any] struct { - comparator func(x, y T) bool - data []T -} - -// EmptyHeap creates empty heap with provided comparator. -func EmptyHeap[T any](comparator func(x, y T) bool) Heap[T] { - return Heap[T]{ - comparator: comparator, - } -} - -// FromSlice creates heap, based on provided slice. -// Slice could be reordered. -func FromSlice[T any](data []T, comparator func(x, y T) bool) Heap[T] { - h := Heap[T]{ - data: data, - comparator: comparator, - } - n := h.Len() - for i := n/2 - 1; i >= 0; i-- { - h.down(i, n) - } - - return h -} - -// Push inserts element to heap. -func (h *Heap[T]) Push(x T) { - h.data = append(h.data, x) - h.up(h.Len() - 1) -} - -// Len returns count of elements in heap. -func (h *Heap[T]) Len() int { - return len(h.data) -} - -// Peak returns top element without deleting. -func (h *Heap[T]) Peak() T { - return h.data[0] -} - -// Pop returns top element with removing it. -func (h *Heap[T]) Pop() T { - n := h.Len() - 1 - h.swap(0, n) - h.down(0, n) - result := h.data[n] - h.data = h.data[0:n] - - return result -} - -// PushPop pushes x to the heap and then pops top element. -func (h *Heap[T]) PushPop(x T) T { - if h.Len() > 0 && h.comparator(h.data[0], x) { - x, h.data[0] = h.data[0], x - h.down(0, h.Len()) - } - - return x -} - -// Replace extracts the root of the heap, and push a new item. -func (h *Heap[T]) Replace(x T) (result T) { - result, h.data[0] = h.data[0], x - h.fix(0) - return -} - -func (h *Heap[T]) fix(i int) (result T) { - if !h.down(i, h.Len()) { - h.up(i) - } - - return result -} - -func (h *Heap[T]) swap(i, j int) { - h.data[i], h.data[j] = h.data[j], h.data[i] -} - -func (h *Heap[T]) up(j int) { - for { - i := (j - 1) / 2 // parent - if i == j || !h.comparator(h.data[j], h.data[i]) { - break - } - h.swap(i, j) - j = i - } -} - -func (h *Heap[T]) down(i0, n int) bool { - i := i0 - for { - j1 := 2*i + 1 - if j1 >= n || j1 < 0 { // j1 < 0 after int overflow - break - } - j := j1 // left child - if j2 := j1 + 1; j2 < n && h.comparator(h.data[j2], h.data[j1]) { - j = j2 // = 2*i + 2 // right child - } - if !h.comparator(h.data[j], h.data[i]) { - break - } - h.swap(i, j) - i = j - } - - return i > i0 -} diff --git a/vendor/github.com/lispad/go-generics-tools/binheap/ordered.go b/vendor/github.com/lispad/go-generics-tools/binheap/ordered.go deleted file mode 100644 index 28f7124357..0000000000 --- a/vendor/github.com/lispad/go-generics-tools/binheap/ordered.go +++ /dev/null @@ -1,83 +0,0 @@ -package binheap - -import ( - "golang.org/x/exp/constraints" -) - -// ComparableHeap provides additional Search and Delete methods. -// Could be used for comparable types. -type ComparableHeap[T comparable] struct { - Heap[T] -} - -// EmptyComparableHeap creates heap for comparable types. -func EmptyComparableHeap[T comparable](comparator func(x, y T) bool) ComparableHeap[T] { - return ComparableHeap[T]{ - Heap: EmptyHeap(comparator), - } -} - -// ComparableFromSlice creates heap, based on provided slice. -// Slice could be reordered. -func ComparableFromSlice[T comparable](data []T, comparator func(x, y T) bool) ComparableHeap[T] { - return ComparableHeap[T]{ - Heap: FromSlice(data, comparator), - } -} - -// Search returns if element presents in heap. -func (h *ComparableHeap[T]) Search(x T) bool { - return h.search(x) != -1 -} - -// Delete removes element from heap, and returns true if x presents in heap. -func (h *ComparableHeap[T]) Delete(x T) bool { - pos := h.search(x) - if pos == -1 { - return false - } - newLen := h.Len() - 1 - h.swap(pos, newLen) - h.data = h.data[:newLen] - - return true -} - -func (h *ComparableHeap[T]) search(x T) int { - for i := range h.data { - if h.data[i] == x { - return i - } - } - return -1 -} - -// EmptyMinHeap creates empty Min-Heap for ordered types. -func EmptyMinHeap[T constraints.Ordered]() ComparableHeap[T] { - return EmptyComparableHeap(func(x, y T) bool { - return x < y - }) -} - -// EmptyMaxHeap creates empty Max-Heap for ordered types. -func EmptyMaxHeap[T constraints.Ordered]() ComparableHeap[T] { - return EmptyComparableHeap(func(x, y T) bool { - return x > y - }) -} - -// EmptyMinHeap creates Min-Heap, based on provided slice. -// Slice could be reordered. -func MinHeapFromSlice[T constraints.Ordered](data []T) ComparableHeap[T] { - return ComparableFromSlice(data, func(x, y T) bool { - return x < y - }) -} - -// EmptyMaxHeap creates Max-Heap, based on provided slice. -// Slice could be reordered. -func MaxHeapFromSlice[T constraints.Ordered](data []T) ComparableHeap[T] { - return ComparableFromSlice(data, func(x, y T) bool { - return x > y - }) -} diff --git a/vendor/github.com/lispad/go-generics-tools/binheap/topn.go b/vendor/github.com/lispad/go-generics-tools/binheap/topn.go deleted file mode 100644 index 679d1a6f79..0000000000 --- a/vendor/github.com/lispad/go-generics-tools/binheap/topn.go +++ /dev/null @@ -1,48 +0,0 @@ -package binheap - -import ( - "golang.org/x/exp/constraints" - "golang.org/x/exp/slices" -) - -// TopN mutates data slice, moving TopN elements of slice to the beginning and returns subslice of first n elements. -// O(M *ln(N)), where M is slice size -// Mutates source data slice. No additional allocations are done. -func TopN[T any](data []T, n int, comparator func(x, y T) bool) []T { - if n > len(data) { - n = len(data) - } - heap := FromSlice(data[0:n], reverse(comparator)) - for i := n; i < len(data); i++ { - if !comparator(data[0], data[i]) { - data[0], data[i] = data[i], data[0] - heap.fix(0) - } - } - slices.SortFunc(data[0:n], comparator) - return data[0:n] -} - -// MinN moves N Min elements of slice to the beginning and returns subslice of first n elements. -// Mutates source data slice. -// No additional allocations are done. -func MinN[T constraints.Ordered](data []T, n int) []T { - return TopN(data, n, func(x, y T) bool { - return x < y - }) -} - -// MaxN moves N Max elements of slice to the beginning and returns subslice of first n elements. -// Mutates source data slice. -// No additional allocations are done. -func MaxN[T constraints.Ordered](data []T, n int) []T { - return TopN(data, n, func(x, y T) bool { - return x > y - }) -} - -func reverse[T any](comparator func(x, y T) bool) func(x, y T) bool { - return func(x, y T) bool { - return !comparator(x, y) - } -} diff --git a/vendor/github.com/lispad/go-generics-tools/binheap/topstream.go b/vendor/github.com/lispad/go-generics-tools/binheap/topstream.go deleted file mode 100644 index 8eb11ecefd..0000000000 --- a/vendor/github.com/lispad/go-generics-tools/binheap/topstream.go +++ /dev/null @@ -1,80 +0,0 @@ -package binheap - -import ( - "golang.org/x/exp/constraints" - "golang.org/x/exp/slices" -) - -// TopNHeap keeps N top elements in reverse order. -type TopNHeap[T any] struct { - comparator func(x, y T) bool - heap Heap[T] - maxSize int -} - -// EmptyTopNHeap creates new heap for storing n top elements. -func EmptyTopNHeap[T any](n int, comparator func(x, y T) bool) TopNHeap[T] { - return TopNHeap[T]{ - comparator: comparator, - heap: EmptyHeap(reverse(comparator)), - maxSize: n, - } -} - -// Push stores x, if x is better than top n, or ignores otherwise. -func (h *TopNHeap[T]) Push(x T) { - if h.heap.Len() < h.maxSize { - h.heap.Push(x) - return - } - - if !h.comparator(h.heap.data[0], x) { - h.heap.Replace(x) - } -} - -// PopTopN returns current top N elements, and empties slice. -func (h *TopNHeap[T]) PopTopN() []T { - result := h.PeekTopN() - h.heap.data = h.heap.data[:0] - - return result -} - -// PeekTopN returns current top N elements. -func (h *TopNHeap[T]) PeekTopN() []T { - result := make([]T, h.heap.Len()) - copy(result, h.heap.data) - slices.SortFunc(result, h.comparator) - - return result -} - -// TopNImmutable returns top n elements from slice. -// O(M *ln(N)), where M is slice size -// Allocates new slice, source data isn't mutated. O(N) additional allocations. -func TopNImmutable[T any](data []T, n int, comparator func(x, y T) bool) []T { - h := EmptyTopNHeap(n, comparator) - for _, x := range data { - h.Push(x) - } - return h.PopTopN() -} - -// MinNImmutable return n minimal elements from slice. -// O(M *ln(N)), where M is slice size -// Allocates new slice, source data isn't mutated. O(N) additional allocations. -func MinNImmutable[T constraints.Ordered](data []T, n int) []T { - return TopNImmutable(data, n, func(x, y T) bool { - return x < y - }) -} - -// MaxNImmutable return n maximal elements from slice. -// O(M *ln(N)), where M is slice size -// Allocates new slice, source data isn't mutated. O(N) additional allocations. -func MaxNImmutable[T constraints.Ordered](data []T, n int) []T { - return TopNImmutable(data, n, func(x, y T) bool { - return x > y - }) -} diff --git a/vendor/modules.txt b/vendor/modules.txt index 4bdf4cdd71..4d43b34d18 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -51,7 +51,7 @@ github.com/CortexFoundation/robot/backend # github.com/CortexFoundation/statik v0.0.0-20210315012922-8bb8a7b5dc66 ## explicit; go 1.16 github.com/CortexFoundation/statik -# github.com/CortexFoundation/torrentfs v1.0.53-0.20230815075557-4bffeba9600c +# github.com/CortexFoundation/torrentfs v1.0.53-0.20230816125424-a7c2a24d3217 ## explicit; go 1.20 github.com/CortexFoundation/torrentfs github.com/CortexFoundation/torrentfs/backend @@ -97,9 +97,10 @@ github.com/anacrolix/dht/v2/types # github.com/anacrolix/envpprof v1.3.0 ## explicit; go 1.12 github.com/anacrolix/envpprof -# github.com/anacrolix/generics v0.0.0-20230428105757-683593396d68 +# github.com/anacrolix/generics v0.0.0-20230816103846-fe11fdc0e0e3 ## explicit; go 1.18 github.com/anacrolix/generics +github.com/anacrolix/generics/heap # github.com/anacrolix/go-libutp v1.3.1 ## explicit; go 1.14 github.com/anacrolix/go-libutp @@ -142,7 +143,7 @@ github.com/anacrolix/stm/stmutil # github.com/anacrolix/sync v0.4.0 ## explicit; go 1.13 github.com/anacrolix/sync -# github.com/anacrolix/torrent v1.52.5 +# github.com/anacrolix/torrent v1.52.6-0.20230816110201-613470861e67 ## explicit; go 1.20 github.com/anacrolix/torrent github.com/anacrolix/torrent/analysis @@ -755,9 +756,6 @@ github.com/labstack/gommon/log # github.com/leodido/go-urn v1.2.4 ## explicit; go 1.16 github.com/leodido/go-urn -# github.com/lispad/go-generics-tools v1.1.0 -## explicit; go 1.18 -github.com/lispad/go-generics-tools/binheap # github.com/lucasb-eyer/go-colorful v1.2.0 ## explicit; go 1.12 github.com/lucasb-eyer/go-colorful