history

package
v0.15.3 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: Apache-2.0 Imports: 1 Imported by: 5

Documentation

Overview

Package history implements a circular buffer with adjacent-item deduplication.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deduplicable

type Deduplicable interface {
	// IsDuplicate returns true if other is considered to be a
	// duplicate of the calling instance.
	IsDuplicate(any) bool
}

Deduplicable is an interface that records should implement if the history should perform their deduplication. An example would be deduplicating records whose only difference is their timestamp.

type History

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

History is a data structure that allows you to keep some number of records.

func New

func New(length int) *History

New returns a History with the specified maximum length.

func (*History) Add

func (history *History) Add(record any)

Add a new record in a threadsafe manner. If record implements Deduplicable, and IsDuplicate returns true when called on the last previously added record, it will not be added.

func (*History) Latest

func (history *History) Latest() any

Latest returns the record most recently passed to Add(), regardless of whether it was actually added or dropped as a duplicate.

func (*History) Records

func (history *History) Records() []any

Records returns the kept records in reverse chronological order in a threadsafe manner.

Jump to

Keyboard shortcuts

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