2021-10-09 08:00:58 +00:00
|
|
|
package torrent
|
|
|
|
|
|
|
|
type pendingRequests struct {
|
2021-10-10 00:54:19 +00:00
|
|
|
m []int
|
2021-10-09 08:00:58 +00:00
|
|
|
}
|
|
|
|
|
2021-10-10 00:19:08 +00:00
|
|
|
func (p *pendingRequests) Dec(r RequestIndex) {
|
2021-10-10 00:54:19 +00:00
|
|
|
prev := p.m[r]
|
2021-10-10 00:19:08 +00:00
|
|
|
if prev <= 0 {
|
|
|
|
panic(prev)
|
2021-10-09 08:00:58 +00:00
|
|
|
}
|
2021-10-10 00:54:19 +00:00
|
|
|
p.m[r]--
|
2021-10-09 08:00:58 +00:00
|
|
|
}
|
|
|
|
|
2021-10-10 00:19:08 +00:00
|
|
|
func (p *pendingRequests) Inc(r RequestIndex) {
|
2021-10-10 00:54:19 +00:00
|
|
|
p.m[r]++
|
2021-10-09 08:00:58 +00:00
|
|
|
}
|
|
|
|
|
2021-10-10 00:32:27 +00:00
|
|
|
func (p *pendingRequests) Init(maxIndex RequestIndex) {
|
2021-10-10 00:54:19 +00:00
|
|
|
p.m = make([]int, maxIndex)
|
2021-10-09 08:00:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *pendingRequests) AssertEmpty() {
|
2021-10-10 00:54:19 +00:00
|
|
|
for _, count := range p.m {
|
|
|
|
if count != 0 {
|
|
|
|
panic(count)
|
|
|
|
}
|
2021-10-10 00:19:08 +00:00
|
|
|
}
|
2021-10-09 08:00:58 +00:00
|
|
|
}
|
|
|
|
|
2021-10-10 00:19:08 +00:00
|
|
|
func (p *pendingRequests) Get(r RequestIndex) int {
|
2021-10-10 00:54:19 +00:00
|
|
|
return p.m[r]
|
2021-10-09 08:00:58 +00:00
|
|
|
}
|