File size distribution: Difference between revisions

Content added Content deleted
Line 448: Line 448:
frequencyGroups _ [] = newFrequencyGroups
frequencyGroups _ [] = newFrequencyGroups
frequencyGroups totalGroups xs
frequencyGroups totalGroups xs
| length xs == 1 = Map.singleton (head xs, head xs) 1
| length xs == 1 = Map.singleton (head xs, head xs) 1
| otherwise = foldr placeGroups newFrequencyGroups xs `using` parTraversable rseq
| otherwise = foldr placeGroups newFrequencyGroups xs `using` parTraversable rseq
where
where
Line 479: Line 479:
expand :: FrequencyGroups -> FrequencyGroups
expand :: FrequencyGroups -> FrequencyGroups
expand = foldr f . withStrategy (parTraversable rseq) <*>
expand = foldr f . withStrategy (parTraversable rseq) <*>
Map.mapWithKey groupsFromGroup . overThreshold
Map.mapWithKey groupsFromGroup . Map.filter (> groupThreshold)


where
where
overThreshold = Map.filter (> groupThreshold)

f :: Maybe (FGKey, FrequencyGroups) -- ^ expanded frequency group
f :: Maybe (FGKey, FrequencyGroups) -- ^ expanded frequency group
-> FrequencyGroups -- ^ accumulator
-> FrequencyGroups -- ^ accumulator
Line 498: Line 496:
| otherwise = Nothing
| otherwise = Nothing
where
where
collectBetween min max = filter (\n -> n >= min && n <= max)
range = filter (\n -> n >= min && n <= max) fileSizes
range = collectBetween min max fileSizes


displaySize :: Integer -> String
displaySize :: Integer -> String