This is a standalone Max Priority Queue data structure from the data-structure-typed collection. If you wish to access
more data structures or advanced features, you can transition to directly installing the
complete data-structure-typed package
interface Bid {
bidder: string;
amount: number;
}
const auction = new MaxPriorityQueue<Bid>([], {
comparator: (a, b) => b.amount - a.amount
});
auction.add({ bidder: 'Alice', amount: 100 });
auction.add({ bidder: 'Bob', amount: 250 });
auction.add({ bidder: 'Charlie', amount: 175 });
console.log(auction.peek()?.bidder);
console.log(auction.peek()?.amount);
const winner = auction.poll()!;
console.log(winner.bidder);
console.log(auction.peek()?.bidder); const cpuQueue = new MaxPriorityQueue<[number, string]>([], {
comparator: (a, b) => b[0] - a[0]
});
cpuQueue.add([5, 'System process']);
cpuQueue.add([1, 'Background task']);
cpuQueue.add([8, 'User interaction']);
cpuQueue.add([3, 'Network sync']);
const order = [];
while (cpuQueue.size > 0) {
order.push(cpuQueue.poll()![1]);
}
console.log(order);
| Principle |
Description |
| Practicality |
Follows ES6 and ESNext standards, offering unified and considerate optional parameters, and simplifies method names. |
| Extensibility |
Adheres to OOP (Object-Oriented Programming) principles, allowing inheritance for all data structures. |
| Modularization |
Includes data structure modularization and independent NPM packages. |
| Efficiency |
All methods provide time and space complexity, comparable to native JS performance. |
| Maintainability |
Follows open-source community development standards, complete documentation, continuous integration, and adheres to TDD (Test-Driven Development) patterns. |
| Testability |
Automated and customized unit testing, performance testing, and integration testing. |
| Portability |
Plans for porting to Java, Python, and C++, currently achieved to 80%. |
| Reusability |
Fully decoupled, minimized side effects, and adheres to OOP. |
| Security |
Carefully designed security for member variables and methods. Read-write separation. Data structure software does not need to consider other security aspects. |
| Scalability |
Data structure software does not involve load issues. |