util

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForEachChunk

func ForEachChunk[T any](data []T, chunkSize uint64, handler func(items []T))

ForEachChunk executes the given handler for each chunk of items in the slice.

Types

type BaseSubjectSet

type BaseSubjectSet[T Subject] struct {
	// contains filtered or unexported fields
}

BaseSubjectSet defines a set that tracks accessible subjects. It is generic to allow other implementations to define the kind of tracking information associated with each subject.

NOTE: Unlike a traditional set, unions between wildcards and a concrete subject will result in *both* being present in the set, to maintain the proper set semantics around wildcards.

func NewBaseSubjectSet

func NewBaseSubjectSet[T Subject](
	constructor func(subjectID string, excludedSubjectIDs []string, sources ...T) T,
	combiner func(existing T, added T) T,
) BaseSubjectSet[T]

NewBaseSubjectSet creates a new base subject set for use underneath well-typed implementation.

The constructor function is a function that returns a new instancre of type T for a particular subject ID. The combiner function is optional, and if given, is used to combine existing elements in the set into a new element. This is typically used in debug packages for tracking of additional metadata.

func (BaseSubjectSet[T]) Add

func (bss BaseSubjectSet[T]) Add(foundSubject T) bool

Add adds the found subject to the set. This is equivalent to a Union operation between the existing set of subjects and a set containing the single subject.

func (BaseSubjectSet[T]) AsSlice

func (bss BaseSubjectSet[T]) AsSlice() []T

AsSlice returns the contents of the subject set as a slice of found subjects.

func (BaseSubjectSet[T]) Clone

func (bss BaseSubjectSet[T]) Clone() BaseSubjectSet[T]

Clone returns a clone of this subject set. Note that this is a shallow clone. NOTE: Should only be used when performance is not a concern.

func (BaseSubjectSet[T]) Get

func (bss BaseSubjectSet[T]) Get(id string) (T, bool)

Get returns the found subject with the given ID in the set, if any.

func (BaseSubjectSet[T]) IntersectionDifference

func (bss BaseSubjectSet[T]) IntersectionDifference(other BaseSubjectSet[T])

IntersectionDifference performs an intersection between this set and the other set, modifying this set in place.

func (BaseSubjectSet[T]) IsEmpty

func (bss BaseSubjectSet[T]) IsEmpty() bool

IsEmpty returns whether the subject set is empty.

func (BaseSubjectSet[T]) Subtract

func (bss BaseSubjectSet[T]) Subtract(foundSubject T)

Subtract subtracts the given subject found the set.

func (BaseSubjectSet[T]) SubtractAll

func (bss BaseSubjectSet[T]) SubtractAll(other BaseSubjectSet[T])

SubtractAll subtracts the other set of subjects from this set of subtracts, modifying this set in place.

func (BaseSubjectSet[T]) UnionWith

func (bss BaseSubjectSet[T]) UnionWith(foundSubjects []T)

UnionWith adds the given subjects to this set, via a union call.

func (BaseSubjectSet[T]) UnionWithSet

func (bss BaseSubjectSet[T]) UnionWithSet(other BaseSubjectSet[T])

UnionWithSet performs a union operation between this set and the other set, modifying this set in place.

func (BaseSubjectSet[T]) UnsafeRemoveExact

func (bss BaseSubjectSet[T]) UnsafeRemoveExact(foundSubject T)

UnsafeRemoveExact removes the *exact* matching subject, with no wildcard handling. This should ONLY be used for testing.

type MultiMap added in v1.13.0

type MultiMap[T comparable, Q any] struct {
	// contains filtered or unexported fields
}

func NewMultiMap added in v1.13.0

func NewMultiMap[T comparable, Q any]() *MultiMap[T, Q]

func (*MultiMap[T, Q]) Add added in v1.13.0

func (mm *MultiMap[T, Q]) Add(key T, item Q)

func (*MultiMap[T, Q]) Get added in v1.13.0

