fixfile-0.1.0.0: File-backed recursive data structures.

Copyright(C) 2016 Rev. Johnny Healey
LicenseLGPL-3
MaintainerRev. Johnny Healey <rev.null@gmail.com>
Stabilityexperimental
Portabilityunknown
Safe HaskellNone
LanguageHaskell2010

Data.FixFile.Tree23

Description

This is an implementation of a Two-Three Tree data structure that can be used with FixFile. It has two interfaces that are

Synopsis

Documentation

type Tree23 g d = g (TreeD d) Source

Type synonym for the Fixed representation of a Two-Three Tree.

type TreeD d = Tree23F (TreeKey d) (TreeValue d) Source

Fixed (TreeD d) represents a Two-Three tree. The data type d should have data families for it's key and value. These data families are not exported from the module. As a result, the only valid types for d are (Set k) as defined here or (Map k v), also defined here.

empty :: Fixed g => Tree23 g d Source

An empty Fixed Tree23.

null :: Fixed g => Tree23 g d -> Bool Source

Predicate that returns true if there are no items in the Tree23.

size :: Fixed g => Tree23 g d -> Int Source

Number of entries in (Tree23 g d).

  • Set

data Set k Source

A Set of k represented as a Two-Three Tree.

createSetFile :: (Binary k, Typeable k) => FilePath -> IO (FixFile (Ref (TreeD (Set k)))) Source

Create a FixFile for storing a set of items.

openSetFile :: (Binary k, Typeable k) => FilePath -> IO (FixFile (Ref (TreeD (Set k)))) Source

Open a FixFile for storing a set of items.

insertSet :: (Fixed g, Ord k) => k -> Tree23 g (Set k) -> Tree23 g (Set k) Source

Insert an item into a set.

lookupSet :: (Fixed g, Ord k) => k -> Tree23 g (Set k) -> Bool Source

Lookup an item in a set.

deleteSet :: (Fixed g, Ord k) => k -> Tree23 g (Set k) -> Tree23 g (Set k) Source

Delete an item from a set.

toListSet :: (Fixed g, Ord k) => Tree23 g (Set k) -> [k] Source

Convert a set into a list of items.

fromListSet :: (Fixed g, Ord k) => [k] -> Tree23 g (Set k) Source

Convert a list of items into a set.

insertSetT :: (Binary k, Ord k) => k -> Transaction (Ref (TreeD (Set k))) s () Source

lookupSetT :: (Binary k, Ord k) => k -> Transaction (Ref (TreeD (Set k))) s Bool Source

FTransaction version of lookupSet.

deleteSetT :: (Binary k, Ord k) => k -> Transaction (Ref (TreeD (Set k))) s () Source

FTransaction version of deleteSet.

  • Map

data Map k v Source

A Map of keys k to values v represented as a Two-Three Tree.

createMapFile :: (Binary k, Typeable k, Binary v, Typeable v) => FilePath -> IO (FixFile (Ref (TreeD (Map k v)))) Source

Create a FixFile of a Map.

openMapFile :: (Binary k, Typeable k, Binary v, Typeable v) => FilePath -> IO (FixFile (Ref (TreeD (Map k v)))) Source

Open a FixFile of a Map.

insertMap :: (Fixed g, Ord k) => k -> v -> Tree23 g (Map k v) -> Tree23 g (Map k v) Source

Insert value v into a map for key k. Any existing value is replaced.

lookupMap :: (Fixed g, Ord k) => k -> Tree23 g (Map k v) -> Maybe v Source

Lookup an item in a map corresponding to key k.

deleteMap :: (Fixed g, Ord k) => k -> Tree23 g (Map k v) -> Tree23 g (Map k v) Source

Delete an item from a map at key k.

alterMap :: (Fixed g, Ord k) => k -> (Maybe v -> Maybe v) -> Tree23 g (Map k v) -> Tree23 g (Map k v) Source

Apply a function to alter a Map at key k. The function takes (Maybe v) as an argument for any possible exiting value and returns Nothing to delete a value or Just v to set a new value.

mapMap :: (Fixed g, Fixed h, Ord k) => (a -> b) -> Tree23 g (Map k a) -> Tree23 h (Map k b) Source

Map a function over a map. Because of the way Tree23 is implemented, it is not possible to create a Functor instance to achieve this.

toListMap :: (Fixed g, Ord k) => Tree23 g (Map k v) -> [(k, v)] Source

Convert a map into a list of key-value tuples.

fromListMap :: (Fixed g, Ord k) => [(k, v)] -> Tree23 g (Map k v) Source

Convert a lst of key-value tuples into a map.

insertMapT :: (Binary k, Binary v, Ord k) => k -> v -> Transaction (Ref (TreeD (Map k v))) s () Source

lookupMapT :: (Binary k, Binary v, Ord k) => k -> Transaction (Ref (TreeD (Map k v))) s (Maybe v) Source

deleteMapT :: (Binary k, Binary v, Ord k) => k -> Transaction (Ref (TreeD (Map k v))) s () Source

alterMapT :: (Binary k, Binary v, Ord k) => k -> (Maybe v -> Maybe v) -> Transaction (Ref (TreeD (Map k v))) s () Source

FTransaction version of alterMap.

keysMap :: (Fixed g, Ord k) => Tree23 g (Map k v) -> [k] Source

Return the list of keys in a map.

valuesMap :: (Fixed g, Ord k) => Tree23 g (Map k v) -> [v] Source

Return a list of values in a map.