collections

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 2 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForeachSlice

func ForeachSlice[T any](f func(index int, value T), slices ...*Slice[T])

func GoSliceJoin

func GoSliceJoin[T any](slices ...[]T) []T

func SliceSetEqual

func SliceSetEqual[T comparable](set1, set2 []T) bool

func SliceSetIntersection

func SliceSetIntersection[T comparable](set1, set2 []T) []T

func SliceSetIntersectionUncomparable

func SliceSetIntersectionUncomparable[T any](set1, set2 []T, equalFunc func(a, b T) bool) []T

Types

type DoubleMap

type DoubleMap[K1 comparable, K2 comparable, V any] struct {
	// contains filtered or unexported fields
}

DoubleMap is a two-level nested generic Map structure

func NewDoubleMap

func NewDoubleMap[K1 comparable, K2 comparable, V any]() *DoubleMap[K1, K2, V]

func (*DoubleMap[K1, K2, V]) Delete

func (dm *DoubleMap[K1, K2, V]) Delete(k1 K1, k2 K2)

func (*DoubleMap[K1, K2, V]) DeleteAll

func (dm *DoubleMap[K1, K2, V]) DeleteAll(k1 K1)

DeleteAll deletes the outer key and all its inner key-values

func (*DoubleMap[K1, K2, V]) Get

func (dm *DoubleMap[K1, K2, V]) Get(k1 K1, k2 K2) (V, bool)

func (*DoubleMap[K1, K2, V]) HasInnerKey

func (dm *DoubleMap[K1, K2, V]) HasInnerKey(k1 K1, k2 K2) bool

func (*DoubleMap[K1, K2, V]) HasKey

func (dm *DoubleMap[K1, K2, V]) HasKey(k1 K1) bool

func (*DoubleMap[K1, K2, V]) Set

func (dm *DoubleMap[K1, K2, V]) Set(k1 K1, k2 K2, v V)

type Map

