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

Views, sort_copy, online algorithms... #42

Open
Morwenn opened this issue Dec 17, 2015 · 3 comments
Open

Views, sort_copy, online algorithms... #42

Morwenn opened this issue Dec 17, 2015 · 3 comments

Comments

@Morwenn
Copy link
Owner

Morwenn commented Dec 17, 2015

cpp-sort currently only cares about in-place sorting algorithms: algorithms that mutate the passed collection and don't return anything (except when they do), which is pretty much enough for people most of the time. However, I believe that there is some value in having algorithms that actually copy a sorted equivalent of the passed collection into the library. It once again leads to maaaaany design decisions depending on how we want to implement that:

  • Have a cppsort::sort_copy function in the library taking a sorter (or defaulting to default_sorter) and an additional OutputIterator parameter?
  • Provide an equivalent cppsort::sort_move function?
  • Create a cppsort::sorted function that takes an iterable and returns a new instance of the same iterable? Make it work with an OutputIterator instead? Have it take any sorter like cppsort::sort?
  • Add a cppsort::sorted_view returning a range with sorted iterators which, when iterated, corresponds to a sorted view of the original collection? It's pretty much what indirect_adapter does in the first place, but decoupling it from the adapter might also be interesting.
  • Have first-class support for online sorting algorithm? Adding an is_online property in cppsort::sorter_traits is easy, but how to use it properly?

An interesting algorithm about incremental sort that might provide some idea and/or insights about online/incremental sorting: http://larshagencpp.github.io/blog/2016/04/23/fast-incremental-sort

Morwenn added a commit that referenced this issue Jan 7, 2017
Currently, cpp-sort only offers an in-place sorting interface. There are
plans to work on a sort_copy interface, but not right now (issue #42),
hence I removed everything related to ska_sort_copy.

The fallback of ska_sort was change to pdq_sort instead of std::sort to
offer a better fallback algorithm, and to ensure that proxy iterators work
as expected with ska_sort.
@Morwenn
Copy link
Owner Author

Morwenn commented Dec 6, 2018

For sort_copy algorithms, one interesting solution would be to take advantage of the fact that sorters are function objects to provide a copy or copy_to method:

cppsort::ska_sort.copy(collection, std::back_inserter(res));

I don't know whether it's a good idea. Like everything else I will have to balance the pros and cons.

@Morwenn
Copy link
Owner Author

Morwenn commented Nov 13, 2019

What I called a sorted "view" in the original post can't be a View according to the standard concept semantics because views are supposed to have O(1) construction and linear traversal. A "sorted view" would either be sorted at construction in O(n log n) time or would use an online algorithm and have O(n log n) traversal. No matter what I do with this issue I should use another terminology.

@Morwenn
Copy link
Owner Author

Morwenn commented Nov 6, 2022

A few updates regarding the concerns discussed in this issue:

The other points are still very much open design issues without obvious answers to this day. To keep the genericity of the collection/compare/projection design without getting too complicated, I'd probably need to invent a way to give a separate channel for output range parameters somehow.

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

1 participant