byte-ring.go -> byte-slider.go
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
// 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 (self *ByteSlider) PushEnd(b byte) {
|
||||
if self.length == cap(self.buf) {
|
||||
self.length--
|
||||
for i := 0; i < self.length; i++ {
|
||||
self.buf[i] = self.buf[i+1]
|
||||
}
|
||||
}
|
||||
self.buf[self.length] = b
|
||||
self.length++
|
||||
}
|
||||
|
||||
func (self *ByteSlider) Equal(target []byte) bool {
|
||||
return target != nil && bytes.Equal(self.buf, target)
|
||||
}
|
||||
Reference in New Issue
Block a user