torrent/pending-requests.go

34 lines
502 B
Go
Raw Normal View History

2021-10-09 08:00:58 +00:00
package torrent
type pendingRequests struct {
m []int
2021-10-09 08:00:58 +00:00
}
2021-10-10 00:19:08 +00:00
func (p *pendingRequests) Dec(r RequestIndex) {
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
}
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) {
p.m[r]++
2021-10-09 08:00:58 +00:00
}
func (p *pendingRequests) Init(maxIndex RequestIndex) {
p.m = make([]int, maxIndex)
2021-10-09 08:00:58 +00:00
}
func (p *pendingRequests) AssertEmpty() {
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 {
return p.m[r]
2021-10-09 08:00:58 +00:00
}