Skip to content

Commit

Permalink
Merge branch 'main' into svg_to_canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshVarga authored Jul 28, 2024
2 parents 31dbefa + 823817f commit 9fa8530
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/simulator/src/eventQueue.js → src/simulator/src/eventQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,29 @@
* Event Queue is simply a priority Queue, basic implementation O(n^2).
* @category eventQueue
*/

interface QueueObject {
queueProperties: {
inQueue: boolean
time: number
index: number
}
propagationDelay: number
}

export class EventQueue {
constructor(size) {
size: number
queue: Array<QueueObject>
frontIndex: number
time: number
constructor(size: number) {
this.size = size
this.queue = new Array(size)
this.frontIndex = 0
this.time = 0
}

/**
* @param {CircuitElement} obj - the elemnt to be added
* @param {number} delay - the delay in adding an object to queue
*/
add(obj, delay) {
add(obj: QueueObject, delay: number) {
if (obj.queueProperties.inQueue) {
obj.queueProperties.time =
this.time + (delay || obj.propagationDelay)
Expand Down Expand Up @@ -59,7 +69,7 @@ export class EventQueue {
* To add without any delay.
* @param {CircuitElement} obj - the object to be added
*/
addImmediate(obj) {
addImmediate(obj: QueueObject) {
this.queue[this.frontIndex] = obj
obj.queueProperties.time = this.time
obj.queueProperties.index = this.frontIndex
Expand All @@ -69,10 +79,8 @@ export class EventQueue {

/**
* Function to swap two objects in queue.
* @param {number} v1
* @param {number} v2
*/
swap(v1, v2) {
swap(v1: number, v2: number) {
const obj1 = this.queue[v1]
obj1.queueProperties.index = v2

Expand Down

0 comments on commit 9fa8530

Please sign in to comment.