Documentation ¶
Overview ¶
Package algorithm contain some basic algorithm functions. eg. sort, search, list, linklist, stack, queue, tree, graph. TODO
Package algorithm contain some basic algorithm functions. eg. sort, search
Index ¶
- func BinaryIterativeSearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, ...) int
- func BinarySearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, ...) int
- func BubbleSort[T any](slice []T, comparator lancetconstraints.Comparator)
- func CountSort[T any](slice []T, comparator lancetconstraints.Comparator) []T
- func HeapSort[T any](slice []T, comparator lancetconstraints.Comparator)
- func InsertionSort[T any](slice []T, comparator lancetconstraints.Comparator)
- func LinearSearch[T any](slice []T, target T, comparator lancetconstraints.Comparator) int
- func MergeSort[T any](slice []T, comparator lancetconstraints.Comparator)
- func QuickSort[T any](slice []T, lowIndex, highIndex int, comparator lancetconstraints.Comparator)
- func SelectionSort[T any](slice []T, comparator lancetconstraints.Comparator)
- func ShellSort[T any](slice []T, comparator lancetconstraints.Comparator)
- type LRUCache
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BinaryIterativeSearch ¶
func BinaryIterativeSearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) int
BinaryIterativeSearch search for target within a sorted slice. If a target is found, the index of the target is returned. Else the function return -1
func BinarySearch ¶
func BinarySearch[T any](sortedSlice []T, target T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) int
BinarySearch search for target within a sorted slice, recursive call itself. If a target is found, the index of the target is returned. Else the function return -1
func BubbleSort ¶
func BubbleSort[T any](slice []T, comparator lancetconstraints.Comparator)
BubbleSort use bubble to sort slice.
func CountSort ¶
func CountSort[T any](slice []T, comparator lancetconstraints.Comparator) []T
CountSort use count sorting for slice
func HeapSort ¶
func HeapSort[T any](slice []T, comparator lancetconstraints.Comparator)
HeapSort use heap to sort slice
func InsertionSort ¶
func InsertionSort[T any](slice []T, comparator lancetconstraints.Comparator)
InsertionSort use insertion to sort slice.
func LinearSearch ¶
func LinearSearch[T any](slice []T, target T, comparator lancetconstraints.Comparator) int
LinearSearch Simple linear search algorithm that iterates over all elements of an slice If a target is found, the index of the target is returned. Else the function return -1
func MergeSort ¶
func MergeSort[T any](slice []T, comparator lancetconstraints.Comparator)
MergeSort merge sorting for slice
func QuickSort ¶
func QuickSort[T any](slice []T, lowIndex, highIndex int, comparator lancetconstraints.Comparator)
QuickSort quick sorting for slice, lowIndex is 0 and highIndex is len(slice)-1
func SelectionSort ¶
func SelectionSort[T any](slice []T, comparator lancetconstraints.Comparator)
SelectionSort use selection to sort slice.
func ShellSort ¶
func ShellSort[T any](slice []T, comparator lancetconstraints.Comparator)
ShellSort shell sort slice.
Types ¶
type LRUCache ¶
type LRUCache[K comparable, V any] struct { // contains filtered or unexported fields }
LRUCache lru cache (thread unsafe)
func NewLRUCache ¶
func NewLRUCache[K comparable, V any](capacity int) *LRUCache[K, V]
NewLRUCache return a LRUCache pointer