diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-01-21 16:49:45 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-01-21 16:49:45 +0100 |
commit | 1ddfab95b71d41de868b5b2ad16c44efcc694373 (patch) | |
tree | 12620ad9ef841dfd9915bea5e8991c7b81f6d42f /src/algorithms/searching/BinarySearch.java | |
parent | partial array support in hybrid interpolation search (diff) | |
download | algorithms-and-data-structures-1ddfab95b71d41de868b5b2ad16c44efcc694373.tar.gz algorithms-and-data-structures-1ddfab95b71d41de868b5b2ad16c44efcc694373.tar.bz2 algorithms-and-data-structures-1ddfab95b71d41de868b5b2ad16c44efcc694373.tar.xz |
m + partial array support in hybrid binary search
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | src/algorithms/searching/BinarySearch.java | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/algorithms/searching/BinarySearch.java b/src/algorithms/searching/BinarySearch.java index c4e35a7..c4caaea 100644 --- a/src/algorithms/searching/BinarySearch.java +++ b/src/algorithms/searching/BinarySearch.java @@ -151,7 +151,7 @@ public class BinarySearch if (low > 0) return TOO_SMALL; - int high = £(cmp "array[1]" "item"); + int high = £(cmp "array[end - 1]" "item"); if (low == 0) return high == 0 ? EVERY_ELEMENT : start; @@ -163,13 +163,12 @@ public class BinarySearch if (low < 0) return TOO_SMALL; - int n = end - 1; - int high = £(cmp "array[n]" "item"); + int high = £(cmp "array[end - 1]" "item"); if (low == 0) return high == 0 ? EVERY_ELEMENT : start; - return high == 0 ? n : high > 0 ? TOO_LARGE : MAYBE; + return high == 0 ? end - 1 : high > 0 ? TOO_LARGE : MAYBE; } } |