-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
dafeng.xdf
committed
Aug 26, 2014
1 parent
8f17d9e
commit e2f6095
Showing
5 changed files
with
80 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# Class BinaryHeap | ||
|
||
> JavaScript Implementation of the Binary Heap. | ||
> Author: xdf | ||
## Constructor Detail | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
;(function($, P, BinaryHeap, undefined){ | ||
// fetch docs | ||
$.ajax({ | ||
url : './README.md', | ||
dataType : 'html', | ||
scriptCharset: 'utf-8', | ||
success : function(d) { | ||
$('#docs').html(marked(d)); | ||
} | ||
}); | ||
// init heap | ||
var TOTAL = 400; | ||
var binaryHeap = new BinaryHeap(); | ||
var result; | ||
var total; | ||
function initHeap() { | ||
result = []; | ||
total = TOTAL; | ||
binaryHeap.clear(); | ||
while(total --) { | ||
binaryHeap.add(total); | ||
} | ||
total = TOTAL; | ||
} | ||
initHeap(); | ||
// init demonstrate | ||
var capacity = 2 / 3; | ||
var WIDTH = TOTAL; | ||
var HEIGHT = TOTAL * capacity; | ||
var Screen = P.Screen; | ||
var Timer = P.Timer; | ||
var screen = new Screen({ | ||
container: 'screen', | ||
width: WIDTH, | ||
height: HEIGHT, | ||
x:0, | ||
y:0 | ||
}); | ||
screen.update(function() { | ||
if(!total) initHeap(); | ||
result.push(binaryHeap.pop()); | ||
var current = []; | ||
var ctx = this.context; | ||
ctx.lineWidth = 1; | ||
current = current.concat(result); | ||
current = current.concat(binaryHeap.list); | ||
current.forEach(function(i, k) { | ||
ctx.beginPath(); | ||
ctx.moveTo(k, i * capacity); | ||
ctx.lineTo(k, HEIGHT); | ||
ctx.stroke(); | ||
}); | ||
total --; | ||
}); | ||
var timer = new Timer(screen); | ||
timer.start(); | ||
})(jQuery, pillow, BinaryHeap.BinaryHeap); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,10 @@ | |
right:0; | ||
border: 0; | ||
} | ||
#screen{ | ||
background: #ebebeb; | ||
} | ||
#demonstrate { | ||
text-align: center; | ||
padding: 20px 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters