bisect

package module
v0.0.0-...-c704031 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2018 License: MIT Imports: 0 Imported by: 0

README

bisect

Travis-CI
GoDoc Report card

Package bisect implements common bisection algorithms.

go get -u github.com/theodesp/bisect

Examples

package main

import (
	"github.com/theodesp/bisect"
	"fmt"
)

func main()  {
	var ints bisect.IntSlice
	for i:=0;i<10;i += 2 {
		ints = append(ints, i)
	}

	ints.InsortLeft(-1)
	ints.InsortRight(16)

	fmt.Println(ints) // [16 -1 0 2 4 6 8]
}

Read the package documentation for more information.

Contributing

We welcome pull requests, bug fixes and issue reports. Before proposing a change, please discuss your change by raising an issue.

License

Copyright © 2017 Theo Despoudis MIT license

Documentation

Overview

Package bisect implements common bisection algorithms.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BisectLeft

func BisectLeft(a Interface, x interface{}) int

Return the index where to insert item x in a, assuming a is sorted. The return value i is such that all e in a[:i] have e < x, and all e in a[i:] have e >= x. So if x already appears in the list, a.insert(x) will insert just before the leftmost x already there.

func BisectRight

func BisectRight(a Interface, x interface{}) int

Return the index where to insert item x in a, assuming a is sorted. The return value i is such that all e in a[:i] have e <= x, and all e in a[i:] have e > x. So if x already appears in the list, a.insert(x) will insert just after the rightmost x already there.

Types

type Float64Slice

type Float64Slice []float64

Float64Slice attaches the methods of items to []float64

func (*Float64Slice) BisectLeft

func (p *Float64Slice) BisectLeft(x float64)

func (*Float64Slice) BisectRight

func (p *Float64Slice) BisectRight(x float64)

func (*Float64Slice) Insert

func (p *Float64Slice) Insert(i int, x interface{})

func (*Float64Slice) InsortLeft

func (p *Float64Slice) InsortLeft(x float64)

func (*Float64Slice) InsortRight

func (p *Float64Slice) InsortRight(x float64)

InsortRight is a convenience method.

func (Float64Slice) Len

func (p Float64Slice) Len() int

func (Float64Slice) Less

func (p Float64Slice) Less(i int, with interface{}) bool

type IntSlice

type IntSlice []int

IntSlice attaches the methods of Items to []int

func (*IntSlice) BisectLeft

func (p *IntSlice) BisectLeft(x int)

func (*IntSlice) BisectRight

func (p *IntSlice) BisectRight(x int)

func (*IntSlice) Insert

func (p *IntSlice) Insert(i int, x interface{})

func (*IntSlice) InsortLeft

func (p *IntSlice) InsortLeft(x int)

func (*IntSlice) InsortRight

func (p *IntSlice) InsortRight(x int)

Convenience methods.

func (IntSlice) Len

func (p IntSlice) Len() int

func (IntSlice) Less

func (p IntSlice) Less(i int, with interface{}) bool

type Interface

type Interface interface {
	// Len is the number of elements in the collection.
	Len() int
	// Compares a given item with the element x at index i
	// Should return a bool:
	//    negative , if a[i] < than
	//    positive , if a[i] > than
	Less(i int, than interface{}) bool
}

Interface is a type, typically a collection can be sorted in-place by the routines in this package

type StringSlice

type StringSlice []string

StringSlice attaches the methods of Items to []string

func (*StringSlice) BisectLeft

func (p *StringSlice) BisectLeft(x string)

func (*StringSlice) BisectRight

func (p *StringSlice) BisectRight(x string)

func (*StringSlice) Insert

func (p *StringSlice) Insert(i int, x interface{})

func (*StringSlice) InsortLeft

func (p *StringSlice) InsortLeft(x string)

func (*StringSlice) InsortRight

func (p *StringSlice) InsortRight(x string)

Convenience methods.

func (StringSlice) Len

func (p StringSlice) Len() int

func (StringSlice) Less

func (p StringSlice) Less(i int, with interface{}) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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