collection

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToSlice

func ToSlice[T comparable](s Set[T]) ([]T, error)

Slice converts a Set of type T into a slice of type []T. It iterates over the elements of the set and appends them to a slice. The resulting slice contains all the elements from the set in an arbitrary order.

Parameters:

s: A Set[T] from which to create the slice.

Returns:

A slice of type []T containing all elements from the input set.

Types

type AnySeries

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

AnySeries is a generic series for any values with null support.

func NewAnySeries

func NewAnySeries(capacity int) *AnySeries

NewAnySeries creates a new empty AnySeries with optional capacity.

func NewAnySeriesFromData

func NewAnySeriesFromData(data []any, mask []bool) (*AnySeries, error)

NewAnySeriesFromData creates an AnySeries from values and mask.

func (*AnySeries) Append

func (s *AnySeries) Append(v any) error

func (*AnySeries) AppendNull

func (s *AnySeries) AppendNull()

func (*AnySeries) At

func (s *AnySeries) At(i int) (any, error)

func (*AnySeries) DType

func (s *AnySeries) DType() reflect.Type

func (*AnySeries) IsNull

func (s *AnySeries) IsNull(i int) bool

func (*AnySeries) Len

func (s *AnySeries) Len() int

func (*AnySeries) MaskCopy

func (s *AnySeries) MaskCopy() []bool

func (*AnySeries) NullCount

func (s *AnySeries) NullCount() int

func (*AnySeries) Set

func (s *AnySeries) Set(i int, v any) error

func (*AnySeries) SetNull

func (s *AnySeries) SetNull(i int) error

func (*AnySeries) Slice

func (s *AnySeries) Slice(start, end int) (Series, error)

func (*AnySeries) ValuesCopy

func (s *AnySeries) ValuesCopy() []any

type BoolSeries

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

BoolSeries is a high-performance series for bool values with null support.

func NewBoolSeries

func NewBoolSeries(capacity int) *BoolSeries

NewBoolSeries creates a new empty BoolSeries with optional capacity.

func NewBoolSeriesFromData

func NewBoolSeriesFromData(data []bool, mask []bool) (*BoolSeries, error)

NewBoolSeriesFromData creates a BoolSeries from values and mask.

func (*BoolSeries) Append

func (s *BoolSeries) Append(v any) error

func (*BoolSeries) AppendNull

func (s *BoolSeries) AppendNull()

func (*BoolSeries) At

func (s *BoolSeries) At(i int) (any, error)

func (*BoolSeries) DType

func (s *BoolSeries) DType() reflect.Type

func (*BoolSeries) IsNull

func (s *BoolSeries) IsNull(i int) bool

func (*BoolSeries) Len

func (s *BoolSeries) Len() int

func (*BoolSeries) MaskCopy

func (s *BoolSeries) MaskCopy() []bool

func (*BoolSeries) NullCount

func (s *BoolSeries) NullCount() int

func (*BoolSeries) Set

func (s *BoolSeries) Set(i int, v any) error

func (*BoolSeries) SetNull

func (s *BoolSeries) SetNull(i int) error

func (*BoolSeries) Slice

func (s *BoolSeries) Slice(start, end int) (Series, error)

func (*BoolSeries) ValuesCopy

func (s *BoolSeries) ValuesCopy() []any

type FilterFunc

type FilterFunc[T any] func(v T) bool

FilterFunc defines a function type that returns true if a value should be included in filtered results.

type Float64Series

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

Float64Series is a high-performance series for float64 values with null support.

func NewFloat64Series

func NewFloat64Series(capacity int) *Float64Series

NewFloat64Series creates a new empty Float64Series with optional capacity.

func NewFloat64SeriesFromData

func NewFloat64SeriesFromData(data []float64, mask []bool) (*Float64Series, error)

NewFloat64SeriesFromData creates a Float64Series from values and mask. If mask is nil, all values are treated as non-null.

func (*Float64Series) Append

func (s *Float64Series) Append(v any) error

func (*Float64Series) AppendNull

func (s *Float64Series) AppendNull()

func (*Float64Series) At

func (s *Float64Series) At(i int) (any, error)

func (*Float64Series) DType

func (s *Float64Series) DType() reflect.Type

func (*Float64Series) Float64Value

func (s *Float64Series) Float64Value(i int) (float64, error)

Float64Value returns the raw float64 value at index i (ignores null mask).

func (*Float64Series) Float64Values

func (s *Float64Series) Float64Values() []float64

Float64Values returns a copy of the raw float64 data slice.

func (*Float64Series) IsNull

func (s *Float64Series) IsNull(i int) bool

func (*Float64Series) Len

func (s *Float64Series) Len() int

func (*Float64Series) MaskCopy

func (s *Float64Series) MaskCopy() []bool

