tagset

package
v0.0.0-...-44638ef Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package tagset supports creation and manipulation of sets of tags. It does so in a safe and efficient fashion, supporting:

- consistent hashing of tagsets to recognize commonalities - flexible combination of tagsets from multiple sources - immutability to allow re-use of tagsets

The package otherwise presents a fairly abstract API that allows performance optimizations without changing semantics.

Accumulators

HashlessTagsAccumulator and HashingTagsAccumulator both allow building tagsets bit-by-bit, by appending new tags.

HashedTags

The HashedTags type represents an _immutable_ set of tags and associated hashes. It is the primary data structure used to represent a set of tags.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HashGenerator

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

A HashGenerator generates hashes for tag sets, with the property that the hash is invariant over re-ordering of tags and duplicate tags.

This type holds storage for hash operations that can be re-used between operations. It is not threadsafe and the caller must ensure that an instance's Hash method is not called concurrently.

func NewHashGenerator

func NewHashGenerator() *HashGenerator

NewHashGenerator creates a new HashGenerator

func (*HashGenerator) Hash

Hash calculates the cumulative XOR of all unique tags in the builder. As a side-effect, it sorts and deduplicates the hashes contained in the builder.

type HashedTags

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

HashedTags is an immutable slice of pre-hashed tags.

func NewHashedTagsFromSlice

func NewHashedTagsFromSlice(tags []string) HashedTags

NewHashedTagsFromSlice creates a new instance, re-using tags as the internal slice.

func (HashedTags) Copy

func (h HashedTags) Copy() []string

Copy returns a new slice with the copy of the tags

func (HashedTags) Get

func (h HashedTags) Get() []string

Get returns the internal slice.

NOTE: this returns a mutable reference to data in this immutable data structure. It is still used by pkg/tagger/tagstore, but new uses should not be added.

func (HashedTags) Len

func (h HashedTags) Len() int

Len returns number of tags

func (HashedTags) Slice

func (h HashedTags) Slice(i, j int) HashedTags

Slice returns a shared sub-slice of tags from t.

type HashingTagsAccumulator

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

HashingTagsAccumulator allows to build a slice of tags, including the hashes of each tag.

This type implements TagAccumulator.

func NewHashingTagsAccumulator

func NewHashingTagsAccumulator() *HashingTagsAccumulator

NewHashingTagsAccumulator returns a new empty HashingTagsAccumulator

func NewHashingTagsAccumulatorWithTags

func NewHashingTagsAccumulatorWithTags(tags []string) *HashingTagsAccumulator

NewHashingTagsAccumulatorWithTags return a new HashingTagsAccumulator, initialized with tags.

func (*HashingTagsAccumulator) Append

func (h *HashingTagsAccumulator) Append(tags ...string)

Append appends tags to the builder

func (*HashingTagsAccumulator) AppendHashed

func (h *HashingTagsAccumulator) AppendHashed(src HashedTags)

AppendHashed appends tags and corresponding hashes to the builder

func (HashingTagsAccumulator) Copy

func (h HashingTagsAccumulator) Copy() []string

Copy returns a new slice with the copy of the tags

func (*HashingTagsAccumulator) Dup

Dup returns a complete copy of HashingTagsAccumulator

func (*HashingTagsAccumulator) Get

func (h *HashingTagsAccumulator) Get() []string

Get returns the internal slice

func (*HashingTagsAccumulator) Hashes

func (h *HashingTagsAccumulator) Hashes() []uint64

Hashes returns the internal slice of tag hashes

func (HashingTagsAccumulator) Len

func (h HashingTagsAccumulator) Len() int

Len returns number of tags

func (*HashingTagsAccumulator) Less

func (h *HashingTagsAccumulator) Less(i, j int) bool

Less implements sort.Interface.Less

func (*HashingTagsAccumulator) Reset

func (h *HashingTagsAccumulator) Reset()

Reset resets the size of the builder to 0 without discaring the internal buffer

func (*HashingTagsAccumulator) SortUniq

func (h *HashingTagsAccumulator) SortUniq()

SortUniq sorts and remove duplicate in place

func (*HashingTagsAccumulator) Swap

func (h *HashingTagsAccumulator) Swap(i, j int)

Swap implements sort.Interface.Swap

func (*HashingTagsAccumulator) Truncate

func (h *HashingTagsAccumulator) Truncate(len int)

Truncate retains first n tags in the buffer without discarding the internal buffer

type HashlessTagsAccumulator

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

HashlessTagsAccumulator allows to build a slice of tags, in a context where the hashes for those tags are not useful.

This type implements TagAccumulator.

func NewHashlessTagsAccumulator

func NewHashlessTagsAccumulator() *HashlessTagsAccumulator

NewHashlessTagsAccumulator returns a new empty HashlessTagsAccumulator.

func NewHashlessTagsAccumulatorFromSlice

func NewHashlessTagsAccumulatorFromSlice(data []string) *HashlessTagsAccumulator

NewHashlessTagsAccumulatorFromSlice return a new HashlessTagsAccumulator with the input slice for it's internal buffer.

func (*HashlessTagsAccumulator) Append

func (h *HashlessTagsAccumulator) Append(tags ...string)

Append appends tags to the builder

func (*HashlessTagsAccumulator) AppendHashed

func (h *HashlessTagsAccumulator) AppendHashed(src HashedTags)

AppendHashed appends tags and corresponding hashes to the builder

func (*HashlessTagsAccumulator) Get

func (h *HashlessTagsAccumulator) Get() []string

Get returns the internal slice

func (*HashlessTagsAccumulator) Reset

func (h *HashlessTagsAccumulator) Reset()

Reset resets the size of the builder to 0 without discaring the internal buffer

func (*HashlessTagsAccumulator) SortUniq

func (h *HashlessTagsAccumulator) SortUniq()

SortUniq sorts and remove duplicate in place

type TagAccumulator

type TagAccumulator interface {
	// Append the given tags to the tag set
	Append(...string)
	// Append the tags contained in the given HashedTags instance to the tag set.
	AppendHashed(HashedTags)
}

A TagAccumulator accumulates tags. The underlying type will provide a means of getting the resulting tag set.

Jump to

Keyboard shortcuts

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