type Map[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewMap

func NewMap[K comparable, V any]() *Map[K, V]

func (*Map[K, V]) Delete

func (m *Map[K, V]) Delete(key K)

func (*Map[K, V]) Each

func (m *Map[K, V]) Each(f func(key K, value V))

func (*Map[K, V]) Empty

func (m *Map[K, V]) Empty() bool

func (*Map[K, V]) Exists

func (m *Map[K, V]) Exists(key K) bool

func (*Map[K, V]) Get

func (m *Map[K, V]) Get(key K) V

func (*Map[K, V]) Keys

func (m *Map[K, V]) Keys() []K

func (*Map[K, V]) Len

func (m *Map[K, V]) Len() int

func (*Map[K, V]) Set

func (m *Map[K, V]) Set(key K, value V)

func (*Map[K, V]) TryGet

func (m *Map[K, V]) TryGet(key K) (V, bool)

func (*Map[K, V]) Values

func (m *Map[K, V]) Values() []V

type NestedArray

type NestedArray[T any] struct {
	Data [][]T
}

func NewNestedArray

func NewNestedArray[T any]() *NestedArray[T]

func (*NestedArray[T]) AddRow

func (n *NestedArray[T]) AddRow(row []T)

func (*NestedArray[T]) GetColLen

func (n *NestedArray[T]) GetColLen(row int) int

func (*NestedArray[T]) GetRowLen

func (n *NestedArray[T]) GetRowLen() int

type Pair

type Pair[T1, T2 any] struct {
	First  T1
	Second T2
}

type Set

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

func NewSet

func NewSet[T comparable]() *Set[T]

func NewSetFromSlice

func NewSetFromSlice[T comparable](from []T) *Set[T]

func (*Set[T]) Add

func (s *Set[T]) Add(value T)

func (*Set[T]) Clear

func (s *Set[T]) Clear()

func (*Set[T]) Contains

func (s *Set[T]) Contains(value T) bool

func (*Set[T]) Exists

func (s *Set[T]) Exists(value T) bool

func (*Set[T]) Len

func (s *Set[T]) Len() int

func (*Set[T]) Remove

func (s *Set[T]) Remove(value T)

func (*Set[T]) Values

func (s *Set[T]) Values() []T

type Slice

type Slice[T any] struct {
	// contains filtered or unexported fields
}

func NewSlice

func NewSlice[T any](params ...int) *Slice[T]

func NewSliceFromData

func NewSliceFromData[T any](data []T) *Slice[T]

func SliceJoin

func SliceJoin[T any](slices ...*Slice[T]) *Slice[T]

func (*Slice[T]) Append

func (s *Slice[T]) Append(values ...T)

func (*Slice[T]) AppendSlice

func (s *Slice[T]) AppendSlice(b *Slice[T])

func (*Slice[T]) At

func (s *Slice[T]) At(index int) *T

func (*Slice[T]) Cap

func (s *Slice[T]) Cap() int

func (*Slice[T]) Clear

func (s *Slice[T]) Clear()

func (*Slice[T]) Data

func (s *Slice[T]) Data() []T

func (*Slice[T]) Each

func (s *Slice[T]) Each(f func(index int, value T))

func (*Slice[T]) Filter

func (s *Slice[T]) Filter(f func(index int, value T) bool) *Slice[T]

func (*Slice[T]) For

func (s *Slice[T]) For(f func(index int, value T) bool)

For each element, if f returns false, stop iteration

func (*Slice[T]) Get

func (s *Slice[T]) Get(index int) T

func (*Slice[T]) GetUncheck

func (s *Slice[T]) GetUncheck(index int) T

func (*Slice[T]) Len

func (s *Slice[T]) Len() int

func (*Slice[T]) RemoveAt

func (s *Slice[T]) RemoveAt(index int)

func (*Slice[T]) Reverse

func (s *Slice[T]) Reverse()

func (*Slice[T]) Set

func (s *Slice[T]) Set(index int, value T) bool

func (*Slice[T]) Sort

func (s *Slice[T]) Sort(less func(i int, j int) bool) *Slice[T]

type SortedMap

type SortedMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewSortedMap

func NewSortedMap[K comparable, V any]() *SortedMap[K, V]

func (*SortedMap[K, V]) Delete

func (sm *SortedMap[K, V]) Delete(key K)

func (*SortedMap[K, V]) Exists

func (sm *SortedMap[K, V]) Exists(key K) bool

func (*SortedMap[K, V]) Get

func (sm *SortedMap[K, V]) Get(key K) (V, bool)

func (*SortedMap[K, V]) Keys

func (sm *SortedMap[K, V]) Keys() []K

func (*SortedMap[K, V]) Len

func (sm *SortedMap[K, V]) Len() int

func (*SortedMap[K, V]) Put

func (sm *SortedMap[K, V]) Put(key K, value V)

func (*SortedMap[K, V]) Range

func (sm *SortedMap[K, V]) Range(fn func(key K, value V) bool)

Range : break when fn return false

func (*SortedMap[K, V]) Values

func (sm *SortedMap[K, V]) Values() []V

type SortedSet

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

func NewSortedSet

func NewSortedSet[T comparable]() *SortedSet[T]

func (*SortedSet[T]) Add

func (s *SortedSet[T]) Add(item T)

func (*SortedSet[T]) At

func (s *SortedSet[T]) At(index int) *T

func (*SortedSet[T]) Clear

func (s *SortedSet[T]) Clear()

func (*SortedSet[T]) Contains

func (s *SortedSet[T]) Contains(item T) bool

func (*SortedSet[T]) Get

func (s *SortedSet[T]) Get(index int) T

func (*SortedSet[T]) Items

func (s *SortedSet[T]) Items() []T

func (*SortedSet[T]) Len

func (s *SortedSet[T]) Len() int

func (*SortedSet[T]) Remove

func (s *SortedSet[T]) Remove(item T) bool

type SortedSlice

type SortedSlice[K comparable, V any] struct {
	// contains filtered or unexported fields
}

SortedSlice 维护插入顺序,并支持通过 Key 快速检索

func NewSortedSlice

func NewSortedSlice[K comparable, V any]() *SortedSlice[K, V]

NewSortedSlice 初始化

func (*SortedSlice[K, V]) GetByIndex

func (s *SortedSlice[K, V]) GetByIndex(index int) V

GetByIndex 通过索引查询

func (*SortedSlice[K, V]) GetByKey

func (s *SortedSlice[K, V]) GetByKey(key K) (V, bool)

GetByKey 通过 Key 快速查询: O(1)

func (*SortedSlice[K, V]) Len

func (s *SortedSlice[K, V]) Len() int

Len 返回当前元素数量

func (*SortedSlice[K, V]) Set

func (s *SortedSlice[K, V]) Set(key K, value V)

Set 插入或更新元素

func (*SortedSlice[K, V]) Values

func (s *SortedSlice[K, V]) Values() []V

type Triple

type Triple[T1, T2, T3 any] struct {
	First  T1
	Second T2
	Third  T3
}

Jump to

Keyboard shortcuts

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