heaps

package
v0.0.0-...-f0e9c47 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2019 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Done = errors.New("no more values left")
)

Functions

func MergeFiles

func MergeFiles(sequences ...[]int) ([]int, error)

MergeFiles merges k sorted sequences into a signle one. Takes O(n log k) time with O(k) space complexity. Where k is the number of sequences and n is the total number of elements combined.

func PrintKSorted

func PrintKSorted(iter IntSliceIter, k int)

PrintKSorted prints almost sorted array in sorted order where each elements is at most k position away from it's correct position. Takes O(n log k) time with O(k) space complexity.

func SortKIncDec

func SortKIncDec(s []int) ([]int, error)

SortKIncDec sorts array that contains multiple sorted inc/dec sequences in one sorted sequence. Takes O(n log k) time with O(k) space complexity. where k is the number of sorted arrays and n is the total number of elements.

Types

type IntHeap

type IntHeap []int

An IntHeap is a min-heap of ints.

func (IntHeap) Len

func (h IntHeap) Len() int

func (IntHeap) Less

func (h IntHeap) Less(i, j int) bool

func (*IntHeap) Pop

func (h *IntHeap) Pop() interface{}

func (*IntHeap) Push

func (h *IntHeap) Push(x interface{})

func (IntHeap) Swap

func (h IntHeap) Swap(i, j int)

type IntSliceIter

type IntSliceIter struct {
	// contains filtered or unexported fields
}

func NewIntSliceIter

func NewIntSliceIter(s []int) IntSliceIter

func (*IntSliceIter) Less

func (iter *IntSliceIter) Less(other IntSliceIter) bool

func (*IntSliceIter) Next

func (iter *IntSliceIter) Next() (int, error)

type IntSliceIterHeap

type IntSliceIterHeap []IntSliceIter

An IntSliceIterHeap is a min-heap of IntSliceIter.

func (IntSliceIterHeap) Len

func (h IntSliceIterHeap) Len() int

func (IntSliceIterHeap) Less

func (h IntSliceIterHeap) Less(i, j int) bool

func (*IntSliceIterHeap) Pop

func (h *IntSliceIterHeap) Pop() interface{}

func (*IntSliceIterHeap) Push

func (h *IntSliceIterHeap) Push(x interface{})

func (IntSliceIterHeap) Swap

func (h IntSliceIterHeap) Swap(i, j int)

type Run

type Run struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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