stable-tree-0.7.0: Trees whose branches are resistant to change

CopyrightJeremy Groven
LicenseBSD3
Safe HaskellNone
LanguageHaskell2010

Data.StableTree.Conversion

Description

Functions for converting between Tree and Fragment types

Synopsis

Documentation

data Fragment k v Source

A Fragment is a user-visible part of a tree, i.e. a single node in the tree that can actually be manipulated by a user. This is useful when doing the work of persisting trees. See toFragments and fromFragments for functions to convert between Fragments and Trees. see store and load for functions related to storing and retrieving Fragments.

Instances

(Eq k, Eq v) => Eq (Fragment k v) 
(Ord k, Ord v) => Ord (Fragment k v) 
(Show k, Show v) => Show (Fragment k v) 
(Ord k, Serialize k, Serialize v) => Serialize (Fragment k v) 

toFragments :: (Ord k, Serialize k, StableKey k, Serialize v) => StableTree k v -> [Fragment k v] Source

Convert a StableTree Tree into a list of storable Fragments. The resulting list is guaranteed to be in an order where each Fragment will be seen after all its children.

fromFragments :: (Ord k, Serialize k, StableKey k, Serialize v) => Map ObjectID (Fragment k v) -> Fragment k v -> Either Text (StableTree k v) Source

Recover a Tree from a single Fragment and a map of the fragments as returned from toFragments. If the fragment set was already stored, it is the caller's responsibility to load all the child fragments into a map (probably involving finding children using the fragmentChildren field of the Fragment type).

fragsToMap :: Ord k => Map ObjectID (Fragment k v) -> Fragment k v -> Either Text (Map k v) Source

Directly convert a bunch of Fragments and a root fragment into a Map instance. Mostly useful for testing the correctness of the fromFragments function.