Sample

int-218fb39999a3-SRC

Unmodified source class

Lines154

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.7520–1; higher is more readable
Dorn0.3240–1; higher is more readable
Mi0.6540–1; higher is more readable
LLOC69Logical lines; fewer is more readable
DeepSeek V4 Pro17.670–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.3480–1; higher is more readable

Views

Source code

package com.google.common.hash; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; import com.google.errorprone.annotations.Immutable; import java.io.InvalidObjectException; import java.io.ObjectInputStream; import java.io.Serializable; import java.nio.ByteBuffer; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Arrays; /** * {@link HashFunction} adapter for {@link MessageDigest} instances. * * @author Kevin Bourrillion * @author Dimitris Andreou */ @Immutable final class MessageDigestHashFunction extends AbstractHashFunction implements Serializable { @SuppressWarnings("Immutable") // cloned before each use private final MessageDigest prototype; private final int bytes; private final boolean supportsClone; private final String toString; MessageDigestHashFunction(String algorithmName, String toString) { this.prototype = getMessageDigest(algorithmName); this.bytes = prototype.getDigestLength(); this.toString = checkNotNull(toString); this.supportsClone = supportsClone(prototype); } MessageDigestHashFunction(String algorithmName, int bytes, String toString) { this.toString = checkNotNull(toString); this.prototype = getMessageDigest(algorithmName); int maxLength = prototype.getDigestLength(); checkArgument( bytes >= 4 && bytes <= maxLength, "bytes (%s) must be >= 4 and < %s", bytes, maxLength); this.bytes = bytes; this.supportsClone = supportsClone(prototype); } private static boolean supportsClone(MessageDigest digest) { try { Object unused = digest.clone(); return true; } catch (CloneNotSupportedException e) { return false; } } @Override public int bits() { return bytes * Byte.SIZE; } @Override public String toString() { return toString; } private static MessageDigest getMessageDigest(String algorithmName) { try { return MessageDigest.getInstance(algorithmName); } catch (NoSuchAlgorithmException e) { throw new AssertionError(e); } } @Override public Hasher newHasher() { if (supportsClone) { try { return new MessageDigestHasher((MessageDigest) prototype.clone(), bytes); } catch (CloneNotSupportedException e) { // falls through } } return new MessageDigestHasher(getMessageDigest(prototype.getAlgorithm()), bytes); } private static final class SerializedForm implements Serializable { private final String algorithmName; private final int bytes; private final String toString; private SerializedForm(String algorithmName, int bytes, String toString) { this.algorithmName = algorithmName; this.bytes = bytes; this.toString = toString; } private Object readResolve() { return new MessageDigestHashFunction(algorithmName, bytes, toString); } private static final long serialVersionUID = 0; } Object writeReplace() { return new SerializedForm(prototype.getAlgorithm(), bytes, toString); } private void readObject(ObjectInputStream stream) throws InvalidObjectException { throw new InvalidObjectException("Use SerializedForm"); } /** Hasher that updates a message digest. */ private static final class MessageDigestHasher extends AbstractByteHasher { private final MessageDigest digest; private final int bytes; private boolean done; private MessageDigestHasher(MessageDigest digest, int bytes) { this.digest = digest; this.bytes = bytes; } @Override protected void update(byte b) { checkNotDone(); digest.update(b); } @Override protected void update(byte[] b, int off, int len) { checkNotDone(); digest.update(b, off, len); } @Override protected void update(ByteBuffer bytes) { checkNotDone(); digest.update(bytes); } private void checkNotDone() { checkState(!done, "Cannot re-use a Hasher after calling hash() on it"); } @Override public HashCode hash() { checkNotDone(); done = true; return (bytes == digest.getDigestLength()) ? HashCode.fromBytesNoCopy(digest.digest()) : HashCode.fromBytesNoCopy(Arrays.copyOf(digest.digest(), bytes)); } } }

Loading feature diagnosis…

Source regions

Feature contributions

Feature contributions

FeatureValueContribution
(log-odds)
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.5008.496−165.28
Source linesThe number of non-empty source lines.154+61.6
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.4.765−7.148

Intercept 8.87 + feature contributions = -101.958 (log-odds).
Score = sigmoid(-101.958) = 0.

Score0.752

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.154−4.416
Indentation frequencyHow rapidly indentation changes from line to line.147+4.347
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.147−2.952
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.153.887+1.741
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.95.948+0.744
Identifier layout (horizontal)How rapidly the visual pattern of identifier characters changes from left to right. It measures spatial frequency, not the meaning of the names.95.961−0.399
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.084+0.13

Intercept 0.07 + feature contributions = -0.735 (log-odds).
Score = sigmoid(-0.735) = 0.324.

Score0.654
Score69
Run 1

The code is highly readable with excellent logical organization. The class structure is clear: an outer hash function adapter and an inner hasher implementation, with serialization concerns cleanly separated in a nested SerializedForm class. Nesting is minimal—only one level in the newHasher try/catch and in the hash() ternary. Each method has a single, clear purpose, and the intent is obvious from names like checkNotDone, supportsClone, and getMessageDigest. Lines are concise and actions are well-separated; constructors validate arguments and assign fields cleanly. The reading flow is natural, moving from construction to hashing to serialization. The static imports for checkArgument, checkNotNull, and checkState reduce verbosity without sacrificing clarity. The only slight complexity is the fall-through catch block in newHasher, but the comment 'falls through' makes the intent explicit. Overall, this is an exemplary model of readable production code.

Run 2

The code is well-structured and readable. It follows a clear logical organization, with constructors, factory methods, and helper classes separated appropriately. Nesting is minimal, with only a few levels of indentation for conditionals and try-catch blocks. The intent of each method and class is clear from naming and comments. The code is concise, avoiding unnecessary verbosity while maintaining clarity. Action granularity is appropriate, with most lines performing a single action. Reading flow is natural, as methods are ordered logically and the supporting inner classes are placed near their usage. Minor deductions include slight complexity in the serialization logic and the fall-through comment in the clone handling, but these do not significantly hinder readability.

Run 3

The code is well-structured and highly readable. It follows clear class organization with fields, constructors, and methods grouped logically. Nesting is minimal, only using necessary try-catch blocks and conditionals. Intent is clear through meaningful names like 'prototype', 'supportsClone', and 'checkNotDone'. The code is concise without sacrificing clarity. Action granularity is appropriate, with one logical operation per line. Reading flow is natural, with methods ordered in a logical sequence from construction to usage. Minor improvements could include reducing duplicate constructor logic and extracting the clone fallback pattern, but these don't significantly impact readability. Overall, this is exemplary code that demonstrates good practices in structure, naming, and organization.

Run 1

Code Structure: Well-organized adapter with separate helpers, serialization support, and a dedicated hasher class. Nesting: Shallow overall; the clone fallback introduces only modest nesting. Clarity of intent: Descriptive method names, validation, and comments make behavior clear, though the toString field name and serialization conventions require some familiarity. Code length: Methods are concise; constructor duplication and repeated update checks add minor repetition but remain understandable. Action granularity: Almost every statement performs a single action, with the final conditional expression combining digest creation and optional truncation understandably. Reading flow: Constructors and core methods lead naturally into supporting classes, though serialization code interrupts the flow between factory and hasher implementation. Consistent formatting helps readability. Minor drawbacks include the validation message saying '<' while the condition permits equality, and the implicit clone-failure fallback.

Run 2

Code Structure: Responsibilities are logically separated into the hash-function adapter, serialization proxy, and digest hasher, with small focused methods. Nesting: Mostly flat; the clone fallback introduces only modest if/try nesting. Clarity of intent: Descriptive method names, explicit validation, and lifecycle checks make behavior clear. Minor distractions include the field named toString, the unused clone result, and a validation message saying '<' where the condition permits equality. Code length: Appropriate for the functionality, though constructors and update methods contain some repetition. Action granularity: Statements generally perform one action per line; the final conditional expression combines digest creation and truncation but remains understandable. Reading flow: Consistent formatting and straightforward method bodies support natural reading, although serialization machinery interrupts the transition from adapter logic to hashing implementation.

Run 3

Code Structure: Responsibilities are logically separated into the hash-function adapter, serialization proxy, and digest hasher, with small, focused methods. Nesting: Mostly shallow; only the cloning fallback introduces an if containing a try/catch. Clarity of intent: Descriptive method names, explicit state checks, and brief comments clarify behavior. Fields named bytes and toString are slightly ambiguous, and the validation message incorrectly says '<' where the condition permits equality. Code length: Concise overall; repeated constructor initialization and update checks add modest, understandable duplication. Action granularity: Statements generally perform one action per line, though the final conditional expression combines digest generation, optional truncation, and wrapping. Reading flow: Consistent formatting and straightforward control flow make the code easy to follow; serialization machinery interrupts the main hashing narrative slightly.