Skip to content

Commit aae97f9

Browse files
authored
lookupCont: Use Shift type synonym (#527)
1 parent ae5ba90 commit aae97f9

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

Data/HashMap/Internal.hs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,10 @@ type Hash = Word
350350
-- Only the lower 'maxChildren' bits are used. The remaining bits must be zeros.
351351
type Bitmap = Word
352352

353-
-- | 'Shift' values correspond to the level of the tree that we're currently
354-
-- operating at. At the root level the 'Shift' is @0@. For the subsequent
355-
-- levels the 'Shift' values are 'bitsPerSubkey', @2*'bitsPerSubkey'@ etc.
353+
-- | A 'Shift' value is the offset of the subkey in the hash and corresponds
354+
-- to the level of the tree that we're currently operating at. At the root
355+
-- level the 'Shift' is @0@. For the subsequent levels the 'Shift' values are
356+
-- 'bitsPerSubkey', @2*'bitsPerSubkey'@ etc.
356357
--
357358
-- Valid values are non-negative and less than @bitSize (0 :: Word)@.
358359
type Shift = Int
@@ -697,22 +698,18 @@ lookupRecordCollision# h k m =
697698
-- so we can be representation-polymorphic in the result type. Since
698699
-- this whole thing is always inlined, we don't have to worry about
699700
-- any extra CPS overhead.
700-
--
701-
-- The @Int@ argument is the offset of the subkey in the hash. When looking up
702-
-- keys at the top-level of a hashmap, the offset should be 0. When looking up
703-
-- keys at level @n@ of a hashmap, the offset should be @n * bitsPerSubkey@.
704701
lookupCont ::
705702
forall rep (r :: TYPE rep) k v.
706703
Eq k
707704
=> ((# #) -> r) -- Absent continuation
708705
-> (v -> Int -> r) -- Present continuation
709706
-> Hash -- The hash of the key
710707
-> k
711-
-> Int -- The offset of the subkey in the hash.
708+
-> Shift
712709
-> HashMap k v -> r
713710
lookupCont absent present !h0 !k0 !s0 !m0 = go h0 k0 s0 m0
714711
where
715-
go :: Eq k => Hash -> k -> Int -> HashMap k v -> r
712+
go :: Eq k => Hash -> k -> Shift -> HashMap k v -> r
716713
go !_ !_ !_ Empty = absent (# #)
717714
go h k _ (Leaf hx (L kx x))
718715
| h == hx && k == kx = present x (-1)

0 commit comments

Comments
 (0)