binomial

package
v0.0.0-...-ad36d6a Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2018 License: BSD-2-Clause Imports: 1 Imported by: 1

README

Package binomial

GoDoc

Tree Structure

Each box below is a Tree struct. Each Tree's child pointer is its first child in a linked list of direct children. The subsequent child in the list is the current child's sibling. Each child has a pointer back to its parent.

The rank, k, of each node is the rank of the tree below that node if you consider that node a root.

This entire diagram represents a rank 2 or degree 2 binomial tree. The Node pointers on each Tree are omitted for simplicity.

      +---------+
+----->k: 2     |
|     +---------+
|     |parent   |
|     |sibling  |
|  +--+child    |
|  |  +---------+
|  |
|  |  +---------+        +---------+
|  +-->k: 0     | +------>k: 1     <--+
|     +---------+ |      +---------+  |
+-----+parent   | | +----+parent   |  |
|     |sibling  +-+ |    |sibling  |  |
|     |child    |   | +--+child    |  |
|     +---------+   | |  +---------+  |
|                   | |               |
+-------------------+ |               |
                      |  +---------+  |
                      +-->k: 0     |  |
                         +---------+  |
                         |parent   +--+
                         |sibling  |
                         |child    |
                         +---------+

Heap Structure

A Heap contains a standard library doubly linked list where the Value for each list Element is a pointer to a Tree.

Documentation

Overview

Package binomial contains binomial tree and heap data structures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Heap

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

Heap is a binomial heap.

func NewHeap

func NewHeap(less Less) *Heap

NewHeap creates a new Heap with the given function to determine the lesser of two items on the heap. The Less function must handle each item added with Add.

func (*Heap) Add

func (h *Heap) Add(i interface{}) *Node

Add places a new Item on the heap.

func (*Heap) FindMin

func (h *Heap) FindMin() *Node

FindMin finds the minimum item on the heap.

func (*Heap) RemoveMin

func (h *Heap) RemoveMin() interface{}

RemoveMin removes the minimum item from the heap.

func (*Heap) Update

func (h *Heap) Update(n *Node)

Update updates the item in a Heap when the value of the item changes. The results are undefined if Node n is not on this Heap.

type Less

type Less func(a, b interface{}) bool

Less is a function that returns true if a is less than b.

type Node

type Node struct {
	Item interface{} // Consumer data
	// contains filtered or unexported fields
}

Node is a user data node on a binomial Tree.

type Tree

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

Tree is a binomial tree.

Jump to

Keyboard shortcuts

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