Gizra/elm-radix-tree/2.0.0

RadixTree

Build an ordered Radix tree.

Structure

type RadixTree a

Represents an ordered Radix tree.

toTree : RadixTree a -> Tree (List a)

Extract the Tree from the RadixTree. The Tree is from the package Tree that has a very nice API for working with trees, and allows converting the Tree to a Zipper - making traversals easier.

Build

Create an empty Radix tree.

import Tree


RadixTree.empty
    |> RadixTree.toTree
    |> Tree.label --> []
singleton : List a -> RadixTree a

Create an Radix tree with a single value.

import Tree


RadixTree.singleton [1, 2, 3]
    |> RadixTree.toTree
    |> Tree.label --> [1, 2, 3]
insert : List a -> RadixTree a -> RadixTree a

An Ordered insert of a value to the Radix tree.

import Tree


RadixTree.singleton [1, 2, 3]
    |> RadixTree.insert [1, 2, 4]
    |> RadixTree.toTree
    |> Tree.label --> [1, 2]


RadixTree.singleton [1, 2, 3]
    |> RadixTree.insert [1, 2, 4]
    |> RadixTree.toTree
    |> Tree.children --> [Tree.singleton [4], Tree.singleton [3]]