ringbuffer

package
v1.0.22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2024 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RingBuffer

type RingBuffer[T any] struct {
	// contains filtered or unexported fields
}

RingBuffer A fast Golang queue using a ring-buffer, based on the version suggested by Dariusz Górecki. Using this instead of other, simpler, queue implementations (slice+append or linked list) provides substantial memory and time benefits, and fewer GC pauses. The queue implemented here is as fast as it is in part because it is not thread-safe.

func NewRingBuffer

func NewRingBuffer[T any](vs ...T) *RingBuffer[T]

NewRingBuffer constructs and returns a new RingBuffer. Example: cog.NewRingBuffer(1, 2, 3)

func (*RingBuffer[T]) Add

func (rb *RingBuffer[T]) Add(v T)

Add add item v.

func (*RingBuffer[T]) AddCol

func (rb *RingBuffer[T]) AddCol(ac cog.Collection[T])

AddCol adds all items of another collection

func (*RingBuffer[T]) Adds

func (rb *RingBuffer[T]) Adds(vs ...T)

Adds adds all items of vs.

func (*RingBuffer[T]) Cap

func (rb *RingBuffer[T]) Cap() int

Cap returns the capcity of the buffer.

func (*RingBuffer[T]) Clear

func (rb *RingBuffer[T]) Clear()

Clear clears list al.

func (*RingBuffer[T]) Contain

func (rb *RingBuffer[T]) Contain(v T) bool

Contain Test to see if the list contains the value v

func (*RingBuffer[T]) ContainCol

func (rb *RingBuffer[T]) ContainCol(ac cog.Collection[T]) bool

ContainCol Test to see if the collection contains all items of another collection

func (*RingBuffer[T]) ContainIter

func (rb *RingBuffer[T]) ContainIter(it cog.Iterator[T]) bool

ContainIter Test to see if the collection contains all items of iterator 'it'

func (*RingBuffer[T]) Contains

func (rb *RingBuffer[T]) Contains(vs ...T) bool

Contains Test to see if the RingBuffer contains the value v

func (*RingBuffer[T]) DeleteAt

func (rb *RingBuffer[T]) DeleteAt(index int)

DeleteAt remove the item at the specified position in this RingBuffer.

func (*RingBuffer[T]) Each

func (rb *RingBuffer[T]) Each(f func(int, T) bool)

Each call f for each item in the RingBuffer

func (*RingBuffer[T]) Get

func (rb *RingBuffer[T]) Get(index int) T

Get returns the item at the specified position in this RingBuffer if i < -rb.Len() or i >= rb.Len(), panic if i < 0, returns rb.Get(rb.Len() + i)

func (*RingBuffer[T]) Head

func (rb *RingBuffer[T]) Head() (v T)

Head get the first item of RingBuffer.

func (*RingBuffer[T]) Index

func (rb *RingBuffer[T]) Index(v T) int

Index returns the index of the first occurrence of the specified v in this RingBuffer, or -1 if this RingBuffer does not contain v.

func (*RingBuffer[T]) IndexFunc

func (rb *RingBuffer[T]) IndexFunc(f func(T) bool) int

IndexFunc returns the index of the first true returned by function f in this list, or -1 if this list does not contain v.

func (*RingBuffer[T]) Insert

func (rb *RingBuffer[T]) Insert(index int, v T)

Insert insert value v at specified index position shifting the value at that position (if any) and any subsequent elements to the right. Panic if position is bigger than RingBuffer's size Note: position equal to RingBuffer's size is valid, i.e. append.

func (*RingBuffer[T]) InsertCol

func (rb *RingBuffer[T]) InsertCol(index int, ac cog.Collection[T])

InsertCol inserts values of another collection ac at specified index position shifting the value at that position (if any) and any subsequent elements to the right. Panic if position is bigger than RingBuffer's size Note: position equal to RingBuffer's size is valid, i.e. append.

func (*RingBuffer[T]) Inserts

func (rb *RingBuffer[T]) Inserts(index int, vs ...T)

Inserts inserts values at specified index position shifting the value at that position (if any) and any subsequent elements to the right. Panic if position is bigger than RingBuffer's size Note: position equal to RingBuffer's size is valid, i.e. append.

func (*RingBuffer[T]) IsEmpty

func (rb *RingBuffer[T]) IsEmpty() bool

IsEmpty returns true if the container length == 0

func (*RingBuffer[T]) Iterator

func (rb *RingBuffer[T]) Iterator() cog.Iterator[T]

Iterator returns a iterator for the RingBuffer

func (*RingBuffer[T]) Len

func (rb *RingBuffer[T]) Len() int

Len returns the number of elements currently stored in the buffer.

func (*RingBuffer[T]) MarshalJSON

func (rb *RingBuffer[T]) MarshalJSON() ([]byte, error)

MarshalJSON implements type json.Marshaler interface, so can be called in json.Marshal(rb)

func (*RingBuffer[T]) MustPeek

func (rb *RingBuffer[T]) MustPeek() T

MustPeek Retrieves, but does not remove, the head of this queue, panic if this queue is empty.

func (*RingBuffer[T]) MustPoll

func (rb *RingBuffer[T]) MustPoll() T

MustPoll Retrieves and removes the head of this queue, panic if this queue is empty.

