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

In the C implementation, is Test::index required? #7

Closed
lh3 opened this issue Mar 15, 2014 · 2 comments
Closed

In the C implementation, is Test::index required? #7

lh3 opened this issue Mar 15, 2014 · 2 comments

Comments

@lh3
Copy link

lh3 commented Mar 15, 2014

In the C implementation, the type is defined as typedef struct { int value, index; } Test. Is Test::index required or is it just for the testing purpose? If we are allowed to add an index field to the array, it is trivial to achieve stable sort with any sorting algorithms, by using a comparison function

#define stable_lt(a,b) ((a).value < (b).value || ((a).value==(b).value \
                        && (a).index<(b).index))

to break any ties, but this is not the true in-place stable sort.

@BonzaiThePenguin
Copy link
Owner

The index is only there so it has some way of verifying that the sort was stable. It's only used by the Verify function, not Sort.

@lh3
Copy link
Author

lh3 commented Mar 15, 2014

Thanks. Make sense.

@lh3 lh3 closed this as completed Mar 15, 2014
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

2 participants