Files
starcodedoc-demo-go-sequenc…/audit/window.go
2026-09-25 11:57:14 +08:00

24 lines
652 B
Go

package audit
type Window struct {
Last uint16
HasLast bool
Summary Summary
}
func (w *Window) Observe(sequence uint16) string {
if !w.HasLast {
w.Last, w.HasLast = sequence, true
w.Summary.Accepted++
w.Summary.Latest = sequence
return "accepted"
}
delta := uint16(sequence - w.Last)
if delta == 0 { w.Summary.Duplicate++; return "duplicate" }
if delta > 32767 { w.Summary.Reordered++; return "reordered" }
if delta > 1 { w.Summary.Lost += uint64(delta - 1) }
w.Last, w.Summary.Latest = sequence, sequence
w.Summary.Accepted++
return "accepted"
}