sitesmatrix

package
v0.154.1 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Dimensions in the Hugo build matrix.
	// These can be used as indices into the Vector type.
	Language int = iota
	Version
	Role
)

Variables

This section is empty.

Functions

func DimensionName

func DimensionName(d int) string

func ParseDimension

func ParseDimension(s string) (int, error)

Types

type Bools

type Bools [3]bool

Bools holds boolean values for each dimension in the Hugo build matrix.

func (Bools) IsZero

func (d Bools) IsZero() bool

func (Bools) Language

func (d Bools) Language() bool

func (Bools) Role

func (d Bools) Role() bool

func (Bools) Version

func (d Bools) Version() bool

type CommonSitestMatrix

type CommonSitestMatrix struct {
	DefaultSite VectorStore
}

type ConfiguredDimension

type ConfiguredDimension interface {
	predicate.IndexMatcher
	IndexDefault() int
	ResolveIndex(string) int
	ResolveName(int) string
	ForEachIndex() iter.Seq[int]
	Len() int
}

type ConfiguredDimensions

type ConfiguredDimensions struct {
	ConfiguredLanguages ConfiguredDimension
	ConfiguredVersions  ConfiguredDimension
	ConfiguredRoles     ConfiguredDimension
	CommonSitesMatrix   CommonSitestMatrix
	// contains filtered or unexported fields
}

ConfiguredDimensions holds the configured dimensions for the site matrix.

func NewTestingDimensions

func NewTestingDimensions(languages, versions, roles []string) *ConfiguredDimensions

NewTestingDimensions creates a new ConfiguredDimensions for testing.

func (*ConfiguredDimensions) GetOrCreateSingleVectorStore

func (c *ConfiguredDimensions) GetOrCreateSingleVectorStore(vec Vector) *IntSets

GetOrCreateSingleVectorStore returns a VectorStore for the given vector.

func (*ConfiguredDimensions) Init

func (c *ConfiguredDimensions) Init() error

func (*ConfiguredDimensions) IsSingleVector

func (c *ConfiguredDimensions) IsSingleVector() bool

func (*ConfiguredDimensions) ResolveNames

func (c *ConfiguredDimensions) ResolveNames(v Vector) types.Strings3

func (*ConfiguredDimensions) ResolveVector

func (c *ConfiguredDimensions) ResolveVector(names types.Strings3) Vector

type Dimension

type Dimension int8

Dimension is a dimension in the Hugo build matrix.

type DimensionInfo

type DimensionInfo interface {
	// The name. This corresponds to the key in the config, e.g. "en", "v1.2.3", "guest".
	Name() string

	// Whether this is the default value for this dimension.
	IsDefault() bool
}

Common information provided by all of language, version and role.

type IntSets

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

IntSets holds the ordered sets of integers for the dimensions, which is used for fast membership testing of files, resources and pages.

var NilStore *IntSets = nil

func (*IntSets) Complement

func (s *IntSets) Complement(ss ...VectorProvider) VectorStore

Complement returns a new VectorStore that contains all vectors in s that are not in any of ss.

func (*IntSets) DifferenceCardinality

func (s *IntSets) DifferenceCardinality(other *IntSets) Vector

func (*IntSets) EqualsVector

func (s *IntSets) EqualsVector(other VectorProvider) bool

func (*IntSets) ForEachVector

func (s *IntSets) ForEachVector(yield func(v Vector) bool) bool

The reason we don't use iter.Seq is https://github.com/golang/go/issues/69015 This is 60% faster and allocation free. The yield function should return false to stop iteration.

func (*IntSets) HasAnyVector

func (s *IntSets) HasAnyVector(v VectorProvider) bool

func (*IntSets) HasLanguage

func (s *IntSets) HasLanguage(lang int) bool

func (*IntSets) HasRole

func (s *IntSets) HasRole(role int) bool

func (*IntSets) HasVector

func (s *IntSets) HasVector(v Vector) bool

HasVector checks if the given vector is contained in the sets.

func (*IntSets) HasVersion

func (s *IntSets) HasVersion(ver int) bool

func (*IntSets) Hash

func (s *IntSets) Hash() (uint64, error)

func (*IntSets) Intersects

