Documentation
¶
Index ¶
Constants ¶
const ( // MatchNone is a placeholder, typically used for leaf nodes. MatchNone = MatchType(iota) // MatchString represents a string type. MatchString // MatchInteger represents an integer type. MatchInteger // MatchIntegerInterval represents an integer interval type. MatchIntegerInterval // MatchNumberInterval represents a floating-point number interval type. MatchNumberInterval // MatchRegexp represents a regular expression type. MatchRegexp // NumberOfMatchTypes indicates the total number of defined match types. NumberOfMatchTypes = int(iota) )
Variables ¶
This section is empty.
Functions ¶
func Float64Ptr ¶
Float64Ptr is a helper function to create a pointer to a float64 value.
Types ¶
type AddRuleOptionFunc ¶ added in v0.3.0
type AddRuleOptionFunc func(addRuleOptions) addRuleOptions
AddRuleOptionFunc defines a function type for configuring the AddRule operation.
func TreatEmptyPatternAsAny ¶ added in v0.3.0
func TreatEmptyPatternAsAny() AddRuleOptionFunc
TreatEmptyPatternAsAny configures the AddRule operation to treat empty patterns as wildcards.
type IntegerInterval ¶
type IntegerInterval struct {
Min *int64 `json:"min"`
MinIsExcluded bool `json:"min_is_excluded"`
Max *int64 `json:"max"`
MaxIsExcluded bool `json:"max_is_excluded"`
}
IntegerInterval represents a closed, open, or half-open interval for integers.
func (IntegerInterval) Contains ¶
func (i IntegerInterval) Contains(x int64) bool
Contains checks if the given integer `x` falls within the interval.
func (IntegerInterval) Equals ¶
func (i IntegerInterval) Equals(other IntegerInterval) bool
Equals checks if two IntegerIntervals are equal.
type MatchKey ¶
type MatchKey struct {
Type MatchType `json:"type"`
// String for MatchString, MatchRegexp types.
String string `json:"string"`
// Integer for MatchInteger, MatchIntegerInterval types.
Integer int64 `json:"integer"`
// Number for MatchNumberInterval type.
Number float64 `json:"number"`
}
MatchKey represents a single key to search within the MatchTree. It specifies the type and the value for that key.
type MatchPattern ¶
type MatchPattern struct {
Type MatchType `json:"type"`
// IsAny indicates if this pattern matches any value for its type.
IsAny bool `json:"is_any"`
// IsInverse indicates if this pattern matches any value NOT in its specified list/intervals.
IsInverse bool `json:"is_inverse"`
// Strings for MatchString type.
Strings []string `json:"strings"`
// Integers for MatchInteger type.
Integers []int64 `json:"integers"`
// IntegerIntervals for MatchIntegerInterval type.
IntegerIntervals []IntegerInterval `json:"integer_intervals"`
// NumberIntervals for MatchNumberInterval type.
NumberIntervals []NumberInterval `json:"number_intervals"`
// Regexp for MatchRegexp type.
Regexp string `json:"regexp"`
// contains filtered or unexported fields
}
MatchPattern defines a single pattern within a MatchRule. It can be an 'any' pattern, an 'inverse' pattern, or a specific value/interval pattern.
func (*MatchPattern) IsEmpty ¶ added in v0.3.0
func (p *MatchPattern) IsEmpty() bool
IsEmpty checks if the MatchPattern is empty (i.e., has no specific matching criteria).
type MatchRule ¶
type MatchRule[T any] struct { Patterns []MatchPattern `json:"patterns"` Value T `json:"value"` Priority int `json:"priority"` }
MatchRule represents a single rule to be added to the MatchTree. It consists of a sequence of patterns, a value to associate, and a priority.
type MatchTree ¶
type MatchTree[T any] struct { // contains filtered or unexported fields }
MatchTree is a generic tree structure for efficient pattern matching. It allows defining rules with various pattern types and searching for matching values based on keys.
func NewMatchTree ¶
NewMatchTree creates a new MatchTree with the specified sequence of MatchTypes. The order of types matters and defines the structure of the tree.
func (*MatchTree[T]) AddRule ¶
func (t *MatchTree[T]) AddRule(rule MatchRule[T], optionFuncs ...AddRuleOptionFunc) error
AddRule adds a new MatchRule to the MatchTree. It returns an error if the rule's patterns do not match the tree's defined types.
type MatchType ¶
type MatchType int
MatchType defines the type of data a pattern or key represents.
func ParseMatchType ¶
ParseMatchType parses a string into a MatchType.
func (MatchType) MarshalJSON ¶
MarshalJSON marshals the MatchType to its string representation.
func (*MatchType) UnmarshalJSON ¶
UnmarshalJSON unmarshals a JSON string into a MatchType.
type NumberInterval ¶
type NumberInterval struct {
Min *float64 `json:"min"`
MinIsExcluded bool `json:"min_is_excluded"`
Max *float64 `json:"max"`
MaxIsExcluded bool `json:"max_is_excluded"`
}
NumberInterval represents a closed, open, or half-open interval for floating-point numbers.
func (NumberInterval) Contains ¶
func (i NumberInterval) Contains(x float64) bool
Contains checks if the given floating-point number `x` falls within the interval, considering floating-point precision.
func (NumberInterval) Equals ¶
func (i NumberInterval) Equals(other NumberInterval) bool
Equals checks if two NumberIntervals are equal, considering floating-point precision.