Documentation
¶
Index ¶
- type Buffer
- func (b *Buffer[T]) All() iter.Seq[T]
- func (b *Buffer[T]) Cap() int
- func (b *Buffer[T]) Copy(dst []T, i int) int
- func (b *Buffer[T]) DiscardFromEnd(n int) int
- func (b *Buffer[T]) DiscardFromStart(n int) int
- func (b *Buffer[T]) Get(i int) T
- func (b *Buffer[T]) Len() int
- func (b *Buffer[T]) PeekEnd() T
- func (b *Buffer[T]) PeekStart() T
- func (b *Buffer[T]) PopEnd() T
- func (b *Buffer[T]) PopStart() T
- func (b *Buffer[T]) PushEnd(x T)
- func (b *Buffer[T]) PushSliceEnd(src []T)
- func (b *Buffer[T]) PushSliceStart(src []T)
- func (b *Buffer[T]) PushStart(x T)
- func (b *Buffer[T]) SetCap(n int)
- func (b *Buffer[T]) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer[T any] struct { // contains filtered or unexported fields }
Buffer holds a slice-backed ring buffer. Elements can be added and removed at both the start and the end of the buffer.
Elements are indexed from zero (the start) to the end. Pushing elements at the start will implicitly reindex all previous elements.
The zero-value is OK to use.
func (*Buffer[T]) Copy ¶
Copy copies min(b.Len(), len(dst)) values into dst from index i in the buffer onwards. It does not affect the size of the buffer. It returns the number of elements actually copied. It panics if i is out of range.
func (*Buffer[T]) DiscardFromEnd ¶
DiscardFromEnd discards min(b.Len(), n) elements from the end of the buffer and returns the number actually discarded
func (*Buffer[T]) DiscardFromStart ¶
DiscardFromStart discards min(b.Len(), n) elements from the start of the buffer and returns the number actually discarded
func (*Buffer[T]) Get ¶
Get returns the i'th element in the buffer; the start element is at index zero; the end is at b.Len() - 1. It panics if i is out of range.
func (*Buffer[T]) PeekEnd ¶
func (b *Buffer[T]) PeekEnd() T
PeekEnd returns the element at the end of the buffer without consuming it. It's equivalent to b.Get(b.Len()-1).
func (*Buffer[T]) PeekStart ¶
func (b *Buffer[T]) PeekStart() T
PeekStart returns the element at the start of the buffer without consuming it. It's equivalent to b.Get(0), and panics if the buffer is empty.
func (*Buffer[T]) PopEnd ¶
func (b *Buffer[T]) PopEnd() T
PopStart removes and returns the element from the end of the buffer. If the buffer is empty, the call will panic.
func (*Buffer[T]) PopStart ¶
func (b *Buffer[T]) PopStart() T
PopStart removes and returns the element from the start of the buffer. If the buffer is empty, the call will panic.
func (*Buffer[T]) PushEnd ¶
func (b *Buffer[T]) PushEnd(x T)
PushEnd adds an element to the end of the buffer.
func (*Buffer[T]) PushSliceEnd ¶
func (b *Buffer[T]) PushSliceEnd(src []T)
PushSliceEnd pushes all the elements of the given slice onto the end of the buffer. It's just like:
for _, x := range src {
b.PushEnd(x)
}
but more efficient.
func (*Buffer[T]) PushSliceStart ¶
func (b *Buffer[T]) PushSliceStart(src []T)
PushSliceStart pushes all the elements of the given slice onto the end of the buffer. It's just like:
for i := len(src)-1; i>=0; i-- {
b.PushStart(src[i])
}
but more efficient.
func (*Buffer[T]) PushStart ¶
func (b *Buffer[T]) PushStart(x T)
PushStart pushes an element to the start of the buffer.