Commit 6b8617b
committed
Add shar's algorithm
This is based on the D version by Alex Muscar, which was based on an
implementation in Writing Efficient Programs by Jon L. Bentley. It was
originally published by Knuth and is attributed to Shar.
https://muscar.eu/shar-binary-search-meta.html
Previously, I had mistaken the monobound binary search for a loop
version of Shar's algorithm, but after looking at them more deeply, I
realize that they are subtly different.
On my Ryzen 7 5800X, this will outperform the monobound binary search on
array sizes that are powers of 2 or near powers of 2.
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>1 parent ff7c12a commit 6b8617b
1 file changed
+34
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
523 | 524 | | |
524 | 525 | | |
525 | 526 | | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
526 | 557 | | |
527 | 558 | | |
528 | 559 | | |
| |||
683 | 714 | | |
684 | 715 | | |
685 | 716 | | |
| 717 | + | |
686 | 718 | | |
687 | 719 | | |
688 | 720 | | |
| |||
701 | 733 | | |
702 | 734 | | |
703 | 735 | | |
| 736 | + | |
704 | 737 | | |
705 | 738 | | |
706 | 739 | | |
| |||
726 | 759 | | |
727 | 760 | | |
728 | 761 | | |
| 762 | + | |
729 | 763 | | |
730 | 764 | | |
731 | 765 | | |
| |||
0 commit comments