git.iko.soy/typeable/attoparsec
on master help sign in
Remove junk whitespace
commit9eb46aebe0e89e69787263ddae2e862254e7fc9c authorBryan O'Sullivan <bos@serpentine.com> dateTue 2 Dec 2014, 13:17 (12 years ago) parentd1397d5
1 file changed+13−14
Data/Attoparsec/Text/FastSet.hs+13−14
Data/Attoparsec/Text/FastSet.hs+13−14
@@ -10,8 +10,8 @@
1010--
1111-- Fast set membership tests for 'Char' values. We test for
1212-- membership using a hashtable implemented with Robin Hood
13−-- collision resolution. The set representation is unboxed,
14−-- and the characters and hashes interleaved, for efficiency.
13+-- collision resolution. The set representation is unboxed,
14+-- and the characters and hashes interleaved, for efficiency.
1515--
1616--
1717-----------------------------------------------------------------------------
@@ -38,11 +38,11 @@ import qualified Data.Text as T
3838data FastSet = FastSet {table :: {-# UNPACK #-} !(A.UArray Int Int),
3939 mask :: {-# UNPACK #-} !Int}
4040 deriving (Eq, Ord, Show)
41−
41+
4242data Entry = Entry {key :: {-# UNPACK #-} !Char,
4343 initialIndex :: {-# UNPACK #-} !Int,
4444 index :: {-# UNPACK #-} !Int} deriving (Show)
45−
45+
4646offset :: Entry -> Int
4747offset e = index e - initialIndex e
4848
@@ -54,20 +54,20 @@ resolveCollisions (a:b:entries) = a' : resolveCollisions (b':entries)
5454 | index a < index b = (a, b)
5555 | offset a < offset b = (b{index=index a}, a{index=index a + 1})
5656 | otherwise = (a, b{index=index a + 1})
57−
57+
5858pad :: Int -> [Entry]-> [Entry]
5959pad = go 0
6060 where go _ m [] = replicate (max 1 m) empty
6161 go k m (e:entries) = map (const empty) [k..i - 1] ++ e : go (i + 1) (m + i - k - 1) entries
6262 where i = index e
6363 empty = Entry '\0' maxBound 0
64−
64+
6565nextPowerOf2 :: Int -> Int
6666nextPowerOf2 0 = 1
6767nextPowerOf2 x = go (x - 1) 1
6868 where go y 32 = y + 1
6969 go y k = go (y .|. (y `shiftR` k)) $ k * 2
70−
70+
7171fastHash :: Char -> Int
7272fastHash = fromEnum
7373
@@ -77,15 +77,15 @@ fromList s = FastSet (AB.listArray (0, length interleaved - 1) interleaved) mask
7777 l = length s'
7878 mask' = nextPowerOf2 ((5 * l) `div` 4) - 1
7979 indeces = map ((.&. mask') . fastHash) s'
80− entries = pad mask' .
81− resolveCollisions .
82− sortBy (compare `on` initialIndex) $
80+ entries = pad mask' .
81+ resolveCollisions .
82+ sortBy (compare `on` initialIndex) $
8383 zipWith (\c i -> Entry c i i) s' indeces
8484 interleaved = concatMap (\e -> [fromEnum $ key e, initialIndex e]) entries
85−
85+
8686set :: T.Text -> FastSet
8787set = fromList . T.unpack
88−
88+
8989-- | Check the set for membership.
9090member :: Char -> FastSet -> Bool
9191member c a = go (2 * i)
@@ -94,10 +94,9 @@ member c a = go (2 * i)
9494 where c' = toEnum $ AB.unsafeAt (table a) j
9595 i' = AB.unsafeAt (table a) $ j + 1
9696 go j = lookupAt j $ lookupAt (j + 2) $ lookupAt (j + 4) $ lookupAt (j + 6) $ go (j + 8)
97−
97+
9898charClass :: String -> FastSet
9999charClass = fromList . go
100100 where go (a:'-':b:xs) = [a..b] ++ go xs
101101 go (x:xs) = x : go xs
102102 go _ = ""
103−