-
Notifications
You must be signed in to change notification settings - Fork 310
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
docs: fixup docs of tree_fold1
#787
Conversation
@scottmcm I believe you wrote |
I would say the different behaviour for non-associative cases is entirely the point of If you have something truely associative, like But even with something only slightly non-associative like See also the string format bench ( itertools/benches/tree_fold1.rs Line 57 in 7a6c1ef
|
Ok yeah, I see what you mean. Thanks for the explanation. I think I missed some things before. Let's take a closer look at all the possible cases:
Both of the non-associative cases should be neglacted in my opinion. |
One particular place where this can be really useful is in building binary trees. Compare the outputs in https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f6a580a37e0a01b1c94767680dd444ca -- using I don't know a great way to fit that example into a doc comment, though :/ |
Just did a very basic test on compiler explorer and both To see this you need to scroll down all the way on the right hand side window. The generated assembly code is color coded the same way as the related rust code. |
Never use I suggest comparing summing up a slice, where you'll see, for example, that the normal They're very very different things once you're not doing something that's not just a constant. |
I guess my understanding of all of this is just lacking then. I'll just close the issue. Thanks a lot for the extra explanation, that was helpful! And sorry for the needless discussion |
No, the discussion is good! It'd be great if you could find a nice way to reflect this difference into the documentation, to help the next person who's wondering why the method exists. |
Thanks for the positive feedback :) Ok, then let me know which parts I should put the highlights on! The different use cases of |
@scottmcm I adjusted the docs once again. Does this come closer to an acceptable explanation? 😅 |
bump to not forget this issue as it's also not that big of an issue 😅 |
Some of this doesn't seem right to me, and the docs now seem a bit confusing, if not inaccurate. Specifically:
Both I think what this is trying to get at is that if
* Not necessary, but sufficient. |
I'm sorry if I made the docs less correct. I can look into this when I find the time again. Otherwise feel free to open a PR yourself |
I was just reading through the docs when I noticed something odd. It's probably just a typo:
There is a recommendation to use
reduce
instead oftree_fold1
whenf
is associative. Sincetree_fold1
won't really work as expected (unless you know what you're doing) in non-associative cases, this would imply that we don't recommend the use oftree_fold1
at all?I just took a guess and adjusted that part of the docs to what it most likely was supposed to be. Feel free to close this PR if I'm completely wrong here 🙈