shaper.go 554 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package gfsmux
  2. // ShaperHeap ...
  3. type ShaperHeap []WriteRequest
  4. // Len ...
  5. func (
  6. h ShaperHeap,
  7. ) Len() int {
  8. return len(
  9. h,
  10. )
  11. }
  12. // Less ...
  13. func (
  14. h ShaperHeap,
  15. ) Less(
  16. i,
  17. j int,
  18. ) bool {
  19. return h[i].Prio < h[j].Prio
  20. }
  21. // Swap ...
  22. func (
  23. h ShaperHeap,
  24. ) Swap(
  25. i,
  26. j int,
  27. ) {
  28. h[i], h[j] = h[j], h[i]
  29. }
  30. // Push ...
  31. func (
  32. h *ShaperHeap,
  33. ) Push(
  34. x interface{},
  35. ) {
  36. *h = append(*h, x.(WriteRequest))
  37. }
  38. // Pop ...
  39. func (
  40. h *ShaperHeap,
  41. ) Pop() interface{} {
  42. old := *h
  43. n := len(
  44. old,
  45. )
  46. x := old[n-1]
  47. *h = old[0 : n-1]
  48. return x
  49. }