Skip to content

Conversation

@sjakobi
Copy link
Member

@sjakobi sjakobi commented Oct 16, 2025

Context: #364


TODO:

  • Update Strict.differenceWith

unsafeInsertNewLeaf h0 l0 m0 = runST (go h0 l0 0 m0)
where
go !_ !l !_ Empty = return l
go h l@(Leaf _ lx) s t@(Leaf hy ly)
Copy link
Member Author

Choose a reason for hiding this comment

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

I suspect it's not good to have to "case" on the HashMap like this. It might be better to supply the Leaf k x within as an extra argument to unsafeInsertNewLeaf.

Copy link
Member Author

Choose a reason for hiding this comment

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

This would probably cause additional allocations though, because the L-Leaf is by default unboxed within the Leaf HashMap node.

-- See https://github.com/haskell-unordered-containers/unordered-containers/issues/75#issuecomment-1128419337
{-# INLINE two #-}

two' :: Shift -> Hash -> HashMap k v -> Hash -> HashMap k v -> ST s (HashMap k v)
Copy link
Member Author

Choose a reason for hiding this comment

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

We should rather change two to have this type.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've refactored two and introduced two' in #521.

unsafeInsertNewLeaf :: Hash -> HashMap k v -> HashMap k v -> HashMap k v
unsafeInsertNewLeaf h0 l0 m0 = runST (go h0 l0 0 m0)
where
go !_ !l !_ Empty = return l
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
go !_ !l !_ Empty = return l
go !_h l !_s Empty = return l

It would probably be better to request that the "caller" ensures that the leaf is in WHNF.

@sjakobi
Copy link
Member Author

sjakobi commented Oct 25, 2025

#535 contains an even faster version of difference. I may keep this version of differenceWith though.

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.

1 participant