Skip to content

Conversation

@sjakobi
Copy link
Member

@sjakobi sjakobi commented Dec 5, 2025

Resolves #560.

Resolves #560.
Copy link
Collaborator

@treeowl treeowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two situations with different needs:

  1. Repetitions are common. Your current code is optimized for this case.
  2. Repetitions are rare.

In the rare-repetition case, we almost always insert the key, so checking first seems like a waste of time. A version optimized for this would return (something isomorphic to) Maybe (HashMap k a). Since we don't have an efficient setjmp/longjmp, I believe this will be slower than your version in the common-repetition case.

Do we want two versions of the function?

| otherwise = go h k x s $ BitmapIndexed (mask hy s) (A.singleton t)
{-# INLINABLE unsafeInsert #-}

unsafeInsertNewKeyM :: Hash -> k -> v -> HashMap k v -> ST s (HashMap k v)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps absent instead of new?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hashNub (and hashNubOn)

3 participants