shaper.go 480 B

1234567891011121314151617
  1. package gfsmux // import "go.gridfinity.dev/gfsmux"
  2. type ShaperHeap []WriteRequest
  3. func (h ShaperHeap) Len() int { return len(h) }
  4. func (h ShaperHeap) Less(i, j int) bool { return h[i].Prio < h[j].Prio }
  5. func (h ShaperHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
  6. func (h *ShaperHeap) Push(x interface{}) { *h = append(*h, x.(WriteRequest)) }
  7. func (h *ShaperHeap) Pop() interface{} {
  8. old := *h
  9. n := len(old)
  10. x := old[n-1]
  11. *h = old[0 : n-1]
  12. return x
  13. }