Refactor ol.TileQueue to extend ol.structs.PriorityQueue

This commit is contained in:
Tom Payne
2013-03-25 21:25:20 +01:00
parent f12f5ccc67
commit 27f9e83780
4 changed files with 42 additions and 220 deletions

View File

@@ -4,15 +4,15 @@ describe('ol.TileQueue', function() {
// is the tile queue's array a heap?
function isHeap(tq) {
var heap = tq.heap_;
var priorities = tq.priorities_;
var i;
var key;
var leftKey;
var rightKey;
for (i = 0; i < (heap.length >> 1) - 1; i++) {
key = heap[i][0];
leftKey = heap[tq.getLeftChildIndex_(i)][0];
rightKey = heap[tq.getRightChildIndex_(i)][0];
for (i = 0; i < (priorities.length >> 1) - 1; i++) {
key = priorities[i];
leftKey = priorities[tq.getLeftChildIndex_(i)];
rightKey = priorities[tq.getRightChildIndex_(i)];
if (leftKey < key || rightKey < key) {
return false;
}
@@ -25,8 +25,9 @@ describe('ol.TileQueue', function() {
for (i = 0; i < num; i++) {
tile = new ol.Tile();
priority = Math.floor(Math.random() * 100);
tq.heap_.push([priority, tile, '', new ol.Coordinate(0, 0)]);
tq.queuedTileKeys_[tile.getKey()] = true;
tq.elements_.push([tile, '', new ol.Coordinate(0, 0)]);
tq.priorities_.push(priority);
tq.queuedElements_[tile.getKey()] = true;
}
}
@@ -53,15 +54,16 @@ describe('ol.TileQueue', function() {
// rest
var i = 0;
tq.tilePriorityFunction_ = function() {
tq.priorityFunction_ = function() {
if ((i++) % 2 === 0) {
return ol.TileQueue.DROP;
return ol.structs.PriorityQueue.DROP;
}
return Math.floor(Math.random() * 100);
};
tq.reprioritize();
expect(tq.heap_.length).to.eql(50);
expect(tq.elements_.length).to.eql(50);
expect(tq.priorities_.length).to.eql(50);
expect(isHeap(tq)).to.be.ok();
});
@@ -71,3 +73,4 @@ describe('ol.TileQueue', function() {
goog.require('ol.Coordinate');
goog.require('ol.Tile');
goog.require('ol.TileQueue');
goog.require('ol.structs.PriorityQueue');