Skip to content

Commit b9dc73d

Browse files
committed
Document preconditions
1 parent 07098bf commit b9dc73d

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

containers/src/Data/IntSet/Internal/IntTreeCommons.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ mask i m = i .&. ((-m) `xor` m)
150150
{-# INLINE mask #-}
151151

152152
-- | The first switching bit where the two prefixes disagree.
153+
--
154+
-- Precondition for defined behavior: p1 /= p2
153155
branchMask :: Int -> Int -> Int
154156
branchMask p1 p2 = iHighestBitMask (p1 `xor` p2)
155157
{-# INLINE branchMask #-}

containers/src/Utils/Containers/Internal/BitUtil.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,15 @@ import GHC.Exts (Int(..), uncheckedIShiftRL#)
4444
#endif
4545

4646
-- | An @Int@ where only the highest bit is set.
47+
--
48+
-- Precondition for defined behavior: w /= 0
4749
iHighestBitMask :: Int -> Int
4850
iHighestBitMask w = unsafeShiftL 1 (wordSize - 1 - countLeadingZeros w)
4951
{-# INLINE iHighestBitMask #-}
5052

5153
-- Right and left logical shifts.
54+
--
55+
-- Precondition for defined behavior: 0 <= shift amount < wordSize
5256
shiftRL, shiftLL :: Word -> Int -> Word
5357
shiftRL = unsafeShiftR
5458
shiftLL = unsafeShiftL
@@ -58,6 +62,8 @@ wordSize :: Int
5862
wordSize = finiteBitSize (0 :: Word)
5963

6064
-- Right logical shift.
65+
--
66+
-- Precondition for defined behavior: 0 <= shift amount < wordSize
6167
iShiftRL :: Int -> Int -> Int
6268
#ifdef __GLASGOW_HASKELL__
6369
iShiftRL (I# x#) (I# sh#) = I# (uncheckedIShiftRL# x# sh#)

0 commit comments

Comments
 (0)