func (*RingBuffer[T]) Peek

func (rb *RingBuffer[T]) Peek() (v T, ok bool)

Peek get the first item of RingBuffer.

func (*RingBuffer[T]) PeekHead

func (rb *RingBuffer[T]) PeekHead() (v T, ok bool)

PeekHead get the first item of RingBuffer.

func (*RingBuffer[T]) PeekTail

func (rb *RingBuffer[T]) PeekTail() (v T, ok bool)

PeekTail get the last item of RingBuffer.

func (*RingBuffer[T]) Poll

func (rb *RingBuffer[T]) Poll() (T, bool)

Poll get and remove the first item of RingBuffer.

func (*RingBuffer[T]) PollHead

func (rb *RingBuffer[T]) PollHead() (v T, ok bool)

PollHead get and remove the first item of RingBuffer.

func (*RingBuffer[T]) PollTail

func (rb *RingBuffer[T]) PollTail() (v T, ok bool)

PollTail get and remove the last item of RingBuffer.

func (*RingBuffer[T]) Push

func (rb *RingBuffer[T]) Push(v T)

Push insert item v at the tail of RingBuffer rb.

func (*RingBuffer[T]) PushHead

func (rb *RingBuffer[T]) PushHead(v T)

PushHead insert item v at the head of RingBuffer rb.

func (*RingBuffer[T]) PushHeadCol

func (rb *RingBuffer[T]) PushHeadCol(ac cog.Collection[T])

PushHeadCol inserts a copy of another collection at the head of RingBuffer rb. The rb and ac may be the same. They must not be nil.

func (*RingBuffer[T]) PushHeads

func (rb *RingBuffer[T]) PushHeads(vs ...T)

PushHeads inserts all items of vs at the head of RingBuffer rb.

func (*RingBuffer[T]) PushTail

func (rb *RingBuffer[T]) PushTail(v T)

PushTail insert item v at the tail of RingBuffer rb.

func (*RingBuffer[T]) PushTailCol

func (rb *RingBuffer[T]) PushTailCol(ac cog.Collection[T])

PushTailCol inserts a copy of another collection at the tail of RingBuffer rb. The rb and ac may be the same. They must not be nil.

func (*RingBuffer[T]) PushTails

func (rb *RingBuffer[T]) PushTails(vs ...T)

PushTails inserts all items of vs at the tail of RingBuffer rb.

func (*RingBuffer[T]) Pushs

func (rb *RingBuffer[T]) Pushs(vs ...T)

Pushs inserts all items of vs at the tail of RingBuffer rb.

func (*RingBuffer[T]) Remove

func (rb *RingBuffer[T]) Remove(v T)

Remove remove all items with associated value v of vs

func (*RingBuffer[T]) RemoveCol

func (rb *RingBuffer[T]) RemoveCol(ac cog.Collection[T])

RemoveCol remove all of this collection's elements that are also contained in the specified collection

func (*RingBuffer[T]) RemoveFunc

func (rb *RingBuffer[T]) RemoveFunc(f func(T) bool)

RemoveFunc remove all items that function f returns true

func (*RingBuffer[T]) RemoveIter

func (rb *RingBuffer[T]) RemoveIter(it cog.Iterator[T])

RemoveIter remove all items in the iterator it

func (*RingBuffer[T]) Removes

func (rb *RingBuffer[T]) Removes(vs ...T)

Removes remove all items in the array vs

func (*RingBuffer[T]) RetainCol

func (rb *RingBuffer[T]) RetainCol(ac cog.Collection[T])

RetainCol Retains only the elements in this collection that are contained in the specified collection.

func (*RingBuffer[T]) RetainFunc

func (rb *RingBuffer[T]) RetainFunc(f func(T) bool)

RetainFunc Retains all items that function f returns true

func (*RingBuffer[T]) Retains

func (rb *RingBuffer[T]) Retains(vs ...T)

Retains Retains only the elements in this collection that are contained in the argument array vs.

func (*RingBuffer[T]) ReverseEach

func (rb *RingBuffer[T]) ReverseEach(f func(int, T) bool)

ReverseEach call f for each item in the RingBuffer with reverse order

func (*RingBuffer[T]) Set

func (rb *RingBuffer[T]) Set(index int, v T) (ov T)

Set set the v at the specified index in this RingBuffer and returns the old value.

func (*RingBuffer[T]) Sort

func (rb *RingBuffer[T]) Sort(less cog.Less[T])

Sort Sorts this RingBuffer according to the order induced by the specified Comparator.

func (*RingBuffer[T]) String

func (rb *RingBuffer[T]) String() string

String print RingBuffer to string

func (*RingBuffer[T]) Swap

func (rb *RingBuffer[T]) Swap(i, j int)

Swap swaps values of two items at the given index.

func (*RingBuffer[T]) Tail

func (rb *RingBuffer[T]) Tail() (v T)

Tail get the last item of RingBuffer.

func (*RingBuffer[T]) UnmarshalJSON

func (rb *RingBuffer[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON implements type json.Unmarshaler interface, so can be called in json.Unmarshal(data, rb)

func (*RingBuffer[T]) Values

func (rb *RingBuffer[T]) Values() []T

Values returns a slice contains all the items of the RingBuffer rb

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL