Documentation
¶
Index ¶
- type Dict
- func (d *Dict[K, V]) Clear()
- func (d *Dict[K, V]) Contains(key K) bool
- func (d *Dict[K, V]) Copy() *Dict[K, V]
- func (d *Dict[K, V]) Equal(other *Dict[K, V]) bool
- func (d *Dict[K, V]) Get(key K) (V, error)
- func (d *Dict[K, V]) Items() []Pair[K, V]
- func (d *Dict[K, V]) Keys() []K
- func (d *Dict[K, V]) Len() int
- func (d *Dict[K, V]) Pop(key K) (V, error)
- func (d *Dict[K, V]) PopItem() (K, V, error)
- func (d *Dict[K, V]) Remove(key K) error
- func (d *Dict[K, V]) Set(key K, value V)
- func (d *Dict[K, V]) SetDefault(key K, defaultValue V) V
- func (d *Dict[K, V]) Update(other *Dict[K, V])
- func (d *Dict[K, V]) Values() []V
- type List
- func (l *List[T]) Append(v T)
- func (l *List[T]) AsSlice() []T
- func (l *List[T]) Clear()
- func (l *List[T]) Concat(other any) *List[T]
- func (l *List[T]) Contains(v T) bool
- func (l *List[T]) Copy() *List[T]
- func (l *List[T]) Count(v T) int
- func (l *List[T]) Extend(elems ...T)
- func (l *List[T]) Get(i int) (T, error)
- func (l *List[T]) Index(v T) (int, error)
- func (l *List[T]) Insert(i int, v T) error
- func (l *List[T]) Len() int
- func (l *List[T]) Pop(idxOpt ...int) (T, error)
- func (l *List[T]) Remove(v T) error
- func (l *List[T]) Reverse()
- func (l *List[T]) Set(i int, v T) error
- func (l *List[T]) Slice(start, stop int) *List[T]
- func (l *List[T]) Sort(less func(a, b T) bool) error
- type Pair
- type Set
- func (s *Set[T]) Add(v T)
- func (s *Set[T]) AsSlice() []T
- func (s *Set[T]) Clear()
- func (s *Set[T]) Contains(v T) bool
- func (s *Set[T]) Copy() *Set[T]
- func (s *Set[T]) Difference(other *Set[T]) *Set[T]
- func (s *Set[T]) DifferenceWith(other *Set[T]) *Set[T]
- func (s *Set[T]) Discard(v T)
- func (s *Set[T]) Equal(other *Set[T]) bool
- func (s *Set[T]) Intersection(other *Set[T]) *Set[T]
- func (s *Set[T]) IntersectionWith(other *Set[T]) *Set[T]
- func (s *Set[T]) IsDisjoint(other *Set[T]) bool
- func (s *Set[T]) IsSubset(other *Set[T]) bool
- func (s *Set[T]) IsSuperset(other *Set[T]) bool
- func (s *Set[T]) Len() int
- func (s *Set[T]) Pop() (T, error)
- func (s *Set[T]) Remove(v T) error
- func (s *Set[T]) SymmetricDifference(other *Set[T]) *Set[T]
- func (s *Set[T]) SymmetricDifferenceWith(other *Set[T]) *Set[T]
- func (s *Set[T]) Union(other *Set[T]) *Set[T]
- func (s *Set[T]) UnionWith(other *Set[T]) *Set[T]
- func (s *Set[T]) Update(elems ...T)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dict ¶
type Dict[K comparable, V any] struct { // contains filtered or unexported fields }
Dict is a Python-like generic dictionary implementation.
func NewDict ¶
func NewDict[K comparable, V any](cap int) *Dict[K, V]
NewDict creates an empty Dict with optional capacity.
func NewDictFromMap ¶
func NewDictFromMap[K comparable, V any](src map[K]V) *Dict[K, V]
NewDictFromMap constructs a Dict by copying entries from provided map.
func (*Dict[K, V]) Keys ¶
func (d *Dict[K, V]) Keys() []K
Keys returns a slice with all keys (iteration order unspecified).
func (*Dict[K, V]) PopItem ¶
PopItem removes and returns an arbitrary key/value pair. Error if empty.
func (*Dict[K, V]) SetDefault ¶
func (d *Dict[K, V]) SetDefault(key K, defaultValue V) V
SetDefault returns the value for key if present; otherwise sets key to defaultValue and returns it.
type List ¶
type List[T any] struct { // contains filtered or unexported fields }
List is a Python-like generic list implementation. It wraps a slice and provides common list methods (append, extend, insert, remove, pop, etc.).
func ListFromSlice ¶
ListFromSlice wraps an existing slice (makes a copy) into a List.
func (*List[T]) AsSlice ¶
func (l *List[T]) AsSlice() []T
AsSlice returns a copy of the underlying slice.
func (*List[T]) Get ¶
Get returns element at index i. Supports negative indices. Returns error if out of range.
func (*List[T]) Index ¶
Index returns the index of the first occurrence of v. Returns error if not found.
func (*List[T]) Insert ¶
Insert inserts element at index i (before current element at i). Supports negative indices.
func (*List[T]) Pop ¶
Pop removes and returns element at index i (default last). Supports negative indices.
type Pair ¶
type Pair[K comparable, V any] struct { Key K Value V }
Pair represents a key/value pair returned by Items().
type Set ¶
type Set[T comparable] struct { // contains filtered or unexported fields }
Set is a Python-like generic set implementation. It requires element type T to be comparable. Internally backed by map[T]struct{} for O(1) membership operations.
func NewSet ¶
func NewSet[T comparable](elems ...T) *Set[T]
NewSet creates a new Set with optional initial elements.
func SetFromSlice ¶
func SetFromSlice[T comparable](s []T) *Set[T]
SetFromSlice creates a Set from a slice (duplicates removed).
func (*Set[T]) AsSlice ¶
func (s *Set[T]) AsSlice() []T
AsSlice returns elements as a slice (iteration order is unspecified).
func (*Set[T]) Difference ¶
Difference returns a new set with elements in s that are not in other.
func (*Set[T]) DifferenceWith ¶
DifferenceWith mutates s to remove any elements present in other.
func (*Set[T]) Discard ¶
func (s *Set[T]) Discard(v T)
Discard deletes element if present; no error if missing.
func (*Set[T]) Intersection ¶
Intersection returns a new set with elements common to s and other.
func (*Set[T]) IntersectionWith ¶
IntersectionWith mutates s to keep only elements present in other.
func (*Set[T]) IsDisjoint ¶
IsDisjoint returns true if s has no elements in common with other.
func (*Set[T]) IsSuperset ¶
IsSuperset returns true if s is a superset of other.
func (*Set[T]) SymmetricDifference ¶
SymmetricDifference returns elements in either s or other but not both.
func (*Set[T]) SymmetricDifferenceWith ¶
SymmetricDifferenceWith mutates s to be the symmetric difference between s and other.