I got an executor thread that is given jobs to execute at certain timestamp. So this means my problem is online.
While there are cases when the new job has a timestamp in the past, we can easily test for that and set the timestamp one millisecond into the future. So the series is monotone.
Currently, I got an array where I store the jobs, then every "tick" I sort the array and process the jobs whose timestamp are below the current time. This sounds bad so I want to improve it.
When inserting jobs I tend to have many which are recurrent jumps in time (timers), eg currenttime+250ms, and once I execute that job I insert another one for another 250ms into the future.
I have another set which are not recurrent, but are also a jump into the future, eg currenttime+576ms. A weird subset of these are very long jumps into the future, eg one day or more. Usually, its short jumps, at most 5 seconds.
I have another set which is aimed towards the very next loop and is also not recurrent, but every loop I end up generating many of these so they are always present, eg currenttime+1ms, I could always keep a separate array for these, if that makes the data structure for the rest faster
As I process them in order, I only need to pop() the top/bottom, and then remove it
As I eventually delete every insertion, I assume both operations should be fast
So, I need fast insert at any position with autosort probably, fast peek / select-min, fast pop / remove-min, search can be super slow so long as peek+pop are fast, and remove at arbitrary index other than min could also be super slow
I read on balanced binary trees and they seem fast but then I noticed their search and remove anywhere are logn so they are good "under all terrains" which is more than what I need, there are also priority queues of many types, so I wonder if theres anything even more optimized towards what I need