-
Notifications
You must be signed in to change notification settings - Fork 270
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
Add lazy segment tree #539
base: main
Are you sure you want to change the base?
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #539 +/- ##
=============================================
- Coverage 98.528% 96.785% -1.743%
=============================================
Files 32 34 +2
Lines 4010 4418 +408
=============================================
+ Hits 3951 4276 +325
- Misses 59 142 +83
|
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.
Run same tests of OneDimensionalArraySegmentTree
with the new one. Put all tests into common function and pass objects of OneDimensionalArraySegmentTree
and OneDimensionalArraySegmentTreeLazy
to the common function.
I am trying to design the method parameters such that I can generalize the implementation but since lazy updates for each of the different applications have different implementation, I am unable to find a common design. |
Share some examples so that we can figure something out. |
Suppose we are solving an range sum update problem where we want to increment all the elements in the range |
self._update_range(node.right, lazy_node.right, mid + 1, end, l, r, value) | ||
node.data = self._func((node.left.data, node.right.data)) | ||
|
||
def update_range(self, start, end, value): |
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.
def update_range(self, start, end, value): | |
def update(self, start, end, value): |
self._update_range(self._root, self._lazy_node, 0, len(self._array) - 1, | ||
start, end, value) | ||
|
||
def update(self, index, value): |
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.
def update(self, index, value): | |
def __setitem__(self, index, value): |
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.
Same for the parent class.
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.
I think right now the case is update
for a single value and update_range
for a range. I think we discussed to use __setitem__
to update a single value. However, for a range we will use update
. So please do it.
So you want me to rename |
References to other Issues or PRs or Relevant literature
Brief description of what is fixed or changed
Other comments