Skip to content
This repository has been archived by the owner on Jun 13, 2020. It is now read-only.

Commit

Permalink
Cleaned up some code
Browse files Browse the repository at this point in the history
  • Loading branch information
exclipy committed Dec 31, 2010
1 parent c51aa18 commit ebad2b3
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions PVector.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ empty = PV 0 shiftStep (BodyNode (array (0, -1) [])) (array (0, -1) [])
| ix >= tailOff c = t A.! (ix - tailOff c)
| otherwise = lookup r s ix
where lookup :: Node e -> Int -> Int -> e
lookup node level ix = let subIx = (ix `shiftR` level) .&. mask
in case node of
BodyNode a -> lookup (a A.! subIx) (level-shiftStep) ix
LeafNode a -> a A.! subIx
lookup (BodyNode a) level ix = let subIx = (ix `shiftR` level) .&. mask
in lookup (a A.! subIx) (level-shiftStep) ix
lookup (LeafNode a) level ix = let subIx = (ix `shiftR` level) .&. mask
in a A.! subIx

-- (append el pv) is pv, with el appended
append :: e -> PVector e -> PVector e
Expand Down Expand Up @@ -105,10 +105,9 @@ map :: (e -> e) -> PVector e -> PVector e
map fn (PV c s r t) = PV c s (mapNode fn r) (arrayMap fn t)
where mapNode fn (BodyNode a) = BodyNode $ arrayMap (mapNode fn) a
mapNode fn (LeafNode a) = LeafNode $ arrayMap fn a


arrayMap :: (Ix i) => (a -> a) -> Array i a -> Array i a
arrayMap fn arr = array (bounds arr) $ P.map (\(key, value) -> (key, fn value)) $ A.assocs arr
arrayMap :: (Ix i) => (a -> a) -> Array i a -> Array i a
arrayMap fn arr =
array (bounds arr) $ P.map (\(key, value) -> (key, fn value)) $ A.assocs arr

-- (elems pv) is a list of the elements of pv
elems :: PVector e -> [e]
Expand Down

0 comments on commit ebad2b3

Please sign in to comment.