circularQueue

package
v0.0.0-...-3728fe3 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

CircularQueue implements a circular queue of RTCM messages.

NewCircularQueue(n) creates a circular queue that holds up to n messages. The queue contains a pointer to a mutex so always use this function to create a queue.

Add(message) adds a message to the queue. If the queue is already full, it removes the oldest message to make way for the new one.

GetMessages() gets the messages in the circular queue as a slice, in the order in which they were added.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CircularQueue

type CircularQueue struct {
	// MaxItems is the maximum number of items in the circular queue.
	MaxItems int
	// Items is a map containing the messages each with a unique index.
	Items map[int]rtcm.Message
	// NextIndex is the next unique index, assigned when a message is added.
	NextIndex int

	// The mutex controls asynchronous access to the circular queue.
	// See https://go.dev/blog/maps
	*sync.RWMutex
}

CircularQueue holds a limited number of RTCM messages. If a message is added and the buffer is already full, the oldest message is removed to make way for the new one. The buffer is safe against asynchronous access.

func NewCircularQueue

func NewCircularQueue(max int) *CircularQueue

NewCircularQueue creates a new circular queue.

func (*CircularQueue) Add

func (cb *CircularQueue) Add(message rtcm.Message)

Add adds a new message to the queue, removing the oldest if necessary.

func (*CircularQueue) GetMessages

func (cb *CircularQueue) GetMessages() []rtcm.Message

GetMessages gets the items in the circular queue as a slice, in ascending order of key, ie in the order that they were added.

Jump to

Keyboard shortcuts

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