matrix2d

Source ยป

matrix2d allows for quick searching of a rectangular, sorted (column-wise and row-wise) matrix. Uses the algorithm described by Craig Gidney.

The code is unit tested with full code coverage.

matrix2d.go

Example output

package main

import (
	"fmt"

	"github.com/esote/matrix2d"
)

func main() {
	matrix := [][]int{
		{1, 2, 3, 4, 5},
		{1, 2, 3, 5, 7},
		{1, 4, 9, 16, 25},
	}

	item := 3
	point, ok := matrix2d.Search(matrix, item)

	if ok {
		fmt.Printf("found %d at (%d, %d)\n", item, point.X, point.Y)
	}

	// prints: "found 3 at (0, 2)"
}