mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Adding typing for priorityqueuejs (#11550)
This commit is contained in:
parent
24c5ceec7f
commit
061f85a77d
65
priorityqueuejs/index.d.ts
vendored
Normal file
65
priorityqueuejs/index.d.ts
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
// Type definitions for priorityqueuejs v1.0
|
||||
// Project: https://github.com/janogonzalez/priorityqueuejs
|
||||
// Definitions by: Joshua DeVinney <https://github.com/geoffreak>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare class PriorityQueue<T> {
|
||||
/**
|
||||
* Compares two Number or String objects.
|
||||
*/
|
||||
static DEFAULT_COMPARATOR: PriorityQueue.Comparator<number | string>;
|
||||
|
||||
/**
|
||||
* Initializes a new empty PriorityQueue wich uses .DEFAULT_COMPARATOR() as the comparator function for its elements.
|
||||
*/
|
||||
constructor();
|
||||
|
||||
/**
|
||||
* Initializes a new empty PriorityQueue with uses the given comparator(a, b) function as the comparator for its elements.
|
||||
* The comparator function must return a positive number when a > b, 0 when a == b and a negative number when a < b.
|
||||
*/
|
||||
constructor(comparator: PriorityQueue.Comparator<T>);
|
||||
|
||||
/**
|
||||
* Dequeues the top element of the priority queue.
|
||||
* Throws an Error when the queue is empty.
|
||||
*/
|
||||
deq(): T;
|
||||
|
||||
/**
|
||||
* Enqueues the element at the priority queue and returns its new size.
|
||||
* @param element The element to add
|
||||
*/
|
||||
enq(element: T): number;
|
||||
|
||||
/**
|
||||
* Executes fn on each element.
|
||||
* Just be careful to not modify the priorities, since the queue won't reorder itself.
|
||||
* @param fn The value to pass to an Array.forEach call
|
||||
*/
|
||||
forEach(fn: (value: T, index: number, array: T[]) => void): void;
|
||||
|
||||
/**
|
||||
* Returns whether the priority queue is empty or not.
|
||||
*/
|
||||
isEmpty(): boolean;
|
||||
|
||||
/**
|
||||
* Peeks at the top element of the priority queue.
|
||||
* Throws an Error when the queue is empty.
|
||||
*/
|
||||
peek(): T;
|
||||
|
||||
/**
|
||||
* Returns the size of the priority queue.
|
||||
*/
|
||||
size(): number;
|
||||
}
|
||||
|
||||
declare namespace PriorityQueue {
|
||||
export interface Comparator<T> {
|
||||
(a: T, b: T): number;
|
||||
}
|
||||
}
|
||||
|
||||
export = PriorityQueue;
|
||||
13
priorityqueuejs/priorityqueuejs-tests.ts
Normal file
13
priorityqueuejs/priorityqueuejs-tests.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import * as PriorityQueue from 'priorityqueuejs';
|
||||
|
||||
var queue = new PriorityQueue<{ cash: number, name: string }>(function(a, b) {
|
||||
return a.cash - b.cash;
|
||||
});
|
||||
|
||||
queue.enq({ cash: 250, name: 'Valentina' });
|
||||
queue.enq({ cash: 300, name: 'Jano' });
|
||||
queue.enq({ cash: 150, name: 'Fran' });
|
||||
queue.size(); // 3
|
||||
queue.peek(); // { cash: 300, name: 'Jano' }
|
||||
queue.deq(); // { cash: 300, name: 'Jano' }
|
||||
queue.size(); // 2
|
||||
19
priorityqueuejs/tsconfig.json
Normal file
19
priorityqueuejs/tsconfig.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": false,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"priorityqueuejs-tests.ts"
|
||||
]
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user