dbvar-2021.8.23: Mutable variables that are written to disk using delta encodings.
Safe Haskell Safe-Inferred
Language Haskell2010

Data.Table

Synopsis

Synopsis

Table models a database table. It corresponds to a collection of rows. Each row has a unique ID, but this is transparent to the API user.

Pile models a set of values. Unlike Set , it is represented as a lightweight list. This is used to highlight that the ordering of rows in a Table is not deterministic.

Supply is a supply of unique IDs.

Table

data Table row Source #

A Table is a collection of rows.

Constructors

Table

Fields

  • rows :: IntMap row

    Rows indexed by unique ID.

  • uids :: Supply

    Unique ID supply. WARNING: This is an internal part of the structure. Changing it may lead to an inconsistent state.

empty :: Table row Source #

The empty Table , containing no rows.

fromRows :: [( Int , row)] -> Table row Source #

Construct a Table from a list of rows with unique IDs.

fromList :: [row] -> Table row Source #

Construct a Table from a list of rows

toPile :: Table row -> Pile row Source #

Pile of rows contained in the Table .

toRows :: Table row -> Pile ( Int , row) Source #

Pile of rows with unique IDs contained in the Table .

selectWhere :: (row -> Bool ) -> Table row -> Pile row Source #

List all rows satisfying the predicate.

insertMany :: [row] -> Table row -> Table row Source #

Insert rows into the table.

deleteWhere :: (row -> Bool ) -> Table row -> Table row Source #

Delete all rows satisfying the predicate.

updateWhere :: (row -> Bool ) -> (row -> row) -> Table row -> Table row Source #

Update all rows satisfying the predicate

data DeltaTable row Source #

Delta encoding for changes to a Table .

Constructors

InsertMany [row]
DeleteWhere (row -> Bool )
UpdateWhere (row -> Bool ) (row -> row)

data DeltaDB key row Source #

Delta encoding for changes to a database table with unique IDs.

Constructors

InsertManyDB [(key, row)]
DeleteManyDB [key]
UpdateManyDB [(key, row)]

Instances

Instances details
Functor ( DeltaDB key) Source #
Instance details

Defined in Data.Table

Methods

fmap :: (a -> b) -> DeltaDB key a -> DeltaDB key b Source #

(<$) :: a -> DeltaDB key b -> DeltaDB key a Source #

( Eq key, Eq row) => Eq ( DeltaDB key row) Source #
Instance details

Defined in Data.Table

( Show key, Show row) => Show ( DeltaDB key row) Source #
Instance details

Defined in Data.Table

key ~ Int => Delta ( DeltaDB key row) Source #
Instance details

Defined in Data.Table

Associated Types

type Base ( DeltaDB key row) Source #

Methods

apply :: DeltaDB key row -> Base ( DeltaDB key row) -> Base ( DeltaDB key row) Source #

type Base ( DeltaDB key row) Source #
Instance details

Defined in Data.Table

type Base ( DeltaDB key row) = Table row

Pile

newtype Pile a Source #

A Pile is a set of values. Unlike Set , it is represented as a list, and avoids the Ord constraint.

This type is useful for highlighting that a collection of values has no specific order, even though it is not represented as a Set .

Constructors

Pile

Fields

deltaListToPile :: DeltaList a -> Pile ( Int , a) Source #

Map a DeltaList to a Pile of indexed single element concatenations. Higher indices are prepended later.

deltaListFromPile :: Pile ( Int , a) -> DeltaList a Source #

Restore a DeltaList from a Pile .

deltaListFromPile . deltaListToPile = id

deltaSetToPile :: DeltaSet a -> Pile ( DeltaSet1 a) Source #

Randomly permute the objects in a Pile . Useful for stress testing.

Every function f :: Pile A -> B should satisfy

forall g.  f . permute g = f

permute :: RandomGen g => g -> Pile a -> Pile a permute = undefined let (index, g2) = randomR (1,n) g1

Map a DeltaSet to a Pile of single element insertions and deltions.

deltaSetFromPile :: Ord a => Pile ( DeltaSet1 a) -> DeltaSet a Source #

Restore a DeltaSet from a Pile of single element insertions and deletions.

deltaSetFromPile . deltaSetToPile = id

Supply

abundance :: Supply Source #

Fresh supply of unique IDs.

fresh :: Supply -> ( Int , Supply ) Source #

Retrieve a fresh unique ID.

consume :: [ Int ] -> Supply -> Supply Source #

Remove a list of unique IDs from the Supply if necessary.