35 lines
666 B
Go
35 lines
666 B
Go
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
|
// All rights reserved.
|
|
|
|
// byte-slider.go
|
|
package expr
|
|
|
|
import "bytes"
|
|
|
|
type ByteSlider struct {
|
|
buf []byte
|
|
length int
|
|
}
|
|
|
|
func NewByteSlider(size int) *ByteSlider {
|
|
return &ByteSlider{
|
|
buf: make([]byte, max(1, size)),
|
|
length: 0,
|
|
}
|
|
}
|
|
|
|
func (slider *ByteSlider) PushEnd(b byte) {
|
|
if slider.length == cap(slider.buf) {
|
|
slider.length--
|
|
for i := 0; i < slider.length; i++ {
|
|
slider.buf[i] = slider.buf[i+1]
|
|
}
|
|
}
|
|
slider.buf[slider.length] = b
|
|
slider.length++
|
|
}
|
|
|
|
func (slider *ByteSlider) Equal(target []byte) bool {
|
|
return target != nil && bytes.Equal(slider.buf, target)
|
|
}
|