1 person found this helpful
>There can be thousands of tasks...So my solution for now is to loop every second over all tasks to do the check.
No. You just made a Wanted Dead Or Alive poster of a man named Application Performance...with Alive crossed out.
You know that the tasks can be arranged so that time task( x ) is due comes before the tmie tasks( x + 1 ) is due (montonically increasing). You can use this by ordering the tasks by the time they are due and sorting them into an array. Then, you only check the first task ( taskArray ) to see if it is due, if it is, you pop it off the array and handle your past due logic. This should change the time complexity of your application to O(1) when considering the dependency on the number of task as opposed to the O( MFG ) you are rocking right now.
I'm not sure about how the timer should be implemented. I am a little wary about the amount of bookkeeping you have to do. What happens when a new task is added (You have to resort your task array and reset the timer for the new first task), what about when a task time is changed, how do you go about resetting your timer, what if that task expires while the user is in the task time change UI ?
If this answer was helpful please mark it as such.
Thanks for the tip, this sounds a lot better the the looping indeed:)
I'll give it a try with the sorting.