Monday, October 07, 2019

FIFO queue use case

I have a simulation whose number of time steps varies according to inputs. To find the last state of the simulation via interpolation, I need to save the last N time steps. I can use a FIFO queue to save the results of last N time steps (e.g. to use in interpolation). Pseudocode:

step() {
    result = calcStateAtCurrentTime();
    queue.push(result);
    if(queue.size() > N) {
        queue.pop();
    }    
}

Bonus: To print unsigned int 64, use printf("%"PRId64", myUInt64)

No comments: