An open API service indexing awesome lists of open source software.

https://github.com/gammazero/eytzinger

Eytzinger binary search
https://github.com/gammazero/eytzinger

binary-search eytzinger-binary-search

Last synced: 3 months ago
JSON representation

Eytzinger binary search

Awesome Lists containing this project

README

        

# eytzinger

[![GoDoc](https://pkg.go.dev/badge/github.com/gammazero/eytzinger)](https://pkg.go.dev/github.com/gammazero/eytzinger)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)

Eytzinger binary search, minimalistic implementation.

Package eytzinger implements Eytzinger Binary Search, using generics to operate on any [ordered](https://pkg.go.dev/golang.org/x/exp/constraints#Ordered) type.

## Installation

```
$ go get github.com/gammazero/eytzinger
```

## Example
```go
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)
}
```