@@ -31,6 +31,7 @@ import GHC.Base hiding (empty)
3131import GHC.Exts (sortWith)
3232import GHC.Fingerprint (Fingerprint (..))
3333import Unsafe.Coerce (unsafeCoerce)
34+import Debug.Trace
3435
3536import qualified Data.Vector as V
3637import qualified Data.Vector.Unboxed as Unboxed
@@ -89,9 +90,18 @@ binarySearch :: Fingerprint -> Unboxed.Vector Word64 -> Unboxed.Vector Word64 ->
8990binarySearch (Fingerprint a b) fpAs fpBs =
9091 let
9192 !(I# len) = Unboxed.length fpAs
92− ind = I# (binSearchHelp (-1#) len)
93+ checkfpBs :: Int# -> Maybe Int
94+ checkfpBs i =
95+ case i <# len of
96+ 0# -> Nothing
97+ _ ->
98+ if a /= Unboxed.unsafeIndex fpAs (I# i)
99+ then Nothing
100+ else if b == Unboxed.unsafeIndex fpBs (I# i)
101+ then Just (I# i)
102+ else checkfpBs (i +# 1#)
93103 in
94− checkfpBs ind (I# len)
104+ inline (checkfpBs (binSearchHelp (-1#) len))
95105 where
96106 binSearchHelp :: Int# -> Int# -> Int#
97107 binSearchHelp l r = case l <# (r -# 1#) of
@@ -102,8 +112,3 @@ binarySearch (Fingerprint a b) fpAs fpBs =
102112 then binSearchHelp m r
103113 else binSearchHelp l m
104114
105− checkfpBs :: Int -> Int -> Maybe Int
106− checkfpBs i len
107− | i >= len || a /= Unboxed.unsafeIndex fpAs i = Nothing
108− | b == Unboxed.unsafeIndex fpBs i = Just i
109− | otherwise = checkfpBs (i + 1) len