File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff 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 ]) {
You can’t perform that action at this time.
0 commit comments