memdb-1.0.0.1: Efficient in memory indexed database

Copyright(c) Philip Kamenarsky 2018
LicenseMIT
Maintainerp.kamenarsky@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Database.Immutable

Contents

Description

This package contains a thin wrapper over a continous memory region combined with an efficient reverse index implementation for fast and type-safe indexed lookups.

It is aimed at storing, loading and querying big immutable datasets. Once written, a database can not be modified further.

The underlying storage is pinned and thus ensures efficient garbage collection without ever reading the structure contents, since no pointers live inside the dataset that point outside it.

Synopsis

Database

data DB (indexes :: [(Symbol, *)]) a Source #

An immutable database containing elements of type a, each one indexed according to an Indexes description.

Import Database.Immutable.Read for reading boxed values and Database.Immutable.Read.Unboxed for the unboxed variant.

Index types

newtype Id a Source #

Offset into the database.

Constructors

Id Word32 
Instances
Eq (Id a) Source # 
Instance details

Defined in Database.Immutable.Internal

Methods

(==) :: Id a -> Id a -> Bool #

(/=) :: Id a -> Id a -> Bool #

Ord (Id a) Source # 
Instance details

Defined in Database.Immutable.Internal

Methods

compare :: Id a -> Id a -> Ordering #

(<) :: Id a -> Id a -> Bool #

(<=) :: Id a -> Id a -> Bool #

(>) :: Id a -> Id a -> Bool #

(>=) :: Id a -> Id a -> Bool #

max :: Id a -> Id a -> Id a #

min :: Id a -> Id a -> Id a #

Show (Id a) Source # 
Instance details

Defined in Database.Immutable.Internal

Methods

showsPrec :: Int -> Id a -> ShowS #

show :: Id a -> String #

showList :: [Id a] -> ShowS #

Serialize (Id a) Source # 
Instance details

Defined in Database.Immutable.Internal

Methods

put :: Putter (Id a) #

get :: Get (Id a) #

newtype Limit a Source #

Limit the number of elements read after an Id.

Constructors

Limit Word32 
Instances
Eq (Limit a) Source # 
Instance details

Defined in Database.Immutable.Internal

Methods

(==) :: Limit a -> Limit a -> Bool #

(/=) :: Limit a -> Limit a -> Bool #

Ord (Limit a) Source # 
Instance details

Defined in Database.Immutable.Internal

Methods

compare :: Limit a -> Limit a -> Ordering #

(<) :: Limit a -> Limit a -> Bool #

(<=) :: Limit a -> Limit a -> Bool #

(>) :: Limit a -> Limit a -> Bool #

(>=) :: Limit a -> Limit a -> Bool #

max :: Limit a -> Limit a -> Limit a #

min :: Limit a -> Limit a -> Limit a #

Show (Limit a) Source # 
Instance details

Defined in Database.Immutable.Internal

Methods

showsPrec :: Int -> Limit a -> ShowS #

show :: Limit a -> String #

showList :: [Limit a] -> ShowS #

Serialize (Limit a) Source # 
Instance details

Defined in Database.Immutable.Internal

Methods

put :: Putter (Limit a) #

get :: Get (Limit a) #

incId :: Id a -> Id a Source #

addLimit :: Id a -> Limit a -> Id a Source #

subIds :: Id a -> Id a -> Limit a Source #

Querying

(!) :: Serialize a => DB indexes a -> Id a -> Maybe a Source #

O(1) Yield the database element at the specified position.

slice :: Serialize a => Id a -> Limit a -> DB indexes a -> [a] Source #

O(n) Yield a slice of the database. The database must contain at least i+n elements.

lookup Source #

Arguments

:: Serialize a 
=> LookupIndex indexes s v a 
=> Name s

Index name

-> v

Index value

-> DB indexes a

Database

-> [a]

Resulting items

O(n) Lookup by index, n being the count of returned elements.

Example:

lookup personsDB #nameIndex "Phil" -- Return all elements named "Phil"