eytzinger

package module
v0.0.0-...-64915f8 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2022 License: MIT Imports: 2 Imported by: 0

README

eytzinger

GoDoc License

Eytzinger binary search, minimalistic implementation.

Package eytzinger implements Eytzinger Binary Search, using generics to operate on any ordered type.

Installation

$ go get github.com/gammazero/eytzinger

Example

a := make([]int, 100)
for i := 0; i < len(a); i++ {
    a[i] = i
}

// Sort slice into Eytzinger order.
eytzinger.Sort(a)

// Find some numbers.
for _, find := range []int{13, 17, 19, 23, 29, 37, 73} {
    index := eytzinger.Search(a, find)
    fmt.Println(find, "is at index", index)
}

Documentation

Overview

Package eytzinger implements Eytzinger Binary Search for any ordered type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Search[T constraints.Ordered](a []T, x T) int

Search does a binary search of an array sorted in Eytzinger order.

func Sort

func Sort[T constraints.Ordered](a []T)

Sort sorts the given array into Eytzinger order.

Types

This section is empty.

Jump to

Keyboard shortcuts

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