ring

package module
v0.0.0-...-fc4206c Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package ring implements a ring data structure for efficiently storing the n most recent entries added to it. The ring data structure is comparable to a ring buffer, but with only one pointer for writing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry interface{}

Entry is the Entry type stored in the data structure. You may want to change the type from interface{} to something else if you're actually using this.

type Ring

type Ring struct {
	// contains filtered or unexported fields
}

Ring implements a ring data structure.

func New

func New(capacity int) *Ring

New creates a new ring data structure of the given capacity.

func (*Ring) Add

func (r *Ring) Add(entry Entry)

Add adds an entry to the ring, appending it if the ring hasn't reached its capacity yet, or otherwise replacing the oldest entry.

func (*Ring) All

func (r *Ring) All() []Entry

All returns a copy of the contents of the ring, starting with the oldest entry and ending with the most recently added entry.

func (*Ring) Last

func (r *Ring) Last() (Entry, bool)

Last returns the most recently added entry.

Jump to

Keyboard shortcuts

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