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

Global compare FCI should be saved and restored (allowing nested comparators) #48

Open
rtheunissen opened this issue Aug 30, 2016 · 10 comments
Assignees
Milestone

Comments

@rtheunissen
Copy link
Member

All structures share the same global FCI, so if while sorting something you try to sort something else, things will break. The best way to handle this is to save the current FCI, use it, then restore it.

@rtheunissen rtheunissen added this to the 2.0.0 milestone Aug 30, 2016
@rtheunissen rtheunissen self-assigned this Aug 30, 2016
@nikic
Copy link
Contributor

nikic commented Aug 30, 2016

Why does this need a global at all?

@rtheunissen
Copy link
Member Author

Because we need to call a user function inside a comparator (C function pointer).

@nikic
Copy link
Contributor

nikic commented Aug 30, 2016

Why can't it be passed along as a context pointer? As you aren't using zend_hash_sort, you shouldn't be limited by a context-free comparator.

@rtheunissen
Copy link
Member Author

I don't believe qsort supports a context parameter.

@nikic
Copy link
Contributor

nikic commented Aug 30, 2016

Huh, you're right. I could have sworn there was a qsort_ex variant, but looks like there isn't :(

@rtheunissen
Copy link
Member Author

There is, but it's not standard. I wonder how plausible it is to implement quick sort manually.

@morrisonlevi
Copy link

morrisonlevi commented Dec 2, 2016

There are two variants commonly found: qsort_r and qsort_s. Sadly the APIs aren't quite the same even though they are supporting the same idea: add a context parameter.

Perhaps we could use this: https://github.com/noporpoise/sort_r. It is in the public domain, so no issue there.

@rtheunissen
Copy link
Member Author

@morrisonlevi interesting idea, would be very easy to just nab that header file and include it. I like.

@rtheunissen
Copy link
Member Author

Coming back to this 2 years later, do we think that a third party sort is still the way to go?

@rtheunissen
Copy link
Member Author

@morrisonlevi the sort_r lib you linked falls back to their own quicksort implementation, but uses qsort_r if it is available. Seems reasonable to me to just include that header then. Might look for some others too..

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

No branches or pull requests

3 participants