-
Notifications
You must be signed in to change notification settings - Fork 161
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
Implement PositionsBound. #2223
Conversation
FYI, |
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.
Thanks for your contribution! Here are some further remarks.
lib/list.gd
Outdated
@@ -1002,6 +1002,34 @@ DeclareOperation( "PositionsProperty", [ IsList, IsFunction ] ); | |||
DeclareOperation( "PositionBound", [ IsList ] ); | |||
|
|||
|
|||
############################################################################# | |||
## | |||
#O PositionsBound( <list> ) . . . . position of first bound element in a list |
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.
That summary does not seem to fit what the function does -- it returns all bound positions, no?
lib/list.gd
Outdated
## | ||
## <#GAPDoc Label="PositionsBound"> | ||
## <ManSection> | ||
## <Oper Name="PositionsBound" Arg='list'/> |
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.
This function will not turn up in the manual unless you explicitly include it in one of the doc/ref/*.xml
files. It would hence stay undocumented for endusers.
lib/list.gd
Outdated
## <Oper Name="PositionsBound" Arg='list'/> | ||
## | ||
## <Description> | ||
## returns the set of all indices for which an element is bound in the list |
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.
This sounds slightly off to me... perhaps "returns the set of all indices of the list which are bound to an element" ?
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 oriented myself on the documentation of PositionProperty just above. Should I change that as well (if I'm already at it)?
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.
Sure. Though we might also want to get another opinion by a native speaker like @ChrisJefferson or @stevelinton
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 not sure which is better. I don't really like "indices which are bound" since it isn't really the indices which are bound, but the corresponding list positions. "indices for which an element is bound in the list" is a little convoluted, but precise. Neither is genuinely likely to be confusing.
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.
How would you like "the set of all bound positions of the list"?
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.
Done.
816a4c6
to
3440f3f
Compare
Codecov Report
@@ Coverage Diff @@
## master #2223 +/- ##
==========================================
+ Coverage 70.34% 70.34% +<.01%
==========================================
Files 481 481
Lines 253181 253190 +9
==========================================
+ Hits 178091 178102 +11
+ Misses 75090 75088 -2
|
I guess that with the hint to Let me nevertheless add three comments, the first two are minor, the third is not: (1) It is a general observation that in (2) Why don't you use (3) Efficient functions for lists must be implemented as functions, not methods, to avoid method selection overhead for lists. Example: While your function is faster for the example in the first post, try this:
I have not waited for an answer (probably you need to wait a few hours). |
It is probably not completely moot (since the use of PositionsProperty to check for bound entries is kind of obscure). But I do not know if one of these options (either replace the body of the code by PositionsProperty or document the use of PositionsProperty) is the preferred option of most of the developers. If so, I'm happy to modify/retract this PR as needed. Concerning (2): I assumed that I will modify the PR in the way (3) suggests as soon as I know which option is preferred by the developers (i.e. whether this PR becomes moot). |
I am for adding a function for Note also that the
and |
Yes, I also think that having I also think that it improves code readability. People will either immediately guess what In that regard, I think it is similar to e.g. |
lib/list.gd
Outdated
## </ManSection> | ||
## <#/GAPDoc> | ||
## | ||
DeclareOperation( "PositionsBound", [ IsList ] ); |
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 Frank pointed out, this should be turned into a global function for optimal performance.
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 that case it should not refer back to PositionsProperty (since that is not a global function).
I would also like to add PositionsBound, I have needed this a few times, and always just write a for loop. I agree that it should be a global function. It could even just be (in my opinion) |
3440f3f
to
393f7ec
Compare
I also support adding this function. (I raised the question in my previous comment because I was unsure about the status of the discussion, and didn't want to imply that I'm against such a function.) Although the function is mainly intended to be called with lists that have holes, one could add efficient handling of dense lists:
|
393f7ec
to
8aedf98
Compare
Currently there is no library method to return the set of all bound entries of a list. This commit implements this functionality in an efficient manner.
8aedf98
to
18c42f1
Compare
Currently there is no library method to return the set of all bound
entries of a list. This commit implements this functionality in an
efficient manner.
To see the effect consider the following time difference: