Created
November 27, 2020 10:58
-
-
Save wadoon/4292b3679816eb280566e9cdda9f7779 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*@ normal_behaviour | |
@ requires true; | |
@ ensures \result <==> (\exists int i; 0 <= i && i < arr.length; arr[i] != id); | |
@ assignable \strictly_nothing; | |
@*/ | |
private boolean contains(int[] arr, int id) { | |
/*@ loop_invariant (\forall int k; 0 <= k && k < i; arr[k] != id); | |
@ loop_invariant 0 <= i && i <= arr.length + 1; | |
@ | |
@ decreases arr.length - i; | |
@ assignable \strictly_nothing; | |
@*/ | |
for(int i = 0; i < count; i++) { | |
if(emails[i] == id) { | |
//! i \witness_for arr[i]==id | |
return true; | |
} | |
} | |
return false; | |
} | |
/*@ normal_behaviour | |
@ requires true; | |
@ ensures \result <==> (\exists int i; 0 <= i && i < arr.length; arr[i] != id); | |
@ ensures \result >= 0 ==> (emails[\result] == id && \result < count); | |
@ assignable \strictly_nothing; | |
@*/ | |
private int containsEasier(int[] arr, int id) { | |
/*@ loop_invariant (\forall int k; 0 <= k && k < i; arr[k] != id); | |
@ loop_invariant 0 <= i && i <= arr.length + 1; | |
@ | |
@ decreases arr.length - i; | |
@ assignable \strictly_nothing; | |
@*/ | |
for(int i = 0; i < count; i++) { | |
if(emails[i] == id) { | |
return i; | |
} | |
} | |
return i; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment