Skip to content

WIP: Add nub#570

Draft
sjakobi wants to merge 2 commits into
masterfrom
sjakobi/hashNub
Draft

WIP: Add nub#570
sjakobi wants to merge 2 commits into
masterfrom
sjakobi/hashNub

Conversation

@sjakobi

@sjakobi sjakobi commented Dec 5, 2025

Copy link
Copy Markdown
Member

Resolves #560.

Resolves #560.

@treeowl treeowl left a comment

Copy link
Copy Markdown
Collaborator

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?

Comment thread Data/HashMap/Internal.hs
| 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
Copy Markdown
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)

2 participants