-
Notifications
You must be signed in to change notification settings - Fork 180
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
Improve compare for IntSet and IntMap #1086
Conversation
1395871
to
4b2a3f0
Compare
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'm having trouble understanding why we need a fancy result type for the go
function. What's going on here?
For a lexicographical comparison of the elements it's not enough to use
then comparing the left branches ( |
|
The constructor names of the result in this context seem rather opaque to me. I assume this is reusing a type from somewhere else? Maybe we should make a new one. |
The type is introduced in this PR. The constructor names are from the previous attempt (7aff529), I don't mind changing them if you have suggestions. |
What names would you prefer @treeowl? |
97fcae1
to
8203980
Compare
Okay, this is good to go. |
Compare the trees directly instead of converting to lists. The implementation follows broadly the same approach as the previous attempt in commit 7aff529.
Greatly simplifies the top-level code.
8203980
to
030fb5e
Compare
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 that's much better, but a bit more documentation is in order.
-- instead and get the same Core. | ||
data Tip' = Tip' {-# UNPACK #-} !Int {-# UNPACK #-} !BitMap | ||
|
||
leftmostTipSure :: IntSet -> Tip' |
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.
Please add a Haddock string.
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.
Why? These functions are not exposed.
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.
My general philosophy is that every top level function and every non-trivial function should be fully documented. For leftmostTipSure
, I recognize that the name really gives it away, but I'm stubborn. orderTips
must surely have a documentable purpose, with some expectations about what its arguments will mean and some description of what its result means.
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 disagree. There is nothing to be gained by adding noise to internal functions with self-explanatory name+type.
If you insist on this please provide the doc strings you would like them to have.
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.
@treeowl do you still want to add doc strings?
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'll try to write one for compareTips
by tomorrow night. But otherwise I guess you can merge and I'll open an issue to remember.
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'll go ahead and merge it then.
leftmostTipSure (Tip k bm) = Tip' k bm | ||
leftmostTipSure Nil = error "leftmostTipSure: Nil" | ||
|
||
orderTips :: Int -> BitMap -> Int -> BitMap -> Order |
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.
Please add a haddock string.
Compare the trees directly instead of converting to lists.
The implementation follows broadly the same approach as the previous attempt in commit 7aff529.
Closes #470, closes #787.
Benchmarks with GHC 9.10:
Map
Set