-
Notifications
You must be signed in to change notification settings - Fork 3
/
README
46 lines (40 loc) · 1.33 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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