func (s *IntSets) Intersects(other *IntSets) bool

func (*IntSets) IsSuperSet

func (s *IntSets) IsSuperSet(other *IntSets) bool

func (*IntSets) KeysSorted

func (s *IntSets) KeysSorted() ([]int, []int, []int)

func (*IntSets) LenVectors

func (s *IntSets) LenVectors() int

LenVectors returns the total number of vectors represented by the IntSets. This is the Cartesian product of the lengths of the individual sets. This will be 0 if s is nil or any of the sets is empty.

func (*IntSets) MustHash

func (s *IntSets) MustHash() uint64

func (*IntSets) String

func (s *IntSets) String() string

func (*IntSets) ToVectorStoreMap

func (s *IntSets) ToVectorStoreMap() *vectorStoreMap

func (*IntSets) VectorSample

func (s *IntSets) VectorSample() Vector

func (*IntSets) Vectors

func (s *IntSets) Vectors() []Vector

func (*IntSets) WithLanguageIndices

func (s *IntSets) WithLanguageIndices(i int) VectorStore

WithLanguageIndices replaces the current language set with a single language index.

type IntSetsBuilder

type IntSetsBuilder struct {

	// Set when a Glob (e.g. "en") filter is provided but no matches are found.
	GlobFilterMisses Bools
	// contains filtered or unexported fields
}

func NewIntSetsBuilder

func NewIntSetsBuilder(cfg *ConfiguredDimensions) *IntSetsBuilder

func (*IntSetsBuilder) Build

func (b *IntSetsBuilder) Build() *IntSets

func (*IntSetsBuilder) WithAllIfNotSet

func (s *IntSetsBuilder) WithAllIfNotSet() *IntSetsBuilder

func (*IntSetsBuilder) WithConfig

func (b *IntSetsBuilder) WithConfig(cfg IntSetsConfig) *IntSetsBuilder

func (*IntSetsBuilder) WithDefaultsAndAllLanguagesIfNotSet

func (s *IntSetsBuilder) WithDefaultsAndAllLanguagesIfNotSet() *IntSetsBuilder

func (*IntSetsBuilder) WithDefaultsIfNotSet

func (s *IntSetsBuilder) WithDefaultsIfNotSet() *IntSetsBuilder

func (*IntSetsBuilder) WithDimensionsFromOtherIfNotSet

func (s *IntSetsBuilder) WithDimensionsFromOtherIfNotSet(other VectorIterator) *IntSetsBuilder

func (*IntSetsBuilder) WithLanguageIndices

func (s *IntSetsBuilder) WithLanguageIndices(idxs ...int) *IntSetsBuilder

func (*IntSetsBuilder) WithSets

func (b *IntSetsBuilder) WithSets(languages, versions, roles *maps.OrderedIntSet) *IntSetsBuilder

type IntSetsConfig

type IntSetsConfig struct {
	ApplyDefaults IntSetsConfigApplyDefaults
	Globs         StringSlices
}

type IntSetsConfigApplyDefaults

type IntSetsConfigApplyDefaults int
const (
	IntSetsConfigApplyDefaultsNone IntSetsConfigApplyDefaults = iota
	IntSetsConfigApplyDefaultsIfNotSet
	IntSetsConfigApplyDefaultsAndAllLanguagesIfNotSet
)

type Sites

type Sites struct {
	// Matrix defines what sites to build this content for.
	Matrix StringSlices `mapstructure:"matrix" json:"matrix"`
	// Complements defines what sites to complement with this content.
	Complements StringSlices `mapstructure:"complements" json:"complements"`
}

Sites holds configuration about which sites a file/content/page/resource belongs to.

func (*Sites) Equal

func (s *Sites) Equal(other Sites) bool

func (Sites) IsZero

func (s Sites) IsZero() bool

IsZero returns true if all slices are empty.

func (*Sites) SetFromParamsIfNotSet

func (s *Sites) SetFromParamsIfNotSet(params maps.Params)

type StringSlices

type StringSlices struct {
	Languages []string `mapstructure:"languages" json:"languages"`
	Versions  []string `mapstructure:"versions" json:"versions"`
	Roles     []string `mapstructure:"roles" json:"roles"`
}

