Hacker News new | past | comments | ask | show | jobs | submit login

The last hour now goes back from 22:45:03.435123897 (remember, nanosecond timer, but now it is from 22:46:07.223981453. Unless you can round the time when the last second, the last minute, etc start, you have to keep the full history of increment events up to the nanosecond for the last 24 hours. That's O(246060*1e9).



But if you do round the time to an acceptable degree of accuracy (say, to within 1ms of the second count and 1m of the day count) then it does work within a fixed amount of memory. It's probably the best solution.

It's a lovely exercise in algorithm tradeoffs. In this case it's mainly accuracy vs. memory, with lots of opportunity to explore implementation optimizations.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: