Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider moving to list-mapped-heap. #59

Open
Fishrock123 opened this issue May 2, 2020 · 0 comments
Open

Consider moving to list-mapped-heap. #59

Fishrock123 opened this issue May 2, 2020 · 0 comments

Comments

@Fishrock123
Copy link
Member

Fishrock123 commented May 2, 2020

i.e. like the Node.js algorithm.

That is, store the timers in lists mapped to duration then backed by a (much smaller) heap. Using this method guarantees timers are implicitly sorted (as long as operations are thread-atomic, I suppose).

Doing so provides O(1) + O(<maplookup> n-durations) insert and deletion, at worst O(log n-durations) + O(1) timeout, and no loss of timer accuracy. If the efficiency of maplookup is sub-linear this should outperform timer wheels overall, since bookkeeping (only when an operation happens) is only dependent on the durations rather than overall timers.

Given that durations are unique and likely to be few, using a hashtable directly should be possible, using the duration as the key itself. (i.e. HashMap with no hashing.)

I'd be willing to give it a shot. I suppose some kind of benchmarks would be desirable?

Edit: it does occur to me now that O(1) deletion is typically dependent on using linked lists, and maybe that isn't ideal in memory. That might matter more for Rust.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant