Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 WeightedIndexTree to rand_distr #1372
Add WeightedIndexTree to rand_distr #1372
Changes from 15 commits
a7aa746
191a1fe
3672f22
b20ac94
f90661e
8188aa9
42e2123
0eb69d4
b00c785
75c150f
30866d6
3b6229e
45a03ac
bca832d
7a0e234
a23e842
c8e5e35
689ac48
57158b7
e459645
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
We don't usually implement
Distribution<Result<..>>
. Do we need to?I think I would prefer to panic on error, but guarantee no panic if
self.is_valid()
(self.can_sample()
).@vks?
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 removed the Result<>, so sample now panics instead. I added the info about
is_valid
to the doc string and introducedsafe_sample
as an alternative that does not panic.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.
If I understand correctly, this must be strictly > 0?
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.
As an intermediate state, this can be zero if all weights are zero or there are no elements.
is_valid
would then returnfalse
. Allowing this is useful, so that the user does not have to apply the updates in the right order to avoid intermediate zero states.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.
In this case the function will already have returned an error.
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.
Sorry I mixed up what this comment was referring to.
I think
target_weight
can be0
in this line, for example: if we have a tree with only one node andgen_range
samples0
, then theloop
block is a no-op and after we hit this line withtarget_weight = 0
.However, I realized the line right after was incorrect, it should be:
assert!(target_weight < self.get(index))
. Should be correct now.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 agree