algorithms

package
v0.0.0-...-244c41e Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// This can mean that a list with 0 items was passed in.
	ErrSearchResultInvalid = errors.New("ErrSearchResultInvalid")
)

Functions

This section is empty.

Types

type BinarySearchFunc

type BinarySearchFunc[T numberType] func(i T) (SearchResult, error)

BinarySearchFunc is a caller-supplied function that tells the Binary Search function to go higher or lower

func CreateByteComparatorFunc

func CreateByteComparatorFunc[T numberType](needle []byte, getListValueAtIndex func(index T) []byte) BinarySearchFunc[T]

CreateByteComparatorFunc creates a comparator function for keys of type []byte

type BinarySearchOptions

type BinarySearchOptions struct {
	MaxIterations int64
}

type BinarySearchResult

type BinarySearchResult[T numberType] struct {
	LastIndexChecked T
	LastResult       SearchResult
}

func BinarySearch

func BinarySearch[T numberType](listSize T, binarySearchFunc BinarySearchFunc[T], passedInOptions *BinarySearchOptions) (BinarySearchResult[T], error)

BinarySearch performs a binary search on a given list size and binary search function please note, the exact value you search for may not be found - please check the BinarySearchResult value

type SearchResult

type SearchResult int
const (
	SearchResultUnknown SearchResult = iota
	// SearchResultFound indicates the desired result has been found and the search should terminate
	SearchResultFound
	// SearchResultGoLower indicates the search should look lower
	SearchResultGoLower
	// SearchResultGoHigher indicates the search should look higher
	SearchResultGoHigher
)

func (SearchResult) String

func (i SearchResult) String() string

Jump to

Keyboard shortcuts

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