This is a standalone Min 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 Event {
time: number;
action: string;
}
const timeline = new MinPriorityQueue<Event>([], {
comparator: (a, b) => a.time - b.time
});
timeline.add({ time: 300, action: 'Timeout' });
timeline.add({ time: 100, action: 'Request received' });
timeline.add({ time: 200, action: 'Processing done' });
timeline.add({ time: 150, action: 'Cache hit' });
const order = [];
while (timeline.size > 0) {
order.push(timeline.poll()!.action);
}
console.log(order);
const freq = new MinPriorityQueue<[number, string]>([], {
comparator: (a, b) => a[0] - b[0]
});
freq.add([5, 'a']);
freq.add([9, 'b']);
freq.add([12, 'c']);
freq.add([2, 'd']);
const first = freq.poll()!;
const second = freq.poll()!;
console.log(first[1]);
console.log(second[1]);
freq.add([first[0] + second[0], first[1] + second[1]]);
console.log(freq.peek()![0]);
| 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. |