-
Notifications
You must be signed in to change notification settings - Fork 309
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
Feature request: incremental sort #508
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An incremental sort would make an excellent addition to itertools's lazy iterator model.
The basic idea of an incremental sort is that you can sort the sequence one element at a time, where the cost of extracting each individual element is only (approximately)
O(log(k))
, wherek
is the number of elements that have already been extracted. For instance:Let's say the predicate
pred
returns half of all elements it's given. This means that thesorted_incremental
only has to emit the first 200 elements or so when the finalresult
is evaluated, rather than having to sort the whole list. Better still, a good algorithm can do this partial sort inO(N + k log(k))
, whereN
is the total size of the list andk
is the number of extracted, sorted elementsA more formal definition of the problem can be seen here and one person's sample C++ implementation here
(Adapted almost verbatim from immutable-js/immutable-js#908)
The text was updated successfully, but these errors were encountered: