Documentation
¶
Overview ¶
Package seq is a fast implementation of sequence buffers described in Go with 100% unit test coverage.
Index ¶
- Constants
- func GT(a, b uint16) bool
- func GTE(a, b uint16) bool
- func LT(a, b uint16) bool
- func LTE(a, b uint16) bool
- type Buffer
- func (b *Buffer) At(seq uint16) interface{}
- func (b *Buffer) Exists(seq uint16) bool
- func (b *Buffer) Find(seq uint16) interface{}
- func (b *Buffer) GenerateBitset32(ack uint16) (ackBits uint32)
- func (b *Buffer) GenerateLatestBitset32() (ack uint16, ackBits uint32)
- func (b *Buffer) Insert(seq uint16, item interface{}) bool
- func (b *Buffer) Latest() uint16
- func (b *Buffer) Len() uint16
- func (b *Buffer) Next() uint16
- func (b *Buffer) Outdated(seq uint16, size uint16) bool
- func (b *Buffer) Remove(seq uint16)
- func (b *Buffer) RemoveRange(start, end uint16)
- func (b *Buffer) Reset()
Constants ¶
const HalfMaxUint16 = uint16(math.MaxUint16/2) + 1
Half the max value of an unsigned 16-bit integer.
Variables ¶
This section is empty.
Functions ¶
func GT ¶
GT returns whether or not the sequence number a is greater than b. This is done by returning whether or not a and b are apart by more than 32767 (half the max value of an unsigned 16-bit integer).
func GTE ¶
GTE returns whether or not the sequence number a is greater than or equal to b. See GT for how this is determined.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is a fast, fixed-sized rolling buffer that buffers entries based on an unsigned 16-bit integer.
func (*Buffer) GenerateBitset32 ¶
GenerateBitset32 generates a 32-bit integer representative of a bitset where entries at index i are 1 if there exists an entry in the buffer whose sequence number is equal to the largest sequence number inserted/acknowledged so far minus i. It returns both the largest sequence number known thus far alongside the bitset as an unsigned 16-bit integer and an unsigned 32-bit integer respectively.
func (*Buffer) GenerateLatestBitset32 ¶
GenerateLatestBitset32 calls GenerateBitset32 on the latest known sequence number.
func (*Buffer) Insert ¶
Insert inserts a new item into this buffer indexed by seq, should seq not be outdated. It returns true if the insertion is successful.
func (*Buffer) Latest ¶
Latest returns the latest sequence number inserted/acknowledged by this buffer.
func (*Buffer) Next ¶
Next returns the next expected sequence number to be inserted/acknowledged by this buffer.
func (*Buffer) Outdated ¶
Outdated returns true if seq is capable of being stored in this buffer based on the largest sequence number that has been inserted/acknowledged so far.
func (*Buffer) RemoveRange ¶
RemoveRange invalidates all items and entries with sequence numbers in the range [start, end].