~trn/gfsmux

ref: 2106.0.0 gfsmux/shaper.go -rw-r--r-- 554 bytes
753dd037 — Jeffrey H. Johnson Update dependencies 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package gfsmux

// ShaperHeap ...
type ShaperHeap []WriteRequest

// Len ...
func (
	h ShaperHeap,
) Len() int {
	return len(
		h,
	)
}

// Less ...
func (
	h ShaperHeap,
) Less(
	i,
	j int,
) bool {
	return h[i].Prio < h[j].Prio
}

// Swap ...
func (
	h ShaperHeap,
) Swap(
	i,
	j int,
) {
	h[i], h[j] = h[j], h[i]
}

// Push ...
func (
	h *ShaperHeap,
) Push(
	x interface{},
) {
	*h = append(*h, x.(WriteRequest))
}

// Pop ...
func (
	h *ShaperHeap,
) Pop() interface{} {
	old := *h
	n := len(
		old,
	)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}