Use templates in ol.structs.PriorityQueue

This commit is contained in:
Tom Payne
2013-11-18 16:55:54 +01:00
parent 9d92b9ee37
commit 353555f740
+9 -8
View File
@@ -15,25 +15,26 @@ goog.require('goog.object');
* @see http://hg.python.org/cpython/file/2.7/Lib/heapq.py * @see http://hg.python.org/cpython/file/2.7/Lib/heapq.py
* *
* @constructor * @constructor
* @param {function(?): number} priorityFunction Priority function. * @param {function(T): number} priorityFunction Priority function.
* @param {function(?): string} keyFunction Key function. * @param {function(T): string} keyFunction Key function.
* @template T
*/ */
ol.structs.PriorityQueue = function(priorityFunction, keyFunction) { ol.structs.PriorityQueue = function(priorityFunction, keyFunction) {
/** /**
* @type {function(?): number} * @type {function(T): number}
* @private * @private
*/ */
this.priorityFunction_ = priorityFunction; this.priorityFunction_ = priorityFunction;
/** /**
* @type {function(?): string} * @type {function(T): string}
* @private * @private
*/ */
this.keyFunction_ = keyFunction; this.keyFunction_ = keyFunction;
/** /**
* @type {Array} * @type {Array.<T>}
* @private * @private
*/ */
this.elements_ = []; this.elements_ = [];
@@ -88,7 +89,7 @@ ol.structs.PriorityQueue.prototype.clear = function() {
/** /**
* Remove and return the highest-priority element. O(log N). * Remove and return the highest-priority element. O(log N).
* @return {*} Element. * @return {T} Element.
*/ */
ol.structs.PriorityQueue.prototype.dequeue = function() { ol.structs.PriorityQueue.prototype.dequeue = function() {
var elements = this.elements_; var elements = this.elements_;
@@ -112,7 +113,7 @@ ol.structs.PriorityQueue.prototype.dequeue = function() {
/** /**
* Enqueue an element. O(log N). * Enqueue an element. O(log N).
* @param {*} element Element. * @param {T} element Element.
*/ */
ol.structs.PriorityQueue.prototype.enqueue = function(element) { ol.structs.PriorityQueue.prototype.enqueue = function(element) {
goog.asserts.assert(!(this.keyFunction_(element) in this.queuedElements_)); goog.asserts.assert(!(this.keyFunction_(element) in this.queuedElements_));
@@ -197,7 +198,7 @@ ol.structs.PriorityQueue.prototype.isKeyQueued = function(key) {
/** /**
* @param {*} element Element. * @param {T} element Element.
* @return {boolean} Is queued. * @return {boolean} Is queued.
*/ */
ol.structs.PriorityQueue.prototype.isQueued = function(element) { ol.structs.PriorityQueue.prototype.isQueued = function(element) {