counter

package
v1.14.2 Latest Latest
Warning

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

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

Documentation

Overview

Package counter provides generic reference counter objects

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter added in v1.14.0

type Counter[T comparable] map[T]int

Counter tracks references for comparable .

No thread safety is provided within this structure, the user is expected to handle concurrent access to this structure if it is used from multiple threads.

func (Counter[T]) Add added in v1.14.0

func (c Counter[T]) Add(key T) bool

Add increments the reference count for the specified key.

func (Counter[T]) DeepCopy added in v1.14.0

func (c Counter[T]) DeepCopy() Counter[T]

DeepCopy makes a new copy of the received Counter.

func (Counter[T]) Delete added in v1.14.0

func (c Counter[T]) Delete(key T) bool

Delete decrements the reference count for the specified key.

type IntCounter

type IntCounter Counter[int]

IntCounter tracks references for integers with an optional limiter.

No threadsafety is provided within this structure, the user is expected to handle concurrent access to this structure if it is used from multiple threads.

func (IntCounter) Add

func (i IntCounter) Add(key int) (changed bool)

Add increments the reference count for the specified integer key.

func (IntCounter) DeepCopy

func (i IntCounter) DeepCopy() IntCounter

DeepCopy makes a new copy of the received IntCounter.

func (IntCounter) Delete

func (i IntCounter) Delete(key int) bool

Delete decrements the reference count for the specified integer key.

func (IntCounter) ToBPFData

func (i IntCounter) ToBPFData() []int

ToBPFData returns the keys as a slice, sorted from high to low.

type PrefixLengthCounter

type PrefixLengthCounter struct {
	lock.RWMutex
	// contains filtered or unexported fields
}

PrefixLengthCounter tracks references to prefix lengths, limited by the maxUniquePrefixes count. Neither of the IPv4 or IPv6 counters nested within may contain more keys than the specified maximum number of unique prefixes.

func DefaultPrefixLengthCounter added in v1.14.0

func DefaultPrefixLengthCounter(maxUniquePrefixes6, maxUniquePrefixes4 int) *PrefixLengthCounter

DefaultPrefixLengthCounter creates a default prefix length counter that already counts the minimum and maximum prefix lengths for IP hosts and default routes (ie, /32 and /0). As with NewPrefixLengthCounter, inesrtions are limited to the specified maximum number of unique prefix lengths.

func NewPrefixLengthCounter

func NewPrefixLengthCounter(maxUniquePrefixes6, maxUniquePrefixes4 int) *PrefixLengthCounter

NewPrefixLengthCounter returns a new PrefixLengthCounter which limits insertions to the specified maximum number of unique prefix lengths.

func (*PrefixLengthCounter) Add

func (p *PrefixLengthCounter) Add(prefixes []netip.Prefix) (bool, error)

Add increments references to prefix lengths for the specified IPNets to the counter. If the maximum number of unique prefix lengths would be exceeded, returns an error.

Returns true if adding these prefixes results in an increase in the total number of unique prefix lengths in the counter.

func (*PrefixLengthCounter) Delete

func (p *PrefixLengthCounter) Delete(prefixes []netip.Prefix) (changed bool)

Delete reduces references to prefix lengths in the the specified IPNets from the counter. Returns true if removing references to these prefix lengths would result in a decrese in the total number of unique prefix lengths in the counter.

func (*PrefixLengthCounter) ToBPFData

func (p *PrefixLengthCounter) ToBPFData() (s6, s4 []int)

ToBPFData converts the counter into a set of prefix lengths that the BPF datapath can use for LPM lookup.

type StringCounter added in v1.14.0

type StringCounter = Counter[string]

Deprecated. Use Counter[string] instead.

Jump to

Keyboard shortcuts

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