Add ReservoirSampling algorithm to randomized module#6204
Add ReservoirSampling algorithm to randomized module#6204siriak merged 7 commits intoTheAlgorithms:masterfrom
Conversation
|
What if sampleSize > stream.length? Perhaps there should be error handling for invalid input, the rest lgtm |
|
✅ Added input validation for Let me know if anything else is needed — happy to improve further 🙌 |
siriak
left a comment
There was a problem hiding this comment.
The code looks good, could you please add some JUnit tests and remove main? You could check that the correct number of elements is returned, that they are all from the initial set, maybe other properties of the algorithm (see https://github.com/TheAlgorithms/Java/tree/master/src/test/java/com/thealgorithms)
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6204 +/- ##
============================================
- Coverage 73.78% 73.78% -0.01%
- Complexity 5299 5304 +5
============================================
Files 671 672 +1
Lines 18344 18357 +13
Branches 3546 3549 +3
============================================
+ Hits 13536 13545 +9
- Misses 4262 4265 +3
- Partials 546 547 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
✅ Applied clang-format and added JUnit test to All requested changes completed. Ready for final review 💪 |
siriak
left a comment
There was a problem hiding this comment.
Code looks good, please fix PR checks and it's ready to merge. Thank you for patience, I'm very busy at the moment so response times are high :)
|
✅ Final test file now formatted with CI will re-run shortly. Appreciate all the support — ready for merge when you are 💪 |
|
Error: /home/runner/work/Java/Java/src/main/java/com/thealgorithms/randomized/ReservoirSampling.java:19:1: Utility classes should not have a public or default constructor. [HideUtilityClassConstructor] |
|
✅ All requested changes are now complete:
Thanks again for your review and feedback. Ready for merge when you are. |
Algorithm Overview:
Implementation Details:
ReservoirSamplingcom.thealgorithms.randomizedmain()methodclang-formatReference:
Author: Michael Alexander Montoya (@cureprotocols)
clang-format -i --style=file path/to/your/file.java