algorithm

package
v2.0.7 Latest Latest
Warning

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

Go to latest
Published: May 18, 2022 License: MIT Imports: 1 Imported by: 4

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

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

func (*LRUCache[K, V]) Get

func (l *LRUCache[K, V]) Get(key K) (V, bool)

Get value of key from lru cache

func (*LRUCache[K, V]) Put

func (l *LRUCache[K, V]) Put(key K, value V)

Put value of key into lru cache

Jump to

Keyboard shortcuts

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