Documentation
¶
Index ¶
- func BinarySearch[T cmp.Ordered](slice []T, target T) int
- func BinarySearchFunc[T any](slice []T, target T, cmp func(a, b T) int) int
- func FindFirst[T any](slice []T, fn func(T) bool) int
- func FindLast[T any](slice []T, fn func(T) bool) int
- func IsSorted[T cmp.Ordered](slice []T) bool
- func IsSortedFunc[T any](slice []T, less func(a, b T) bool) bool
- func LinearSearch[T comparable](slice []T, target T) int
- func LowerBound[T cmp.Ordered](slice []T, target T) int
- func Sort[T cmp.Ordered](slice []T)
- func SortDesc[T cmp.Ordered](slice []T)
- func SortFunc[T any](slice []T, less func(a, b T) bool)
- func UpperBound[T cmp.Ordered](slice []T, target T) int
- type LRU
- type Queue
- type Set
- func (s *Set[T]) Add(item T)
- func (s *Set[T]) Clear()
- func (s *Set[T]) Contains(item T) bool
- func (s *Set[T]) Diff(other *Set[T]) *Set[T]
- func (s *Set[T]) Intersect(other *Set[T]) *Set[T]
- func (s *Set[T]) IsEmpty() bool
- func (s *Set[T]) Remove(item T)
- func (s *Set[T]) Size() int
- func (s *Set[T]) ToSlice() []T
- func (s *Set[T]) Union(other *Set[T]) *Set[T]
- type Stack
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BinarySearch ¶
BinarySearch 二分查找,返回目标值的索引,如果不存在返回 -1 / Binary search, return index of target, -1 if not found
func BinarySearchFunc ¶
BinarySearchFunc 使用自定义比较函数进行二分查找 / Binary search with custom comparison function
func FindFirst ¶
FindFirst 查找第一个满足条件的元素索引,不存在返回 -1 / Find first element index matching condition, return -1 if not found
func FindLast ¶
FindLast 查找最后一个满足条件的元素索引,不存在返回 -1 / Find last element index matching condition, return -1 if not found
func IsSortedFunc ¶
IsSortedFunc 使用自定义比较函数检查切片是否已排序 / Check if slice is sorted using custom comparison function
func LinearSearch ¶
func LinearSearch[T comparable](slice []T, target T) int
LinearSearch 线性查找,返回目标值的索引,如果不存在返回 -1 / Linear search, return index of target, -1 if not found
func LowerBound ¶
LowerBound 查找第一个大于等于目标值的元素索引 / Find first element index >= target
func UpperBound ¶
UpperBound 查找第一个大于目标值的元素索引 / Find first element index > target
Types ¶
type LRU ¶
type LRU[K comparable, V any] struct { // contains filtered or unexported fields }
LRU LRU缓存 / LRU cache
func NewLRU ¶
func NewLRU[K comparable, V any](capacity int) *LRU[K, V]
NewLRU 创建LRU缓存 / Create LRU cache
type Queue ¶
type Queue[T any] struct { // contains filtered or unexported fields }
Queue 队列数据结构 / Queue data structure
type Set ¶
type Set[T comparable] struct { // contains filtered or unexported fields }
Set 集合数据结构 / Set data structure