rephrase tcp.Value methods; add Ring.FreeLimited; work on TxQueue

This commit is contained in:
soypat
2025-01-18 09:30:36 -03:00
parent 93d1f80015
commit 51ca0a95b5
5 changed files with 95 additions and 39 deletions
+6 -6
View File
@@ -24,24 +24,24 @@ type Value uint32
type Size uint32
// LessThan checks if v is before w (modulo 32) i.e., v < w.
func LessThan(v, w Value) bool {
func (v Value) LessThan(w Value) bool {
return int32(v-w) < 0
}
// LessThanEq returns true if v==w or v is before (modulo 32) i.e., v < w.
func LessThanEq(v, w Value) bool {
return v == w || LessThan(v, w)
func (v Value) LessThanEq(w Value) bool {
return v == w || v.LessThan(w)
}
// InRange checks if v is in the range [a,b) (modulo 32), i.e., a <= v < b.
func InRange(v, a, b Value) bool {
func (v Value) InRange(a, b Value) bool {
return v-a < b-a
}
// InWindow checks if v is in the window that starts at 'first' and spans 'size'
// sequence numbers (modulo 32).
func InWindow(v, first Value, size Size) bool {
return InRange(v, first, Add(first, size))
func (v Value) InWindow(first Value, size Size) bool {
return v.InRange(first, Add(first, size))
}
// Add calculates the sequence number following the [v, v+s) window.