This module provides data structure that allows random picking up from a collection of data in O(log(N)) time. You can set weight of each element with WideFloat from kudzu-forest/elm-wide-float package.
Type alias that represents each weighted contents in RandomTree.
Type that represent floating point number with wider range than Float in core package. This is introduced for preventing overflow of exponentially changing value.
If you need to directly manipulate values of WideFloat, please hit elm install kudzu-forest/elm-wide-float in your terminal.
Returns weighted datum whose weight is multiplied with the given Float.
Maps content in Element.
Returns a RandomTree that has only one element.
Returns a RandomTree that has all element in given list.
Creates RandomTree from list of tuples of a Float value corresponding to its weight as the first component, and a datum as the second component.
the weighter it is, the higher probability it is chosen in.
Inserts a Weighted data to an already-existing RandomTree.
Inserts an element into the tree. The first parameter denotes the relative weight(1 means the whole weight of the original tree).
Inserts all elements of given list into the tree of second parameter. The first components of the tuple denotes the relative weight(1 means the whole weight of the original tree).
Removes any number of elements which is the same as the first parameter from the second parameter. The returned value is wrapped in Maybe.
Maps all the content of the tree, with the weights unchanged.
Removes any number of elements which passes the test function given as the first parameter from the second parameter. The returned value is wrapped in Maybe.
Random generator that generates one of the elements conteined in RandomTree given as parameter.
The time complexity is O(log(N)) where N denotes the size of the tree.
Random generator that generates one of the elements conteined in RandomTree, paired with the rest part of the tree.
If the RandomTree has only one element, then Nothing is returned as the second component.
The time complexity is O(log(N)) where N denotes the size of the tree.
Random generator that replaces one weighted data from the tree and generates a pair consisting of the removed data and resultant tree.
Returns how many elements the tree has.
Returns the sum of weight of all the elements in the tree.
Type that represents binary tree with weighted elements for random picking up.