Anonymous user
File size distribution: Difference between revisions
m
→{{header|Haskell}}: cleanup
m (→{{header|Haskell}}: cleanup) |
|||
Line 414:
type FrequencyGroup = ((Integer, Integer), Integer)
frequencyGroups :: Int -> [Integer] -> [FrequencyGroup]▼
frequencyGroups _ [] = []▼
| otherwise = placeGroups xs groupMinMax▼
where▼
range = maximum xs - minimum xs▼
groupSize = succ $ ceiling $ realToFrac range / realToFrac totalGroups▼
groups = takeWhile (<=groupSize + maximum xs) $ iterate (+groupSize) 0▼
groupMinMax = (,0) <$> zip groups (pred <$> tail groups)▼
placeGroups [] = id▼
placeGroups (d:ds) = placeGroups ds .▼
fmap (\g@((min,max), count) ->▼
if d >= min && d <= max▼
then ((min, max), succ count)▼
else g▼
)▼
fileSizes :: [Item] -> [Integer]
Line 445 ⟶ 426:
f (Folder p) acc = p:acc
f _ acc = acc
totalBytes :: [Item] -> Integer
Line 459 ⟶ 436:
) (0, 0)
| length range > 1 = frequencyGroups gsize range▼
|
▲ | otherwise = placeGroups xs groupMinMax
where
▲ range = maximum xs - minimum xs
collectBetween min max = filter (\n -> n >= min && n <= max)▼
▲ groupSize = succ $ ceiling $ realToFrac range / realToFrac totalGroups
range = collectBetween min max fileSizes▼
▲ groups = takeWhile (<=groupSize + maximum xs) $ iterate (+groupSize) 0
▲ groupMinMax = (,0) <$> zip groups (pred <$> tail groups)
▲ placeGroups [] = id
▲ placeGroups (d:ds) = placeGroups ds .
▲ fmap (\g@((min,max), count) ->
▲ if d >= min && d <= max
▲ then ((min, max), succ count)
▲ else g
▲ )
expandGroups :: Int -> [Integer] -> Integer -> [FrequencyGroup] -> [FrequencyGroup]
Line 479 ⟶ 467:
expand = ((\g@((min, max), count) ->
if count > groupThreshold then
groupsFromGroup
else
[g]
) =<<)
groupsFromGroup ((min, max), count)
▲ | length range > 1 = frequencyGroups gsize range
| otherwise = [((min, max), count)]
▲ where
▲ collectBetween min max = filter (\n -> n >= min && n <= max)
▲ range = collectBetween min max fileSizes
displaySize :: Integer -> String
Line 561 ⟶ 556:
Right (path, groupSize) -> do
items <- parallelItemCollector path
let (fileCount, folderCount) = counts items
printf "Total files: %d\n" fileCount
|