the-sett / tea-tree / TeaTree

Todo: It will be a multiway Tree implementation, not a binary tree.

Will save this for an optimized version:

type alias NodeArray a =
    Array Int a

Need to add API for simpler read-only walking of the tree. Zippers will churn the heap, but a read only pass for rendering the view does not need them so can be made more efficient.

Types


type Tree a


type Zipper a


type Path

Tree operations

singleton : a -> Zipper a

zipper : Tree a -> Zipper a

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

Zipper operations

goToChild : Basics.Int -> Zipper a -> Maybe (Zipper a)

goToRightMostChild : Zipper a -> Maybe (Zipper a)

goUp : Zipper a -> Maybe (Zipper a)

goLeft : Zipper a -> Maybe (Zipper a)

goRight : Zipper a -> Maybe (Zipper a)

goToRoot : Zipper a -> Zipper a

Walking the zipper context back to the root will produce a Tree with any updates made as the zipper was walked over the tree, folded back in to the new Tree.

goToNext : Zipper a -> Maybe (Zipper a)

goToPrevious : Zipper a -> Maybe (Zipper a)

goTo : (a -> Basics.Bool) -> Zipper a -> Maybe (Zipper a)

updateFocusDatum : (a -> a) -> Zipper a -> Zipper a

datum : Zipper a -> a

insertChild : a -> Zipper a -> Zipper a

appendChild : a -> Zipper a -> Zipper a

getPath : Zipper a -> Path

toTree : Zipper a -> Tree a

depth : Zipper a -> Basics.Int

Path operations

goToPath : Path -> Tree a -> Maybe (Zipper a)

The Path and Tree can be recombined to recover a previous position in the tree. walkPath : Path -> Tree a -> Maybe (Zipper a)

Every node will be marked with a unique id, so that re-walking the tree from a Path can be confirmed as correct. Walking a Path will produce a Maybe.

This allows events to be tagged with Paths which describe a return to a previously visited position within a tree, without capturing any other data associated with that node. This is to circumvent the stale data issue when a user is interacting with a tree.

updateDatum : Path -> (a -> a) -> Tree a -> Tree a

The contents of nodes in the tree will be held in an Array Id a. Ids will be assigned sequentially. This will allow mapping by id without re-walking a Path possible. It will only be necessary to re-walk paths when adding new nodes into the tree, as this is the only situation when fresh ids will need to be generated.

Sorting

sortBy : (a -> comparable) -> Tree a -> Tree a