2
0
mirror of synced 2025-02-23 22:28:11 +00:00
torrent/pending-requests.go
2021-10-19 14:08:56 +11:00

35 lines
487 B
Go

package torrent
type pendingRequests struct {
m map[RequestIndex]int
}
func (p pendingRequests) Dec(r RequestIndex) {
p.m[r]--
n := p.m[r]
if n == 0 {
delete(p.m, r)
}
if n < 0 {
panic(n)
}
}
func (p pendingRequests) Inc(r RequestIndex) {
p.m[r]++
}
func (p *pendingRequests) Init() {
p.m = make(map[RequestIndex]int)
}
func (p *pendingRequests) AssertEmpty() {
if len(p.m) != 0 {
panic(p.m)
}
}
func (p pendingRequests) Get(r RequestIndex) int {
return p.m[r]
}