-
Notifications
You must be signed in to change notification settings - Fork 76
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
Implement stable sorting for events #84
base: master
Are you sure you want to change the base?
Conversation
#define SORT_CMP(x,y) compare((x).timestamp, (y).timestamp) | ||
#include "sort/sort.h" | ||
|
||
void events_sort(struct tdb_grouped_event *buf, uint64_t num_events) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you use 4 space indents for consistency with the existing codebase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
I tested this PR with simple dumps Looks good to me. Thanks @rasky. |
Currently, TrailDB sorts internal events using libc's
qsort
function, which is not stable. This means that events with identical timestamp will be reordered, which is especially confusing in case the user is feeding already-sorted data.This patch implements stable sorting through
timsort
.NOTE: timsort is potentially very good with pre-sorted data, but we don't get to exploit that because events are being reversed (somewhere in the code coming up to the point being patches). A possible further improvement is to fix this, so that timsort sees pre-sorted data and goes faster.