From 868aee0cc6283749ea62cfa93c8b1101197e7da8 Mon Sep 17 00:00:00 2001 From: Simon Jakobi Date: Mon, 20 Oct 2025 23:07:48 +0200 Subject: [PATCH 1/2] lookupCont: Use `Shift` type synonym --- Data/HashMap/Internal.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Data/HashMap/Internal.hs b/Data/HashMap/Internal.hs index 6cad1028..b5272faa 100644 --- a/Data/HashMap/Internal.hs +++ b/Data/HashMap/Internal.hs @@ -708,11 +708,11 @@ lookupCont :: -> (v -> Int -> r) -- Present continuation -> Hash -- The hash of the key -> k - -> Int -- The offset of the subkey in the hash. + -> Shift -- The offset of the subkey in the hash. -> HashMap k v -> r lookupCont absent present !h0 !k0 !s0 !m0 = go h0 k0 s0 m0 where - go :: Eq k => Hash -> k -> Int -> HashMap k v -> r + go :: Eq k => Hash -> k -> Shift -> HashMap k v -> r go !_ !_ !_ Empty = absent (# #) go h k _ (Leaf hx (L kx x)) | h == hx && k == kx = present x (-1) From d35547f2e32db27ae562db9f32542f4ff93ebc7e Mon Sep 17 00:00:00 2001 From: Simon Jakobi Date: Tue, 21 Oct 2025 12:51:53 +0200 Subject: [PATCH 2/2] Move documentation from `lookupCont` to `Shift` --- Data/HashMap/Internal.hs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Data/HashMap/Internal.hs b/Data/HashMap/Internal.hs index b5272faa..ed7154e0 100644 --- a/Data/HashMap/Internal.hs +++ b/Data/HashMap/Internal.hs @@ -350,9 +350,10 @@ type Hash = Word -- Only the lower 'maxChildren' bits are used. The remaining bits must be zeros. type Bitmap = Word --- | 'Shift' values correspond to the level of the tree that we're currently --- operating at. At the root level the 'Shift' is @0@. For the subsequent --- levels the 'Shift' values are 'bitsPerSubkey', @2*'bitsPerSubkey'@ etc. +-- | A 'Shift' value is the offset of the subkey in the hash and corresponds +-- to the level of the tree that we're currently operating at. At the root +-- level the 'Shift' is @0@. For the subsequent levels the 'Shift' values are +-- 'bitsPerSubkey', @2*'bitsPerSubkey'@ etc. -- -- Valid values are non-negative and less than @bitSize (0 :: Word)@. type Shift = Int @@ -697,10 +698,6 @@ lookupRecordCollision# h k m = -- so we can be representation-polymorphic in the result type. Since -- this whole thing is always inlined, we don't have to worry about -- any extra CPS overhead. --- --- The @Int@ argument is the offset of the subkey in the hash. When looking up --- keys at the top-level of a hashmap, the offset should be 0. When looking up --- keys at level @n@ of a hashmap, the offset should be @n * bitsPerSubkey@. lookupCont :: forall rep (r :: TYPE rep) k v. Eq k @@ -708,7 +705,7 @@ lookupCont :: -> (v -> Int -> r) -- Present continuation -> Hash -- The hash of the key -> k - -> Shift -- The offset of the subkey in the hash. + -> Shift -> HashMap k v -> r lookupCont absent present !h0 !k0 !s0 !m0 = go h0 k0 s0 m0 where