]> Sergey Matveev's repositories - btrtrc.git/blob - pending-requests.go
Merge branch 'peer-requesting'
[btrtrc.git] / pending-requests.go
1 package torrent
2
3 type pendingRequests struct {
4         m []int
5 }
6
7 func (p *pendingRequests) Dec(r RequestIndex) {
8         prev := p.m[r]
9         if prev <= 0 {
10                 panic(prev)
11         }
12         p.m[r]--
13 }
14
15 func (p *pendingRequests) Inc(r RequestIndex) {
16         p.m[r]++
17 }
18
19 func (p *pendingRequests) Init(maxIndex RequestIndex) {
20         p.m = make([]int, maxIndex)
21 }
22
23 func (p *pendingRequests) AssertEmpty() {
24         for _, count := range p.m {
25                 if count != 0 {
26                         panic(count)
27                 }
28         }
29 }
30
31 func (p *pendingRequests) Get(r RequestIndex) int {
32         return p.m[r]
33 }