On Tue, 1 Dec 2026 04:03:30 GMT, Daisuke Yamazaki <[email protected]> wrote:

> Please review this fix for `Set.ofLazy` and `Map.ofLazy` behaviour.
> 
> When looking up an object that is equal to a stored candidate but is a 
> different instance,
> `Set.contains()` and `Map.get()` pass the lookup argument to the computing 
> function instead of the stored candidate.
> 
> This change stores the candidates in an array and uses the lookup index to 
> retrieve the corresponding candidate before calling the computing function.
> 
> Regression tests have been added for both `Set` and `Map` to verify that the 
> computing function receives the stored candidate.
> 
> Tests:
> - `LazySetTest`
> - `tier1`
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

Ok. So maybe I should hold off on a new PR and just share my thoughts here 
@PeyaPeyaPeyang 

So, what do you think about adding a slimmed-down version of the backing 
key-to-int map and where we can get both keys and values (`int`) from the 
slimmed-down map? That way we don't have to have an extra array and I think it 
might even be faster. Here is an outline:


    private sealed interface ToIntMapWithSlots<K> {
        // A nonnegative result identifies the slot for both accessors.
        int findSlot(Object key);
        K keyAt(int slot);
        int valueAt(int slot);
    }


And then we could have two implementations: one for N entries and one for just 
1 entry (making it correspond to what we had before).

The `ToIntMapWithSlotsN` (or whatever it should be called) could have two 
`@Stable` arrays:
 * private final K[] keys;
 * private final int[] indices;

We could use a trick where we put index + 1 in the `int` array to benefit from 
stability. 

What do you think?

-------------

PR Comment: https://git.openjdk.org/jdk/pull/34144#issuecomment-7315431839

Reply via email to