kudzu-forest / elm-random-tree / RandomTree.Uniform

This module provides data structure subjected to random choice of elements in uniform probability.

Note

Tree in this module

Types


type Tree a

Type that represents binary tree with elements subjected to random picking up in uniform probabilities.

Creation

singleton : a -> Tree a

Returns a Tree that has only one element.

fromList : a -> List a -> Tree a

Returns a Tree that has all elements in given list.

Insertion

insert : a -> Tree a -> Tree a

Inserts a data to an already-existing Tree.

insertList : List a -> Tree a -> Tree a

Inserts all elements of given list into the tree.

Modification

map : (a -> b) -> Tree a -> Tree b

Maps all the content of the tree.

filter : (a -> Basics.Bool) -> Tree a -> Maybe (Tree a)

Removes any number of elements which fails to passes the test function given as the first parameter.

delete : a -> Tree a -> Maybe (Tree a)

Removes any number of elements which is the same as the first parameter from the second parameter.

Random Picking Up

get : Tree a -> Random.Generator a

Random generator that generates one of the elements conteined in Tree given as parameter. The time complexity is O(log(N)).

take : Tree a -> Random.Generator ( a, Maybe (Tree a) )

Random generator that generates one of the elements conteined in Tree, paired with the rest part of the tree. The time complexity is O(log(N)).

replace : a -> Tree a -> Random.Generator ( a, Tree a )

Random generator that replaces one data from the tree and generates a pair consisting of the removed data and resultant tree.

Status Checking

count : Tree a -> Basics.Int

Returns how many elements the tree has.