as3 binary search
No notes
Syntax:
ActionScript 3
public function binarySearch(keys:Array, target:int):int { var high:int = keys.length; var low:int = -1; while (high - low > 1) { totalHops++; var probe:int = (low + high) >>> 1; // Bit operations helps to speed up the process if (keys[probe] > target) { high = probe; } else { low = probe; } } return (low == -1 || keys[low] !== target) ? -1 : low; }