func (*Float64Series) NullCount

func (s *Float64Series) NullCount() int

func (*Float64Series) Set

func (s *Float64Series) Set(i int, v any) error

func (*Float64Series) SetNull

func (s *Float64Series) SetNull(i int) error

func (*Float64Series) Slice

func (s *Float64Series) Slice(start, end int) (Series, error)

func (*Float64Series) ValuesCopy

func (s *Float64Series) ValuesCopy() []any

type Int64Series

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

Int64Series is a high-performance series for int64 values with null support.

func NewInt64Series

func NewInt64Series(capacity int) *Int64Series

NewInt64Series creates a new empty Int64Series with optional capacity.

func NewInt64SeriesFromData

func NewInt64SeriesFromData(data []int64, mask []bool) (*Int64Series, error)

NewInt64SeriesFromData creates an Int64Series from values and mask.

func (*Int64Series) Append

func (s *Int64Series) Append(v any) error

func (*Int64Series) AppendNull

func (s *Int64Series) AppendNull()

func (*Int64Series) At

func (s *Int64Series) At(i int) (any, error)

func (*Int64Series) DType

func (s *Int64Series) DType() reflect.Type

func (*Int64Series) Int64Value

func (s *Int64Series) Int64Value(i int) (int64, error)

Int64Value returns the raw int64 value at index i (ignores null mask).

func (*Int64Series) Int64Values

func (s *Int64Series) Int64Values() []int64

Int64Values returns a copy of the raw int64 data slice.

func (*Int64Series) IsNull

func (s *Int64Series) IsNull(i int) bool

func (*Int64Series) Len

func (s *Int64Series) Len() int

func (*Int64Series) MaskCopy

func (s *Int64Series) MaskCopy() []bool

func (*Int64Series) NullCount

func (s *Int64Series) NullCount() int

func (*Int64Series) Set

func (s *Int64Series) Set(i int, v any) error

func (*Int64Series) SetNull

func (s *Int64Series) SetNull(i int) error

func (*Int64Series) Slice

func (s *Int64Series) Slice(start, end int) (Series, error)

func (*Int64Series) ValuesCopy

func (s *Int64Series) ValuesCopy() []any

type Series

type Series interface {
	// Len returns the number of elements in the series.
	Len() int

	// DType returns the reflect.Type of the elements in the series.
	DType() reflect.Type

	// At returns the value at index i. Returns nil if the value is null.
	At(i int) (any, error)

	// IsNull returns true if the value at index i is null.
	IsNull(i int) bool

	// NullCount returns the number of null values in the series.
	NullCount() int

	// Set sets the value at index i. Use nil to set a null value.
	Set(i int, v any) error

	// SetNull sets the value at index i to null.
	SetNull(i int) error

	// Append adds a value to the end of the series. Use nil to append a null value.
	Append(v any) error

	// AppendNull appends a null value to the series.
	AppendNull()

	// ValuesCopy returns a shallow copy of the underlying data as []any.
	// Null values are represented as nil.
	ValuesCopy() []any

	// MaskCopy returns a copy of the null mask.
	MaskCopy() []bool

	// Slice returns a new Series containing elements from start (inclusive) to end (exclusive).
	Slice(start, end int) (Series, error)
}

Series is the interface for all typed series implementations. Each implementation stores data in a strongly-typed slice with a boolean mask for null values.

func NewSeriesOfType

func NewSeriesOfType(t reflect.Type, capacity int) Series

NewSeriesOfType creates a new Series based on the provided reflect.Type.

func NewSeriesOfTypeWithSize

func NewSeriesOfTypeWithSize(t reflect.Type, size int) Series

NewSeriesOfTypeWithSize creates a new Series with the specified size (length).

func NewSeriesWithData

func NewSeriesWithData(t reflect.Type, values []any) (Series, error)

NewSeriesWithData creates a typed series from a slice of any values. It attempts to convert values to the target type.

type Set

type Set[T comparable] map[T]struct{}

Set is an alias for a map representing an unordered collection of unique elements of type T. Type T must be comparable.

func NewSet

func NewSet[T comparable](initialSize ...int) (Set[T], error)

NewSet creates and initializes a new empty Set. If an initial size is provided, the set will be pre-allocated with that size. The initial size must be a non-negative integer.

func ToSet

func ToSet[T comparable](slice []T) (Set[T], error)

ToSet converts a slice of type []T into a Set of type Set[T]. It iterates over the elements of the slice and adds them to a Set. The resulting Set contains all the elements from the input slice in an arbitrary order.

Parameters:

slice: A slice of type []T from which to create the Set.

Returns:

A Set of type Set[T] containing all elements from the input slice.

func (Set[T]) Add

func (s Set[T]) Add(v T) error

