You forgot to catch the overflow bug in your midpoint calculation. `(l + r) / 2` can overflow because you're adding 2 variable integers. Instead you can use `l + (r - l) / 2` which is safu from overflow as long as you know that l < r, which you do in this case.
Thank you so much for your videos. I am starting on rust and i am learnign a lot from your videos. I sincerely hope you can continue making more. one small thing to call out, probably also needs double checking from you is that, when we define the input parameter as `AsRef`, we need to be cautious that the function still takes ownership from the input parameter. So in this case, using the function you have defined in the video, once a vector is used for binary search, it is no longer usable. I think if that is right, then from the design perspective, it may be better to make the input parameter simply &[T]?
@@nyxtom understood if within your program you are going to return from more than one location you have to use return in all them except the default one. Thanks
You forgot to catch the overflow bug in your midpoint calculation. `(l + r) / 2` can overflow because you're adding 2 variable integers. Instead you can use `l + (r - l) / 2` which is safu from overflow as long as you know that l < r, which you do in this case.
Just a tip dont use else on an if statement with a return. other than that cool stuff did not know about cmp
can you share your setup details, which extension is it with neovim.
Thank you so much for your videos. I am starting on rust and i am learnign a lot from your videos. I sincerely hope you can continue making more.
one small thing to call out, probably also needs double checking from you is that, when we define the input parameter as `AsRef`, we need to be cautious that the function still takes ownership from the input parameter. So in this case, using the function you have defined in the video, once a vector is used for binary search, it is no longer usable.
I think if that is right, then from the design perspective, it may be better to make the input parameter simply &[T]?
You deserve more subs pal ...such great content.
Thanks a lot for your explanation. I tried this code and found that the case when L equals R is not handled. I guess this case is possible.
how did you structured your code so you can have the tests in a total separated directory?
Can you please tell if instead of "return Some(mid);" when i used "Some(mid)" it gave error. Why?
@@nyxtom understood if within your program you are going to return from more than one location you have to use return in all them except the default one.
Thanks