-
Notifications
You must be signed in to change notification settings - Fork 318
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Extend k_smallest with largest and key options #586
Comments
If this has a good chance of being accepted I'm willing to make a pull request for this feature. |
Sounds great to me! If you decide to do a PR, could you try to implement |
This has a great chance of getting merged! 🙂 |
Am I understanding it correctly that there's a bug in the current implementation? https://github.com/rust-itertools/itertools/blob/master/src/k_smallest.rs#L10 This assumes the iterator is a EDIT: yes, this is wrong: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=cc076206949046426a9d76dc005368b1 |
Looking at it, I don't see a way we could implement this using |
Or skip the |
I guess your problem is that Copying the sifting logic might be a viable solution (unless it's a huge amount of code). I think we already did something similar (see https://github.com/rust-itertools/itertools/blob/master/src/unziptuple.rs#L42-L46). If you decide to go that route, please add documentation in a similar fashion. |
An alternative solution to #654 would be to use the binary_heap_plus crate which supports custom comparison functions. One problem is their MSRV is 1.56 compared to Itertool's 1.32. I haven't looked into it but it might be possible to make their crate more backwards compatible. It would keep the implementations within this crate much smaller. For example (not exactly the same API): https://github.com/Alextopher/advent-of-code-2022/blob/main/aoc/src/iterstuff.rs#L29 |
Currently this crate only has
k_smallest
. Compare this to the offering formin
/max
(which are the same function, just limited to k = 1):I think it would be nice if we extended
k_smallest
to:The text was updated successfully, but these errors were encountered: