container

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2025 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmptySliceIfNil added in v0.17.2

func EmptySliceIfNil[T any](src []T) (dst []T)

EmptySliceIfNil checks if the given slice is nil. If it is, it returns an empty slice of the same type. Otherwise, it returns the original slice.

func InSlice

func InSlice[T comparable](v T, items []T) bool

InSlice checks if the target element exists in the given slice.

Types

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

Set implements a generic collection of unique elements with type safety. The zero value is not usable, always create instances via NewSet constructor. This implementation is not thread-safe and requires external synchronization when used in concurrent environments.

func NewSet

func NewSet[T comparable](capacity int, elements ...T) *Set[T]

NewSet constructs a Set instance with optional initial capacity and elements.

func (*Set[T]) Add

func (set *Set[T]) Add(elements ...T) *Set[T]

Add inserts one or multiple elements into the set.

func (*Set[T]) Contains

func (set *Set[T]) Contains(element T) bool

Contains checks membership of an element in the set.

func (*Set[T]) Elements

func (set *Set[T]) Elements() []T

Elements returns all set members as a new slice.

func (*Set[T]) IsEmpty

func (set *Set[T]) IsEmpty() bool

IsEmpty checks for an empty set condition.

func (*Set[T]) Length

func (set *Set[T]) Length() int

Length returns the cardinality (element count) of the set.

func (*Set[T]) Remove

func (set *Set[T]) Remove(elements ...T) *Set[T]

Remove deletes specified elements from the set.

Jump to

Keyboard shortcuts

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