Skip to content

evansenter/f_heap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FHeap
=====

This is an implementation of the Fibonacci Heap data structure in Ruby. The Fibonacci Heap is a collection of trees that satisfy the minimum heap property (that is to say, each child node has a value >= its parent's value), which elicits the trait of having a better amortized runtime than a binomial heap.

Example
=======

irb(main):002:0> heap = FHeap.new
=> #<FHeap:0x10164d0c8 @trees=[], @min_node=nil>

irb(main):003:0> heap.insert!(9)
irb(main):004:0> heap.insert!(7)
irb(main):005:0> heap.insert!(8)
irb(main):006:0> heap.insert!(6)
irb(main):007:0> heap.insert!(5)
irb(main):008:0> heap.insert!(3)
irb(main):009:0> heap.insert!(4)
irb(main):010:0> heap.insert!(2)
irb(main):011:0> heap.insert!(1)
irb(main):012:0> heap.insert!(0)

irb(main):013:0> heap.extract_minimum!.value
=> 0
irb(main):014:0> heap.extract_minimum!.value
=> 1
irb(main):015:0> heap.extract_minimum!.value
=> 2
irb(main):016:0> heap.extract_minimum!.value
=> 3
irb(main):017:0> heap.extract_minimum!.value
=> 4
irb(main):018:0> heap.extract_minimum!.value
=> 5
irb(main):019:0> heap.extract_minimum!.value
=> 6
irb(main):020:0> heap.extract_minimum!.value
=> 7
irb(main):021:0> heap.extract_minimum!.value
=> 8
irb(main):022:0> heap.extract_minimum!.value
=> 9
irb(main):023:0> heap.extract_minimum!
=> nil

Copyright (c) 2010 Evan Senter, released under the MIT license