Skip to content

Commit 761fbda

Browse files
committed
Tweak invariant documentation
1 parent 9ce5cc6 commit 761fbda

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

containers/src/Data/IntMap/Internal.hs

+14-10
Original file line numberDiff line numberDiff line change
@@ -358,18 +358,22 @@ intFromNat = fromIntegral
358358
data IntMap a = Bin {-# UNPACK #-} !Prefix
359359
!(IntMap a)
360360
!(IntMap a)
361-
-- Invariant: Nil is never found as a child of Bin.
362361
| Tip {-# UNPACK #-} !Key a
363362
| Nil
364-
365-
-- | A @Prefix@ stores the most significant bits shared by all keys in a Bin,
366-
-- immediately followed a single set bit, which we refer to as "mask".
367-
--
368-
-- Invariant: All keys in the left child have the mask bit unset, and all keys
369-
-- in the right child have the mask bit set.
370-
--
371-
-- It follows from the invariant that the @Int@ value of the @Prefix@ is the
372-
-- smallest value that can be present in the right child.
363+
-- IntMap invariants:
364+
-- * Nil is never found as a child of Bin.
365+
-- * The Prefix of a Bin is the common high-order bits that all keys in the
366+
-- Bin share.
367+
-- * We call the bit immediately following the shared prefix the mask bit.
368+
-- All keys in the left child of a Bin have the mask bit unset, and all keys
369+
-- in the right child have the mask bit set.
370+
371+
-- | A @Prefix@ is some prefix of high-order bits of an @Int@.
372+
--
373+
-- This is represented by an @Int@ which starts with the prefix bits,
374+
-- immediately followed by a set bit. This is the mask bit for a @Bin@. It
375+
-- follows from the IntMap invariants that this @Int@ value is the smallest
376+
-- value that can be present in its right child.
373377
newtype Prefix = Prefix { unPrefix :: Int }
374378
deriving (Eq, Lift)
375379

0 commit comments

Comments
 (0)