-
Notifications
You must be signed in to change notification settings - Fork 6
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
Bit testing can use unsafeRead because the length was verified #24
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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 we would also need to check that
bitIx >= 0
for this to be safe-ish. If you pass in a negative index, this could be very bad. Perhaps the bug is that the API takes an index using a signed type.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 general, I am saddened that so much of the prelude and containers uses Int instead of Natural. Any index, the length, the initial size, etc. should all be Natural but are all Ints. I've used Natural in other places, but it does add some noise because there's a need to convert between Natural and Int in [lots of places to impedance match with the stuff that is written to use Int.
I think this is actually safe in practice because this is an internal module that is not exported to users, and it's only used from Algorithms.DFS as the latter iterates through graph elements (practically speaking, even the
bigIx >= size
should be unnecessary based on the usage).I considered switching this interface to Nat, but it's using the
vertexId
, so either DFS is callingtoEnum
on all these so that BitSet can almost immediately callfromEnum
to invoke thefromEnum
to call theVector
operations, or theVertex
type changes to aNatural
(and although it's supposed to be internal, it's visible and a much bigger change, and it still needs thefromEnum
to call theVector
operations).In fact, I switched the other read in this file to unsafe, then I benchmarked, the original safe, the unsafe in this PR, and a unsafe Nat version with the fromEnum/toEnum I discussed above. I'll email the
criterion
HTML separately. tl;dr Nat+unsafe is 33% slower than unsafe, and safe is 25% slower than unsafe.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 had forgotten that this was an internal-only module.
In that case, what if we just renamed this to
unsafeSetBit
andunsafeTestBit
and even removed the bounds check?I was going to say that the only uses do their own checking, but that is not entirely true. If you mix vertices from another graph, you could hit an error (and we don't have any type-level enforcement of that). It looks like it would be safe if we just filtered the root
[Vertex]
inputs in the DFS module.