haskell-unordered-containers / unordered-containers

Efficient hashing-based container types
BSD 3-Clause "New" or "Revised" License
221 stars 97 forks source link

`two` and `unionWithKey.goDifferentHash` are very similar #468

Open sjakobi opened 2 years ago

sjakobi commented 2 years ago

https://github.com/haskell-unordered-containers/unordered-containers/blob/8c20f7ad6f58dd1477bbd0a3f8bf122f6d20ad4c/Data/HashMap/Internal.hs#L969-L987

https://github.com/haskell-unordered-containers/unordered-containers/blob/8c20f7ad6f58dd1477bbd0a3f8bf122f6d20ad4c/Data/HashMap/Internal.hs#L1668-L1674

Maybe we can create a common abstraction, e.g. by changing the type of two:

 two :: Shift -> Hash -> HashMap k v -> Hash -> HashMap k v -> ST s (HashMap k v)
sjakobi commented 2 years ago

Once the Leaf for the first key-value pair is constructed early-on, we can also tweak two with the "shifted hash" tricks introduced in https://github.com/haskell-unordered-containers/unordered-containers/pull/458.