Skip to content

Commit

Permalink
added getHashCode for diagnostics of hash collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Jan 8, 2024
1 parent 7338b14 commit 6019038
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/org/rascalmpl/library/util/Reflective.java
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ public IInteger getFingerprintNode(INode nd){
return values.integer(ToplevelType.getFingerprintNode(nd));
}

public IInteger getHashCode(IValue v) {
return values.integer(v.hashCode());
}

public void throwNullPointerException() {
throw new NullPointerException();
}
Expand Down
11 changes: 11 additions & 0 deletions src/org/rascalmpl/library/util/Reflective.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,17 @@ public java int getFingerprint(value val, int arity, bool concretePatterns);
@javaClass{org.rascalmpl.library.util.Reflective}
public java int getFingerprintNode(node nd);

@synopsis{Get the internal hash code of a value. For the benefit of debugging the Rascal implementation.}
@description{
This function is useless for Rascal programmer's as it is a part of the under-the-hood implementation of values.
You can use a value directly as a lookup key. The internal data-structures probably use this hashCode for
optimal lookups in `O(log(size))`.
We use this function to diagnose possible performance issues caused by hash collisions.
}
@javaClass{org.rascalmpl.library.util.Reflective}
public java int getHashCode(value v);

@synopsis{Throw a raw Java NullPointerException, to help simulate an unexpected exception in test scenarios}
@javaClass{org.rascalmpl.library.util.Reflective}
java void throwNullPointerException();
Expand Down

0 comments on commit 6019038

Please sign in to comment.