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

Safe HaskellNone

Data.StableTree.Persist

Description

Logic for dealing with the actual persistence of Stable Trees. The key exports here are Error, Store, load, and store. A user needs to implement the loadTree, loadValue, storeTree and storeValue parts of Store, and make an appropriate Error type to report storage errors, and then the load and store functions can just do their thing. If necessary, a user can also implement Build for custom data types.

Synopsis

Documentation

data Store m e k v Source

Write appropriate functions here to load and store primitive parts of trees.

Constructors

Store 

Fields

loadTree :: Id -> m (Either e (Depth, Map k (ValueCount, Id)))
 
loadValue :: Id -> m (Either e v)
 
storeTree :: Id -> Depth -> Map k (ValueCount, Id) -> m (Maybe e)
 
storeValue :: Id -> v -> m (Maybe e)
 

class Build t whereSource

Typeclass to generate unique ByteStrings for StableTree keys and values. Used to generate the unique identities for values and branches.

Methods

build :: t -> BuilderSource

class Error e whereSource

Things go wrong with end-user storage, but things can also go wrong with reconstructing tree values. Implement stableTreeError to allow load and store to report their own errors.

Instances

data Id Source

The opaque type to identify values and branches of trees.

Instances

encodeId :: Id -> ByteStringSource

Convert an Id into a 32-byte ByteString. Useful for actual storage of Ids

decodeId :: ByteString -> Either String IdSource

Convert a stored ByteString back into an Id. Gives a Left err if the given ByteString isn't 32 bytes long

load :: (Monad m, IsKey k, Ord k, Error e) => Store m e k v -> Id -> m (Either e (StableTree k v))Source

Retrieve a tree given its id.

store :: (Monad m, Build k, Ord k, Build v) => Store m e k v -> StableTree k v -> m (Either e Id)Source

Store a tree using a Store and return its calculated Id

buildBinary :: Binary t => t -> BuilderSource

Generate a builder for something that is already a Binary

buildSerialize :: Serialize t => t -> BuilderSource

Generate a builder for something that is already a Serialize