From: "Dougie Lawson" <dl1...@gmail.com> Sent: Monday, October 21, 2013 10:32 PM
If I have a table of 3,500 entries of twelve bytes (I'm doing a compare of eight bytes to find the entry I'm looking for and a check on a half word marker for the end of the table to avoid running off the end) then is it worth the pain of re-writing it as a binary search. If it is worth the pain and does anyone have a sample binary search tucked away. The table is built into a CSECT at the bottom of my code. I can restructure it if we need any special pointers to make a binary search work.
This may help:- Array c has lower bound 0, upper bound n: i = -1; k = n+1; /* pointers that always point beyond the smallest and largest values */ do while (i+1 < k); m = isrl(i+k,1); if c(m) > j then k = m; else if c(m) < j then i = m; else return (m); /* element found */ end; return (-1); /* element not found. */