github.com/geph-official/geph2@v0.22.6-0.20210211030601-f527cb59b0df/libs/niaucchi4/e2e_window.go (about) 1 package niaucchi4 2 3 const rwSize = 128 4 5 type replayWindow struct { 6 lastBuf []uint64 7 bufPtr uint8 8 highest uint64 9 } 10 11 func (rw *replayWindow) add(val uint64) { 12 // add 13 if len(rw.lastBuf) < rwSize { 14 rw.lastBuf = append(rw.lastBuf, val) 15 } else { 16 rw.lastBuf[rw.bufPtr] = val 17 rw.bufPtr++ 18 rw.bufPtr %= rwSize 19 } 20 } 21 22 func (rw *replayWindow) check(val uint64) bool { 23 if val+rwSize < rw.highest { 24 return false 25 } 26 if val > rw.highest { 27 // obviously not replay 28 rw.highest = val 29 rw.add(val) 30 return true 31 } 32 // check if already exists 33 for _, v := range rw.lastBuf { 34 if v == val { 35 return false 36 } 37 } 38 rw.add(val) 39 return true 40 }