record

package
v1.22.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package record provides Record

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Record

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

Record is an object that keeps track of recorded values. It is safe for concurrent access, the zero value is ready to use.

Re-use of the Record is possible (using the Reset method), however the implementation is internally optimized when writes happen only once.

A Record must not be copied after first use.

Example
r := Record{}

// record a value using the Record() method
fmt.Println(r.Record("first"))
fmt.Println(r.Record("first"))

// check if a value has been recorded using .Recorded()
fmt.Println(r.Recorded("second"))
r.Record("second")
fmt.Println(r.Recorded("second"))

// Reset all recorded values using .Reset()
r.Reset()
fmt.Println(r.Recorded("first"))
fmt.Println(r.Recorded("second"))
Output:

false
true
false
true
false
false

func (*Record) Record

func (r *Record) Record(v any) (recorded bool)

Record records and marks the value v as having been visited.

When value has been recorded before, returns a true. Otherwise returns false.

Record is an atomic operation and can be safely called concurrently.

func (*Record) Recorded

func (r *Record) Recorded(v any) (visited bool)

Recorded checks and returns if the value v has been recorded.

Recorded is an atomic operation and can be safely called concurrently.

func (*Record) Reset

func (r *Record) Reset()

Reset clears all recorded values from this Record, resetting it to an empty state.

Reset is not safe for concurrent usage; no reads or writes should happen concurrently with a reset.

Jump to

Keyboard shortcuts

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