StringSlices holds slices of Glob patterns for languages, versions, and roles.

func (StringSlices) Equal

func (d StringSlices) Equal(other StringSlices) bool

func (StringSlices) IsZero

func (d StringSlices) IsZero() bool

func (*StringSlices) SetFromParamsIfNotSet

func (d *StringSlices) SetFromParamsIfNotSet(params maps.Params)

type ToVectorStoreProvider

type ToVectorStoreProvider interface {
	ToVectorStore() VectorStore
}

type Vector

type Vector [3]int

Vector represents a site vector in the Hugo sites matrix from the three dimensions: Language, Version and Role. This is a fixed-size array for performance reasons (for one, it can be used as map key).

func (Vector) Compare

func (v1 Vector) Compare(v2 Vector) int

Compare returns -1 if v1 is less than v2, 0 if they are equal, and 1 if v1 is greater than v2. This adds a implicit weighting to the dimensions, where the first dimension is the most important, but this is just used for sorting to get stable output.

func (Vector) Distance

func (v1 Vector) Distance(v2 Vector) int

Distance returns the distance between v1 and v2 using the first dimension that is different.

func (Vector) EqualsVector

func (v1 Vector) EqualsVector(other VectorProvider) bool

func (Vector) ForEachVector

func (v1 Vector) ForEachVector(yield func(v Vector) bool) bool

func (Vector) HasAnyVector

func (v1 Vector) HasAnyVector(vp VectorProvider) bool

func (Vector) HasVector

func (v1 Vector) HasVector(v2 Vector) bool

func (Vector) IsFirst

func (v1 Vector) IsFirst() bool

IsFirst returns true if this is the first vector in the matrix, i.e. all dimensions are 0.

func (Vector) Language

func (v1 Vector) Language() int

Language returns the language dimension.

func (Vector) LenVectors

func (v1 Vector) LenVectors() int

func (Vector) Role

func (v1 Vector) Role() int

Role returns the role dimension.

func (Vector) VectorSample

func (v1 Vector) VectorSample() Vector

func (Vector) Version

func (v1 Vector) Version() int

Version returns the version dimension.

func (Vector) Weight

func (v1 Vector) Weight() int

type VectorIterator

type VectorIterator interface {
	// ForEachVector iterates over all vectors in the provider.
	// It returns false if the iteration was stopped early.
	ForEachVector(func(v Vector) bool) bool

	// LenVectors returns the number of vectors in the provider.
	LenVectors() int

	// VectorSample returns one of the vectors in the provider, usually the first or the only one.
	// This will panic if the provider is empty.
	VectorSample() Vector
}

type VectorProvider

type VectorProvider interface {
	VectorIterator
	// HasVector returns true if the given vector is contained in the provider.
	// Used for membership testing of files, resources and pages.
	HasVector(HasAnyVectorv Vector) bool

	// HasAnyVector returns true if any of the vectors in the provider matches any of the vectors in v.
	HasAnyVector(v VectorProvider) bool

	// Equals returns true if this provider is equal to the other provider.
	EqualsVector(other VectorProvider) bool
}

type VectorStore

type VectorStore interface {
	VectorProvider
	Complement(...VectorProvider) VectorStore
	WithLanguageIndices(i int) VectorStore
	HasLanguage(lang int) bool
	HasVersion(version int) bool
	HasRole(role int) bool
	MustHash() uint64

	// Used in tests.
	KeysSorted() ([]int, []int, []int)
	Vectors() []Vector
}

func NewWeightedVectorStore

func NewWeightedVectorStore(vs VectorStore, weight int) VectorStore

func VectorIteratorToStore

func VectorIteratorToStore(vi VectorIterator) VectorStore

type Vectors

type Vectors map[Vector]struct{}

func (Vectors) ForEachVector

func (vs Vectors) ForEachVector(yield func(v Vector) bool) bool

func (Vectors) LenVectors

func (vs Vectors) LenVectors() int

func (Vectors) ToVectorStore

func (vs Vectors) ToVectorStore() VectorStore

func (Vectors) VectorSample

func (vs Vectors) VectorSample() Vector

VectorSample returns one of the vectors in the set.