treefold-0.1.0.0: Provides folds which try to combine elements in a balanced way.

Safe HaskellNone
LanguageHaskell2010

Data.TreeFold.Parallel

Description

This is a parallel version of Data.TreeFold: all the functions here take a Strategy which specifies how to evaluate the fold in parallel, and a number for the size of the chunks evaluated in parallel. The number works like this. If you imagine the treefold as being executed on a list of 32 elements like so:

5_______________________________________________________________
                                /\
                               /  \
                              /    \
                             /      \
                            /        \
                           /          \
                          /            \
                         /              \
                        /                \
                       /                  \
                      /                    \
                     /                      \
                    /                        \
                   /                          \
                  /                            \
4________________/______________________________\_______________
                /\                              /\
               /  \                            /  \
              /    \                          /    \
             /      \                        /      \
            /        \                      /        \
           /          \                    /          \
          /            \                  /            \
3________/______________\________________/______________\_______
        /\              /\              /\              /\
       /  \            /  \            /  \            /  \
      /    \          /    \          /    \          /    \
2____/______\________/______\________/______\________/______\___
    /\      /\      /\      /\      /\      /\      /\      /\
1__/__\____/__\____/__\____/__\____/__\____/__\____/__\____/__\_
0_/\__/\__/\__/\__/\__/\__/\__/\__/\__/\__/\__/\__/\__/\__/\__/\

Depending on what number you supply, the tree fold will run lazily until it gets to the corresponding point in the diagram above. Then, it will evaluate the subtrees in parallel according to the strategy supplied. It will then start again on the list of evaluated values, continuing until it gets to only one.

Synopsis

Documentation

treeFold :: Strategy a -> Int -> (a -> a -> a) -> a -> [a] -> a Source #

A parallel version of treeFold.

treeFoldNonEmpty :: Strategy a -> Int -> (a -> a -> a) -> NonEmpty a -> a Source #

A parallel version of treeFoldNonEmpty.

treeFoldMap :: Strategy a -> Int -> (b -> a) -> (a -> a -> a) -> a -> [b] -> a Source #

A parallel version of treeFoldMap.

treeFoldMapNonEmpty :: Strategy a -> Int -> (b -> a) -> (a -> a -> a) -> NonEmpty b -> a Source #

A parallel version of treeFoldMapNonEmpty.

rpar :: Strategy a #