Skip to content

Commit

Permalink
fix for accidental modification
Browse files Browse the repository at this point in the history
  • Loading branch information
unp1 committed Sep 10, 2024
1 parent 52e780a commit 6cead8e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion BinarySearch/src/BinSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,24 @@ class BinSearch {
@ ensures 0 <= \result < a.length;
@ ensures a[\result] == v;
@ assignable \nothing;
@ also
@ private exceptional_behavior
@ requires !(\exists int idx; 0 <= idx < a.length; a[idx] == v);
@ assignable \nothing;
@ signals_only RuntimeException;
@*/
private int binSearch(int[] a, int v) {
int low = 0;
int up = a.length;

/*@ loop_invariant 0 <= low <= up <= a.length;
@ loop_invariant (\forall int x; 0 <= x < low; a[x] != v);
@ loop_invariant (\forall int x; up <= x < a.length; a[x] != v);
@ assignable \nothing;
@ decreases up - low;
@*/
while (low < up) {
int mid = (low + up) / 2;
int mid = low + ((up - low) / 2);
if (v == a[mid]) {
return mid;
} else if (v < a[mid]) {
Expand Down

0 comments on commit 6cead8e

Please sign in to comment.