RFR: 8352171: Arrays.hashCode for sub-range of byte array API addition
Roger Riggs
rriggs at openjdk.org
Fri Mar 28 15:29:18 UTC 2025
On Thu, 20 Mar 2025 21:50:59 GMT, Chen Liang <liach at openjdk.org> wrote:
>> Add the java.util.Arrays.hashCode(byte[], int start, int end).
>>
>> Hi team, I am new here, please give me some guidance. Thank you.
>
> src/java.base/share/classes/java/util/Arrays.java line 4454:
>
>> 4452: */
>> 4453: public static int hashCode(byte[] a, int fromIndex, int toIndex) {
>> 4454: if (a == null) {
>
> The `a == null` special check is dubious - `a == null` has a meaning if we are hashing a whole `byte[]` object, but with a specific `fromIndex` and `toIndex` it just doesn't work.
>
> That said, we might consider accepting the initial hash too - For example, we have two `byte[]` arrays and we want a concatenated hash. The initial hash allows us to compute such a hash from two arrays easily.
None of the other public APIs for hashcode include an initial value argument.
The caller can easily combine the hashcode values themselves as needed.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24128#discussion_r2018886224
More information about the core-libs-dev
mailing list