This is really a tricky problem to spot. :) Everyone is focused on the code inside the brackets and the missing "else" is not being observed very fast.
> Email-style angle brackets
> are used for blockquotes.
> > And, they can be nested.
> #### Headers in blockquotes
>
> * You can quote a list.
> * Etc.
Horizontal Rules
Three or more dashes or asterisks:
---
* * *
- - - -
Manual Line Breaks
End a line with two or more spaces:
Roses are red,
Violets are blue.
Fenced Code Blocks
Code blocks delimited by 3 or more backticks or tildas:
```
This is a preformatted
code block
```
Header IDs
Set the id of headings with {#<id>} at end of heading line:
## My Heading {#myheading}
Tables
Fruit |Color
---------|----------
Apples |Red
Pears |Green
Bananas |Yellow
Definition Lists
Term 1
: Definition 1
Term 2
: Definition 2
Footnotes
Body text with a footnote [^1]
[^1]: Footnote text here
Abbreviations
MDD <- will have title
*[MDD]: MarkdownDeep
FUTURE POSTS
RavenDB 7.1: Next-Gen Pagers - 5 days from now
RavenDB 7.1: Write modes - 7 days from now
RavenDB 7.1: Reclaiming disk space - 9 days from now
RavenDB 7.1: Shared Journals - 12 days from now
There are posts all the way to Feb 17, 2025
RECENT SERIES
Challenge
(77): 03 Feb 2025 - Giving file system developer ulcer
Answer
(13): 22 Jan 2025 - What does this code do?
Comments
Yay scoping braces!
Ha ha, it's quite subtle, but so obvious once you spot it.
I think there is something 'else' missing ;-)
Missing else?
LOL, I didn't saw it either
Not to mention the sheer lunacy of mid not being related to target in any discernable way. Ugh.
(oh, yeah, and missing else)
Apart from missing else, what about arithmetic overflow?
I would change the line: var mid = (left + right + 1) / 2;
to this: var mid = left + (right - left + 1) / 2;
You still get the same result, but it's a little bit safer for higher values.
The bug aside, I'd use checked((left + right + 1) / 2).
Another potential problem: behavior of comparator might be not aligned with subtraction, so that
_comparator.Compare(mid-1, mid) >=0
This is really a tricky problem to spot. :) Everyone is focused on the code inside the brackets and the missing "else" is not being observed very fast.
Sorry to dissapoint, took me a second.
Anyway, I don't belive in scoping braces when they contain 1 line, it's not safer and not easier to read.. just redundant.
Comment preview