Skip to content

Commit e08c071

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

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
@@ -1919,13 +1919,16 @@ public boolean endsWith(String suffix) {
19191919
*
19201920
* @return a hash code value for this object.
19211921
*
1922-
* @diffblue.limitedSupport
1923-
* We guarantee that two strings with different hash code have different
1924-
* content, but the exact value will not correspond to the actual one.
1922+
* @diffblue.limitedSupport length of the string is limited by unwind value
19251923
*/
19261924
public int hashCode() {
1927-
// DIFFBLUE MODEL LIBRARY This is treated internally in CBMC
1928-
return CProver.nondetInt();
1925+
// DIFFBLUE MODEL LIBRARY
1926+
int len = length();
1927+
int h = 0;
1928+
for (int i = 0; i < len; i++) {
1929+
h = 31 * h + CProverString.charAt(this, i);
1930+
}
1931+
return h;
19291932
// int h = hash;
19301933
// if (h == 0 && value.length > 0) {
19311934
// char val[] = value;

0 commit comments

Comments
 (0)