binary

package
v1.13.4 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2025 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SearchL

func SearchL[T any](n int, f func(int) (bool, T, error)) (int, T, error)

SearchL is a binary search variant, which uses an indicator func f(i), and finds the index of the last element, and the element itself, which returns true.

Example search space: index: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 values: 1, 1, 1, 1, 1, 0, 0, 0, 0, 0

SearchL would return: index 4 and f(4) Returns -1, if f(i) returns false for all i in [0,n) Returns n-1, if f(i) returns true for all i in [0,n)

Based on: https://pesho-ivanov.github.io/#Binary%20search

func SearchR

func SearchR[T any](n int, f func(int) (bool, T, error)) (int, T, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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