Documentation
¶
Overview ¶
Package sets provides utility functions for common operations on sets and slices. Sets are represented as map[string]struct{} for efficient lookups.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetSplitIndex ¶
GetSplitIndex calculates the index at which to split a slice of a given length into two halves. The first half will be larger if the length is odd.
func Split ¶
func Split(slice OrderedSet) (OrderedSet, OrderedSet)
Split divides a slice into two approximately equal halves.
func SubtractSlices ¶
SubtractSlices returns a new slice containing elements from the 'a' slice that are not present in the 'b' slice. The order of elements in 'a' is preserved.
Types ¶
type OrderedSet ¶
type OrderedSet []string
OrderedSet represents a slice of strings. Note: This is a type alias and does not enforce uniqueness or order at compile time. Functions that return an OrderedSet, like MakeSlice, guarantee the slice is sorted and unique.
func MakeSlice ¶
func MakeSlice(set Set) OrderedSet
MakeSlice converts a Set into a new, sorted slice of strings (an OrderedSet).
type Set ¶
type Set map[string]struct{}
Set represents a collection of unique string values.
func AddInPlace ¶
AddInPlace adds all elements from b to a and returns the result.
func Intersection ¶
Intersection returns a new set containing only the elements present in both set a and set b.
func MakeSet ¶
MakeSet converts a slice of strings into a Set for efficient lookups. Duplicates in the slice are removed.
func Subtract ¶
Subtract returns a new set containing elements from set a that are not present in set b.
func SubtractInPlace ¶
Subtract removes all elements in b from a and returns the result.
type SetFormatter ¶
type SetFormatter struct {
// contains filtered or unexported fields
}
SetFormatter provides a lazy, fmt.Stringer-compliant way to format a Set for logging. The conversion to a sorted string only happens when the String() method is called by the logging framework.
func FormatSet ¶
func FormatSet(set Set) SetFormatter
FormatSet returns a SetFormatter that can be used in logging statements. It delays the expensive work of sorting and joining until it's actually needed.
func (SetFormatter) String ¶
func (sf SetFormatter) String() string
String implements the fmt.Stringer interface.