Skip to content

Commit cca6d41

Browse files
Add a model for String.hashCode
This is very similar to the original code.
1 parent 0e6413d commit cca6d41

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/main/java/java/lang/String.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,13 +2087,16 @@ public boolean endsWith(String suffix) {
20872087
*
20882088
* @return a hash code value for this object.
20892089
*
2090-
* @diffblue.limitedSupport
2091-
* We guarantee that two strings with different hash code have different
2092-
* content, but the exact value will not correspond to the actual one.
2090+
* @diffblue.limitedSupport length of the string is limited by unwind value
20932091
*/
20942092
public int hashCode() {
2095-
// DIFFBLUE MODEL LIBRARY This is treated internally in CBMC
2096-
return CProver.nondetInt();
2093+
// DIFFBLUE MODEL LIBRARY
2094+
int len = length();
2095+
int h = 0;
2096+
for (int i = 0; i < len; i++) {
2097+
h = 31 * h + CProverString.charAt(this, i);
2098+
}
2099+
return h;
20972100
// int h = hash;
20982101
// if (h == 0 && value.length > 0) {
20992102
// char val[] = value;

0 commit comments

Comments
 (0)