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

Prototype out IntervalHeap or std's BinaryHeap with a comparator-based API #16

Closed
Gankra opened this issue Nov 30, 2014 · 3 comments
Closed

Comments

@Gankra
Copy link
Owner

Gankra commented Nov 30, 2014

This would allow a heap to be reinterpretted as min/max without affecting the consumer of the collection (no wrapping the data to redefine Ord). It may also be the future of searching in maps/sets. However Heaps are a good simple place to test the ideas out on.

See this PR for preliminary work done in the area. It got blocked on unboxed closures becoming more coherent, which is now the case.

Ideally comparators would be part of the type, with a default Natural Comparator that just uses Ord. A Reverse Comparator would also be useful, in the same vein as the Reverse iterator adaptor. We could also consider providing a Fake Comparator for wrapping PartialOrd impls unsafely.

Unboxed closures that return Ord should presumably work as Comparators.

CC @huonw @sellibitze @aturon @reem

@reem
Copy link
Collaborator

reem commented Dec 1, 2014

This could probably be done with a:

trait Comparator<T> {
    fn cmp(T, T) -> Ordering;
}

and a default type param to an implementation that just forwards from Ord on all the necessary collections. Then you just need a blanket impl for closures of the right type...

@Ericson2314
Copy link

It must be part of the type for unions (and other binary functions) to be safe and fast. Could Comparator<T> be an alias of Fn instantiated with the right arguments, or would that cause coherence issues?

@Gankra
Copy link
Owner Author

Gankra commented Jan 2, 2015

@apasel422 knocked this outta the park

@Gankra Gankra closed this as completed Jan 2, 2015
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

3 participants