-
Notifications
You must be signed in to change notification settings - Fork 2
feat(algorithms design, data-structures): continuous median #166
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
Conversation
📝 WalkthroughWalkthroughThis PR introduces a new ContinuousMedianHandler class that maintains a running median using two heaps (max-heap for lower half, min-heap for upper half). The implementation includes insert and get_median methods, accompanied by test coverage and documentation updates in DIRECTORY.md. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@DIRECTORY.md`:
- Around line 591-592: The new list entry under "Continuous Median" has
incorrect indentation causing MD007; adjust the bullet for "[Test Continuous
Median Handler]" to be a nested list item (two spaces before the asterisk) so it
aligns under the "Continuous Median" parent bullet, ensuring list depth is
consistent with surrounding entries.
🧹 Nitpick comments (2)
design_patterns/continuous_median/test_continuous_median_handler.py (2)
6-10: Normalize test case shape to simplify inputs.The current nested tuple/list structure is hard to read. Consider representing each step as
(list_of_ints, expected)inside a singlerequestslist.♻️ Suggested test case shape
-CONTINUOUS_MEDIA_HANDLER_TESTS = [ - ( - ([(1, 2), 1.50000], [(3), 2.00000]), - ), -] +CONTINUOUS_MEDIA_HANDLER_TESTS = [ + ( + [([1, 2], 1.5), ([3], 2.0)], + ), +]
15-23: Streamline the loop once inputs are consistent.With the normalized cases above, you can remove the type branch and iterate uniformly.
♻️ Simplified loop and type hint
- def test_continuous_median_handler(self, requests: List[Tuple[List[Tuple[int]] | int, int | float]]): + def test_continuous_median_handler(self, requests: List[Tuple[List[int], int | float]]): median_handler = ContinuousMedianHandler() - for request in requests: - data, expected = request - if type(data) is int: - median_handler.insert(data) - else: - for d in data: - median_handler.insert(d) + for data, expected in requests: + for value in data: + median_handler.insert(value) actual = median_handler.get_median() self.assertEqual(expected, actual)
Describe your change:
Continuous median using two heaps
Checklist:
Fixes: #{$ISSUE_NO}.Summary by CodeRabbit
New Features
Documentation
Tests
✏️ Tip: You can customize this high-level summary in your review settings.