Skip to content

Commit 6cead8e

Browse files
committed
fix for accidental modification
1 parent 52e780a commit 6cead8e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

BinarySearch/src/BinSearch.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,24 @@ class BinSearch {
66
@ ensures 0 <= \result < a.length;
77
@ ensures a[\result] == v;
88
@ assignable \nothing;
9+
@ also
10+
@ private exceptional_behavior
11+
@ requires !(\exists int idx; 0 <= idx < a.length; a[idx] == v);
12+
@ assignable \nothing;
13+
@ signals_only RuntimeException;
914
@*/
1015
private int binSearch(int[] a, int v) {
1116
int low = 0;
1217
int up = a.length;
1318

19+
/*@ loop_invariant 0 <= low <= up <= a.length;
20+
@ loop_invariant (\forall int x; 0 <= x < low; a[x] != v);
21+
@ loop_invariant (\forall int x; up <= x < a.length; a[x] != v);
22+
@ assignable \nothing;
23+
@ decreases up - low;
24+
@*/
1425
while (low < up) {
15-
int mid = (low + up) / 2;
26+
int mid = low + ((up - low) / 2);
1627
if (v == a[mid]) {
1728
return mid;
1829
} else if (v < a[mid]) {

0 commit comments

Comments
 (0)