go_heaps

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

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

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

README

go-heaps

GoDoc License

Reference implementations of heap data structures in Go

Installation

$ go get -u github.com/theodesp/go-heaps

Contents

Heaps

  • Pairing Heap: A pairing heap is a type of heap data structure with relatively simple implementation and excellent practical amortized performance,

Usage

package main

import (
	pairingHeap "go-heaps/pairing"
	"fmt"
)

func main()  {
	heap := pairingHeap.NewWithIntComparator()
	heap.Insert(4)
	heap.Insert(3)
	heap.Insert(2)
	heap.Insert(5)

	fmt.Println(heap.DeleteMin()) // 2
	fmt.Println(heap.DeleteMin()) // 3
	fmt.Println(heap.DeleteMin()) // 4
	fmt.Println(heap.DeleteMin()) // 5
}

Complexity

Operation Pairing
FindMin Θ(1)
DeleteMin O(log n)
Insert Θ(1)
Find O(n)
Delete O(log n)
Adjust O(log n)

LICENCE

Copyright © 2017 Theo Despoudis MIT license

Documentation

Index

Constants

View Source
const Version = "0.0.1"

Version The main version number that is being run at the moment.

Variables

This section is empty.

Functions

func IntComparator

func IntComparator(a, b interface{}) int

IntComparator provides a basic comparison on int

func StringComparator

func StringComparator(a, b interface{}) int

StringComparator provides a fast comparison on strings

Types

type Comparator

type Comparator func(a, b interface{}) int

Comparator will make type assertion (see IntComparator for example), which will panic if a or b are not of the asserted type.

Should return a number:

negative , if a < b
zero     , if a == b
positive , if a > b

type Interface

type Interface interface {
	// Inserts an element to the heap and returns it
	Insert(v interface{}) interface{}

	// DeleteMin deletes and returns the smallest element
	DeleteMin() interface{}

	// FindMin returns the minimum element
	FindMin() interface{}

	// Removes all items
	Clear()
}

Interface is basic interface that all Heaps implement.

Directories

Path Synopsis
Package pairing implements a Pairing heap Data structure
Package pairing implements a Pairing heap Data structure

Jump to

Keyboard shortcuts

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