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

Make events traceable #51

Merged
merged 3 commits into from
Jan 10, 2017
Merged

Make events traceable #51

merged 3 commits into from
Jan 10, 2017

Conversation

KitsuneRal
Copy link
Member

This PR changes the container for events to std::deque. This brings in an important guarantee that once inserted, an event object stays in memory where it landed, without relocations upon insertion of further events (somewhat similar to std::list/QLinkedList); at the same time std::deque allows amortized-constant complexity of random access (similar to std::vector/QVector/QList).

Combined with a separate hashmap of event id's to iterators in this deque, it becomes possible to find an arbitrary event object by its id together with its position in the respective timeline. This allows to considerably simplify read marker management: instead of searching back and forth over the timeline, it's now possible to pinpoint an event with a certain id by a single lookup in the hashmap. I suppose, such traceability can bring even more benefits further on.

A new hashmap, eventsIndex, is provided, that allows you to find the event in the timeline if you have eventId. This hashmap uses the fact that deque iterators don't invalidate upon insertion of elements to either end of the deque. Thanks to that, promoteReadMarker() and doAddNewMessageEvents() have been considerably simplified; also, it should be easier now to calculate event indices without rolling back and forth over the timeline.
Copy link
Contributor

@Fxrh Fxrh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@KitsuneRal KitsuneRal merged commit f37874c into master Jan 10, 2017
@KitsuneRal KitsuneRal deleted the kitsune-traceable-events branch January 10, 2017 22:41
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

Successfully merging this pull request may close these issues.

2 participants