Make code prettier
This updates ESLint and our shared eslint-config-openlayers to use Prettier. Most formatting changes were automatically applied with this:
npm run lint -- --fix
A few manual changes were required:
* In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
* In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason. While editing this, I reworked `ExampleBuilder` to be a class.
* In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
This commit is contained in:
@@ -4,13 +4,11 @@
|
||||
import {assert} from '../asserts.js';
|
||||
import {clear} from '../obj.js';
|
||||
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
export const DROP = Infinity;
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Priority queue.
|
||||
@@ -24,13 +22,11 @@ export const DROP = Infinity;
|
||||
* @template T
|
||||
*/
|
||||
class PriorityQueue {
|
||||
|
||||
/**
|
||||
* @param {function(T): number} priorityFunction Priority function.
|
||||
* @param {function(T): string} keyFunction Key function.
|
||||
*/
|
||||
constructor(priorityFunction, keyFunction) {
|
||||
|
||||
/**
|
||||
* @type {function(T): number}
|
||||
* @private
|
||||
@@ -60,7 +56,6 @@ class PriorityQueue {
|
||||
* @private
|
||||
*/
|
||||
this.queuedElements_ = {};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,7 +67,6 @@ class PriorityQueue {
|
||||
clear(this.queuedElements_);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove and return the highest-priority element. O(log N).
|
||||
* @return {T} Element.
|
||||
@@ -94,15 +88,13 @@ class PriorityQueue {
|
||||
return element;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enqueue an element. O(log N).
|
||||
* @param {T} element Element.
|
||||
* @return {boolean} The element was added to the queue.
|
||||
*/
|
||||
enqueue(element) {
|
||||
assert(!(this.keyFunction_(element) in this.queuedElements_),
|
||||
31); // Tried to enqueue an `element` that was already added to the queue
|
||||
assert(!(this.keyFunction_(element) in this.queuedElements_), 31); // Tried to enqueue an `element` that was already added to the queue
|
||||
const priority = this.priorityFunction_(element);
|
||||
if (priority != DROP) {
|
||||
this.elements_.push(element);
|
||||
@@ -114,7 +106,6 @@ class PriorityQueue {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return {number} Count.
|
||||
*/
|
||||
@@ -122,7 +113,6 @@ class PriorityQueue {
|
||||
return this.elements_.length;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the index of the left child of the node at the given index.
|
||||
* @param {number} index The index of the node to get the left child for.
|
||||
@@ -133,7 +123,6 @@ class PriorityQueue {
|
||||
return index * 2 + 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the index of the right child of the node at the given index.
|
||||
* @param {number} index The index of the node to get the right child for.
|
||||
@@ -144,7 +133,6 @@ class PriorityQueue {
|
||||
return index * 2 + 2;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the index of the parent of the node at the given index.
|
||||
* @param {number} index The index of the node to get the parent for.
|
||||
@@ -155,7 +143,6 @@ class PriorityQueue {
|
||||
return (index - 1) >> 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make this a heap. O(N).
|
||||
* @private
|
||||
@@ -167,7 +154,6 @@ class PriorityQueue {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Is empty.
|
||||
*/
|
||||
@@ -175,7 +161,6 @@ class PriorityQueue {
|
||||
return this.elements_.length === 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} key Key.
|
||||
* @return {boolean} Is key queued.
|
||||
@@ -184,7 +169,6 @@ class PriorityQueue {
|
||||
return key in this.queuedElements_;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {T} element Element.
|
||||
* @return {boolean} Is queued.
|
||||
@@ -193,7 +177,6 @@ class PriorityQueue {
|
||||
return this.isKeyQueued(this.keyFunction_(element));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} index The index of the node to move down.
|
||||
* @private
|
||||
@@ -206,13 +189,14 @@ class PriorityQueue {
|
||||
const priority = priorities[index];
|
||||
const startIndex = index;
|
||||
|
||||
while (index < (count >> 1)) {
|
||||
while (index < count >> 1) {
|
||||
const lIndex = this.getLeftChildIndex_(index);
|
||||
const rIndex = this.getRightChildIndex_(index);
|
||||
|
||||
const smallerChildIndex = rIndex < count &&
|
||||
priorities[rIndex] < priorities[lIndex] ?
|
||||
rIndex : lIndex;
|
||||
const smallerChildIndex =
|
||||
rIndex < count && priorities[rIndex] < priorities[lIndex]
|
||||
? rIndex
|
||||
: lIndex;
|
||||
|
||||
elements[index] = elements[smallerChildIndex];
|
||||
priorities[index] = priorities[smallerChildIndex];
|
||||
@@ -224,7 +208,6 @@ class PriorityQueue {
|
||||
this.siftDown_(startIndex, index);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} startIndex The index of the root.
|
||||
* @param {number} index The index of the node to move up.
|
||||
@@ -250,7 +233,6 @@ class PriorityQueue {
|
||||
priorities[index] = priority;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* FIXME empty description for jsdoc
|
||||
*/
|
||||
@@ -275,8 +257,6 @@ class PriorityQueue {
|
||||
priorities.length = index;
|
||||
this.heapify_();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export default PriorityQueue;
|
||||
|
||||
Reference in New Issue
Block a user