Add inserts a value into the set only if it does not already exist.

func (Set[T]) AddMulti

func (s Set[T]) AddMulti(val ...T) error

AddMulti inserts multiple values into the set only if they do not already exist. It iterates over the provided values and attempts to add each one to the set. If any value already exists in the set, the function returns an error. If all values are successfully added, the function returns nil.

func (Set[T]) Compare

func (s Set[T]) Compare(s2 Set[T]) (bool, any)

Compare checks if two sets are equal by comparing their lengths and ensuring all elements in the first set exist in the second set. It first checks if the lengths of the two sets are equal. If not, it returns false and nil. Then, it iterates over the elements of the first set and checks if each element exists in the second set. If an element does not exist in the second set, it returns false and the non-existent element. If all elements in the first set exist in the second set, it returns true and nil.

Parameters:

s2: The input Set[T] to compare with the current set.

Returns:

A boolean indicating if the sets are equal.
An any value representing the first element that does not exist in the second set if the sets are not equal, or nil if they are equal.

func (Set[T]) Difference

func (s Set[T]) Difference(s2 Set[T]) (Set[T], error)

Difference creates a new Set containing elements that exist in the current set but not in the input set. It iterates over the elements of the current set and checks if they do not exist in the input set. If an element does not exist in the input set, it is added to the resulting set. The resulting Set contains all the elements that are unique to the current set in an arbitrary order.

Parameters:

s2: The input Set[T] to find the difference with the current set.

Returns:

A Set of type Set[T] containing all elements that are unique to the current set.
An error if the operation fails.

func (Set[T]) Filter

func (s Set[T]) Filter(P FilterFunc[T]) (Set[T], error)

Filter applies a filter function to each element of the set and returns a new set containing only the elements that pass the filter. The filter function P is applied to each element of the set. If the function returns true for an element, it is included in the resulting set. If the function returns false, the element is not included. The function returns a new Set containing the filtered elements and an error if the operation fails.

func (Set[T]) Has

func (s Set[T]) Has(v T) bool

Has returns true if the value exists in the set.

func (Set[T]) Intersect

func (s Set[T]) Intersect(s2 Set[T]) (Set[T], error)

Intersect creates a new Set containing elements that exist in both the current set and the input set. It iterates over the elements of the current set and checks if they exist in the input set. If an element exists in both sets, it is added to the resulting set. The resulting Set contains all the elements that are common to both input sets in an arbitrary order.

Parameters:

s2: The input Set[T] to intersect with the current set.

Returns:

A Set of type Set[T] containing all elements that are common to both input sets.
An error if the operation fails.

func (Set[T]) Union

func (s Set[T]) Union(s2 Set[T]) (Set[T], error)

Union creates a new Set containing all elements from both the current set and the input set. It iterates over the elements of both sets and adds them to a new Set, ensuring no duplicates. The resulting Set contains all unique elements from both input sets in an arbitrary order.

Parameters:

s2: The input Set[T] to union with the current set.

Returns:

A Set of type Set[T] containing all unique elements from both input sets.
An error if the operation fails.

type StringSeries

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

StringSeries is a high-performance series for string values with null support.

func NewStringSeries

func NewStringSeries(capacity int) *StringSeries

NewStringSeries creates a new empty StringSeries with optional capacity.

func NewStringSeriesFromData

func NewStringSeriesFromData(data []string, mask []bool) (*StringSeries, error)

NewStringSeriesFromData creates a StringSeries from values and mask.

func (*StringSeries) Append

func (s *StringSeries) Append(v any) error

func (*StringSeries) AppendNull

func (s *StringSeries) AppendNull()

func (*StringSeries) At

func (s *StringSeries) At(i int) (any, error)

func (*StringSeries) DType

func (s *StringSeries) DType() reflect.Type

func (*StringSeries) IsNull

func (s *StringSeries) IsNull(i int) bool

func (*StringSeries) Len

func (s *StringSeries) Len() int

func (*StringSeries) MaskCopy

func (s *StringSeries) MaskCopy() []bool

func (*StringSeries) NullCount

func (s *StringSeries) NullCount() int

func (*StringSeries) Set

func (s *StringSeries) Set(i int, v any) error

func (*StringSeries) SetNull

func (s *StringSeries) SetNull(i int) error

func (*StringSeries) Slice

func (s *StringSeries) Slice(start, end int) (Series, error)

func (*StringSeries) StringValue

func (s *StringSeries) StringValue(i int) (string, error)

StringValue returns the raw string value at index i (ignores null mask).

func (*StringSeries) StringValues

func (s *StringSeries) StringValues() []string

StringValues returns a copy of the raw string data slice.

func (*StringSeries) ValuesCopy

func (s *StringSeries) ValuesCopy() []any

Jump to

Keyboard shortcuts

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