-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Efficient in memory indexed database -- -- Please see the README on GitHub at -- https://github.com/pkamenarsky/memdb#readme @package memdb @version 1.0.0.2 module Multimap.ByteString new :: IO Multimap insert :: Multimap -> ByteString -> Word32 -> IO () lookup :: Multimap -> ByteString -> IO [Word32] data Multimap module Multimap.Word32 new :: IO Multimap insert :: Multimap -> Word32 -> Word32 -> IO () lookup :: Multimap -> Word32 -> IO [Word32] data Multimap module Database.Immutable.Write -- | Offset into the database. newtype Id a Id :: Word32 -> Id a [getId] :: Id a -> Word32 -- | Limit the number of elements read after an Id. newtype Limit a Limit :: Word32 -> Limit a [getLimit] :: Limit a -> Word32 -- | Increment Id. incId :: Id a -> Id a -- | Subtract two indexes, returning a Limit. subIds :: Id a -> Id a -> Limit a -- | Write data sequentially to a database file. Database files can be read -- back using readDB. -- -- An additional file path.meta is produced holding the number -- of written elements. writeDB :: Serialize a => FilePath -> ((a -> IO ()) -> IO r) -> IO r -- | Creata a database from a list. Databases can be created back using -- createDB. fromList :: Serialize a => [a] -> ByteString module Database.Immutable.Read -- | Create a database from a ByteString and build up in-memory -- indexes according to the Indexes description. createDB :: forall indexes a. Serialize a => InsertIndex indexes a => ByteString -> Int -> Maybe (Int -> Int -> IO ()) -> Indexes indexes a -> IO (Either String (DB indexes a)) -- | Read a database from a file path and build up in-memory indexes -- according to the Indexes description. readDB :: forall indexes a. Serialize a => InsertIndex indexes a => FilePath -> Maybe (Int -> Int -> IO ()) -> Indexes indexes a -> IO (Either String (DB indexes a)) -- | Type tying a typelevel Symbol to a value. -- -- Name has an IsLabel instance and can thus be created by -- using the overloaded labels syntax (i.e. #someName) when the -- OverloadedLabels GHC extension is enabled. data Name (a :: Symbol) -- | Indexes description. Currently, there are two supported index -- types: Word32 and ByteString. Both can be specified -- using the utility functions word32Index and -- byteStringIndex, respectively. -- -- For example, one might define indexes over a datatype in the following -- way: -- --
-- data Person = Person
-- { name :: String
-- , age :: Int
-- } deriving (Generic, Serialize)
--
-- personIndexes
-- = byteStringIndex #nameIndex (pack . name)
-- $ word32Index #ageIndex (fromIntegral . age)
-- unindexed
--
--
-- Composite or computed indexes can be built by supplying an appropriate
-- function to byteStringIndex or word32Index, e.g:
--
-- -- personIndexes -- = byteStringIndex #nameAndAgePlusOneIndex -- (\p -> pack (name p <> show (age p + 1))) -- unindexed --data Indexes (indexes :: [(Symbol, *)]) a -- | Default Indexes description, specifying an unindexed database. unindexed :: Indexes '[] a -- | Add a ByteString index to an Indexes description to be -- built when reading a database. byteStringIndex :: KnownSymbol s => Name s -> (a -> b) -> (b -> ByteString) -> Indexes indexes a -> Indexes ('(s, ByteStringIndex b) : indexes) a -- | Add a Word32 index to an Indexes description to be built -- when reading a database. word32Index :: KnownSymbol s => Name s -> (a -> b) -> (b -> Word32) -> Indexes indexes a -> Indexes ('(s, Word32Index b) : indexes) a -- | 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. module Database.Immutable -- | 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. data DB (indexes :: [(Symbol, *)]) a data ByteStringIndex a data Word32Index a -- | Offset into the database. newtype Id a Id :: Word32 -> Id a -- | Limit the number of elements read after an Id. newtype Limit a Limit :: Word32 -> Limit a -- | O(1) Return number of records contained in the database. length :: DB indexes a -> Limit a -- | Zero Id. zeroId :: Id a -- | Increment Id. incId :: Id a -> Id a -- | Add a Limit to an Id. addLimit :: Id a -> Limit a -> Id a -- | Subtract two indexes, returning a Limit. subIds :: Id a -> Id a -> Limit a -- | O(1) Return the database element at the specified position. (!) :: Serialize a => DB indexes a -> Id a -> Maybe a -- | O(n) Return a slice of the database. The database must contain -- at least i+n elements. slice :: Serialize a => Id a -> Limit a -> DB indexes a -> [a] -- | O(n) Lookup by index, n being the count of returned -- elements. -- -- Example: -- --
-- lookup personsDB #nameIndex "Phil" -- Return all elements named "Phil" --lookup :: forall indexes s v a. Serialize a => LookupIndex indexes s v a => Name s -> v -> DB indexes a -> [a]