func (mm *MultiMap[T, Q]) Get(key T) []Q

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

Set implements a very basic generic set.

func NewSet

func NewSet[T comparable](items ...T) *Set[T]

NewSet returns a new set.

func (*Set[T]) Add

func (s *Set[T]) Add(value T) bool

Add adds the given value to the set and returns true. If the value is already present, returns false.

func (*Set[T]) AsSlice

func (s *Set[T]) AsSlice() []T

AsSlice returns the set as a slice of values.

func (*Set[T]) Copy added in v1.14.0

func (s *Set[T]) Copy() *Set[T]

Copy returns a copy of this set.

func (*Set[T]) Extend

func (s *Set[T]) Extend(values []T)

Extend adds all the values to the set.

func (*Set[T]) ForEach added in v1.14.0

func (s *Set[T]) ForEach(callback func(value T) error) error

ForEach executes the callback for each item in the set until an error is encountered.

func (*Set[T]) Has

func (s *Set[T]) Has(value T) bool

Has returns true if the set contains the given value.

func (*Set[T]) Intersect added in v1.14.0

func (s *Set[T]) Intersect(other *Set[T]) *Set[T]

Intersect removes any values from this set that are not shared with the other set, returning a new set.

func (*Set[T]) IntersectionDifference

func (s *Set[T]) IntersectionDifference(other *Set[T]) *Set[T]

IntersectionDifference removes any values from this set that are not shared with the other set. Returns the same set.

func (*Set[T]) IsEmpty

func (s *Set[T]) IsEmpty() bool

IsEmpty returns true if the set is empty.

func (*Set[T]) Len added in v1.14.0

func (s *Set[T]) Len() int

Len returns the length of the set.

func (*Set[T]) Remove

func (s *Set[T]) Remove(value T) bool

Remove removes the value from the set, returning whether the element was present when the call was made.

func (*Set[T]) RemoveAll

func (s *Set[T]) RemoveAll(other *Set[T])

RemoveAll removes all values from this set found in the other set.

func (*Set[T]) Subtract

func (s *Set[T]) Subtract(other *Set[T]) *Set[T]

Subtract subtracts the other set from this set, returning a new set.

type StringSetWrapper added in v1.14.0

type StringSetWrapper struct {
	StrSet *Set[string]
}

StringSetWrapper wraps a set of strings and provides marshalling for zerolog.

func StringSet added in v1.14.0

func StringSet(set *Set[string]) StringSetWrapper

StringSet wraps a Set of strings and provides automatic log marshalling.

func (StringSetWrapper) MarshalZerologObject added in v1.14.0

func (s StringSetWrapper) MarshalZerologObject(e *zerolog.Event)

MarshalZerologObject implements zerolog object marshalling.

type Subject

type Subject interface {
	// GetSubjectId returns the ID of the subject. For wildcards, this should be `*`.
	GetSubjectId() string

	// GetExcludedSubjectIds returns the list of subject IDs excluded. Should only have values
	// for wildcards.
	GetExcludedSubjectIds() []string
}

Subject is a subject that can be placed into a BaseSubjectSet.

type SubjectSet

type SubjectSet struct {
	BaseSubjectSet[*v1.FoundSubject]
}

SubjectSet defines a set that tracks accessible subjects.

NOTE: Unlike a traditional set, unions between wildcards and a concrete subject will result in *both* being present in the set, to maintain the proper set semantics around wildcards.

func NewSubjectSet

func NewSubjectSet() SubjectSet

NewSubjectSet creates and returns a new subject set.

func (SubjectSet) IntersectionDifference

func (ss SubjectSet) IntersectionDifference(other SubjectSet)

func (SubjectSet) SubtractAll

func (ss SubjectSet) SubtractAll(other SubjectSet)

func (SubjectSet) UnionWithSet

func (ss SubjectSet) UnionWithSet(other SubjectSet)

Jump to

Keyboard shortcuts

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