-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Type safe, in-memory dictionary with multidimensional keys. -- -- Type safe, in-memory dictionary with multidimensional keys. Similar to -- ixset, higgsset, tables. But offers: type safe interface, -- auto-increment dimensions, specifying the relationships between the -- key dimension and the elements (one-one, one-many, many-one, -- many-many), performance. @package data-store @version 0.3.0.1 module Data.Store.Internal.Type moduleName :: String -- | This is type-level tag for tagging dimensions of key and the index of -- a store. You can think of M as an abbreviation for -- many. -- --
-- RawKey (O :. O :. O :. M :. O) (ContentID :. String :. String :. String :. Double) ~ (ContentID :. String :. String :. [String] :. Double) --class (Ord k, Enum k, Bounded k) => Auto k -- | The store data type has four type arguments that define what and how -- things are stored. -- -- The krs (key relation specification) and irs (index -- relation specification) define the relations between the dimensions of -- the key and the elements. To that end, we use O and -- M type-level tags and -- 'Data.Store.Type.Internal.(:.)' data type to create tuple of -- these tags (to describe all the dimensions). -- -- The possible relations are as follows: -- --
-- type ContentStoreKRS = O :. O :. O :. M :. O -- type ContentStoreIRS = O :. O :. M :. M :. M -- type ContentStoreTS = ContentID :. String :. String :. String :. Double -- type ContentStore = Store ContentStoreKRS ContentStoreIRS ContentStoreTS Content ---- -- See also: -- -- data Store tag krs irs ts v Store :: !(IntMap (IKey krs ts, v)) -> !(Index irs ts) -> {-# UNPACK #-} !Int -> Store tag krs irs ts v storeV :: Store tag krs irs ts v -> !(IntMap (IKey krs ts, v)) storeI :: Store tag krs irs ts v -> !(Index irs ts) storeNID :: Store tag krs irs ts v -> {-# UNPACK #-} !Int data GenericKey dim rs ts KN :: !(dim r t) -> !(GenericKey dim rt tt) -> GenericKey dim (r :. rt) (t :. tt) K1 :: !(dim r t) -> GenericKey dim r t type Key = GenericKey KeyDimension type IKey = GenericKey IKeyDimension data Index rs ts IN :: !(IndexDimension r t) -> !(Index rt tt) -> Index (r :. rt) (t :. tt) I1 :: !(IndexDimension r t) -> Index r t data KeyDimension r t KeyDimensionO :: t -> KeyDimension O t KeyDimensionM :: [t] -> KeyDimension M t KeyDimensionA :: KeyDimension O t data IKeyDimension r t IKeyDimensionO :: t -> IKeyDimension O t IKeyDimensionM :: [t] -> IKeyDimension M t data IndexDimension r t IndexDimensionO :: !(Map t Int) -> IndexDimension O t IndexDimensionM :: !(Map t IntSet) -> IndexDimension M t class GetDimension n a getDimension :: GetDimension n a => n -> a -> RawDimensionType n a data TT data FF class Empty a empty :: Empty a => a class EmptyProxy flag a emptyProxy :: EmptyProxy flag a => flag -> a -- | Data type for creating tuples, it is used to: -- --
-- M :. O :. O :. M ---- --
-- Int :. Double :. String :. String ---- --
-- [1, 2, 3] :. 3.5 :. "Foo" :. ["Bar1", "Bar2"] --data (:.) h t (:.) :: h -> t -> :. h t instance Typeable5 Store instance Typeable2 IKeyDimension instance Typeable2 KeyDimension instance (NFData a, NFData b) => NFData (a :. b) instance (NFData t, NFData (IKey rt tt)) => NFData (IKey (r :. rt) (t :. tt)) instance NFData t => NFData (IKey M t) instance NFData t => NFData (IKey O t) instance NFData t => NFData (IKeyDimension r t) instance (NFData t, NFData (Index rt tt)) => NFData (Index (r :. rt) (t :. tt)) instance NFData t => NFData (Index M t) instance NFData t => NFData (Index O t) instance NFData t => NFData (IndexDimension r t) instance (NFData e, NFData (IKey krs ts), NFData (Index irs ts)) => NFData (Store tag krs irs ts e) instance Empty (Index irs ts) => Empty (Store tag krs irs ts e) instance (Ord t, Empty (Index rt tt)) => Empty (Index (M :. rt) (t :. tt)) instance (Ord t, Empty (Index rt tt)) => Empty (Index (O :. rt) (t :. tt)) instance Ord t => Empty (Index M t) instance Ord t => Empty (Index O t) instance GetDimension n (Index rt tt) => GetDimension (S n) (Index (r :. rt) (t :. tt)) instance GetDimension Z (Index (r :. rt) (t :. tt)) instance GetDimension Z (Index M t) instance GetDimension Z (Index O t) instance Show t => Show (IndexDimension r t) instance (Ord t, SafeCopy t) => SafeCopy (IndexDimension M t) instance (Ord t, SafeCopy t) => SafeCopy (IndexDimension O t) instance (Ord t, Serialize t) => Serialize (IndexDimension M t) instance (Ord t, Serialize t) => Serialize (IndexDimension O t) instance Show t => Show (IKeyDimension r t) instance (Ord t, SafeCopy t) => SafeCopy (IKeyDimension M t) instance (Ord t, SafeCopy t) => SafeCopy (IKeyDimension O t) instance (Ord t, Serialize t) => Serialize (IKeyDimension M t) instance (Ord t, Serialize t) => Serialize (IKeyDimension O t) instance Eq (IKeyDimension r t) instance Show t => Show (KeyDimension r t) instance (Show t, Show (Index rt tt)) => Show (Index (r :. rt) (t :. tt)) instance Show t => Show (Index M t) instance Show t => Show (Index O t) instance Typeable2 Index instance (Ord t, SafeCopy t, SafeCopy (Index rt tt)) => SafeCopy (Index (M :. rt) (t :. tt)) instance (Ord t, SafeCopy t, SafeCopy (Index rt tt)) => SafeCopy (Index (O :. rt) (t :. tt)) instance (Ord t, SafeCopy t) => SafeCopy (Index M t) instance (Ord t, SafeCopy t) => SafeCopy (Index O t) instance (Ord t, Serialize t, Serialize (Index rt tt)) => Serialize (Index (M :. rt) (t :. tt)) instance (Ord t, Serialize t, Serialize (Index rt tt)) => Serialize (Index (O :. rt) (t :. tt)) instance (Ord t, Serialize t) => Serialize (Index M t) instance (Ord t, Serialize t) => Serialize (Index O t) instance (Show t, Show (IKey rt tt)) => Show (IKey (r :. rt) (t :. tt)) instance Show t => Show (IKey M t) instance Show t => Show (IKey O t) instance (Show t, Show (Key rt tt)) => Show (Key (r :. rt) (t :. tt)) instance Show t => Show (Key M t) instance Show t => Show (Key O t) instance Typeable2 (GenericKey dim) instance (SafeCopy (GenericKey dim rt tt), SafeCopy (dim r t)) => SafeCopy (GenericKey dim (r :. rt) (t :. tt)) instance SafeCopy (dim M t) => SafeCopy (GenericKey dim M t) instance SafeCopy (dim O t) => SafeCopy (GenericKey dim O t) instance (Serialize (GenericKey dim rt tt), Serialize (dim r t)) => Serialize (GenericKey dim (r :. rt) (t :. tt)) instance Serialize (dim M t) => Serialize (GenericKey dim M t) instance Serialize (dim O t) => Serialize (GenericKey dim O t) instance Eq (GenericKey IKeyDimension rs ts) instance (Show (IKey krs ts), Show v) => Show (Store tag krs irs ts v) instance (SafeCopy (IKey krs ts), SafeCopy (Index irs ts), SafeCopy v) => SafeCopy (Store tag krs irs ts v) instance (Serialize (IKey krs ts), Serialize (Index irs ts), Serialize v) => Serialize (Store tag krs irs ts v) instance (Show h, Show t) => Show (h :. t) instance (Ord k, Enum k, Bounded k) => Auto k module Data.Store.Internal.Function moduleName :: String genericSubset :: Empty (Index irs ts) => IntSet -> Store tag krs irs ts v -> Store tag krs irs ts v genericLookup :: IntSet -> Store tag krs irs ts v -> [(RawKey krs ts, v)] genericUpdateWithKey :: (Applicative f, Monad f) => (IKey krs ts -> Int -> Store tag krs irs ts e -> f (Store tag krs irs ts e)) -> (RawKey krs ts -> e -> Maybe (e, Maybe (Key krs ts))) -> IntSet -> Store tag krs irs ts e -> f (Store tag krs irs ts e) mergeKeys :: Key krs ts -> IKey krs ts -> IKey krs ts keyInternalToRaw :: IKey krs ts -> RawKey krs ts keyFromInternal :: IKey krs ts -> Key krs ts keyToInternal :: Index irs ts -> Key krs ts -> IKey krs ts nextKey :: Auto t => IndexDimension r t -> t genericInsert :: Applicative f => (IKey krs ts -> Int -> Store tag krs irs ts e -> f (Store tag krs irs ts e)) -> IKey krs ts -> e -> Store tag krs irs ts e -> f (Store tag krs irs ts e) -- | Inserts the given element identifier into the store's index under the -- given internal key. -- -- In case of collisions: returns Nothing. indexInsertID :: IKey krs ts -> Int -> Store tag krs irs ts e -> Maybe (Store tag krs irs ts e) -- | Inserts the given element identifier into the store's index under the -- given internal key. -- -- In case of collisions: deletes them. indexInsertID' :: IKey krs ts -> Int -> Store tag krs irs ts e -> Identity (Store tag krs irs ts e) -- | UNSAFE. Inserts the given element identifier into the store's index -- under the given internal key. -- -- In case of collisions: ignores them. indexInsertID'' :: IKey krs ts -> Int -> Store tag krs irs ts e -> Identity (Store tag krs irs ts e) findCollisions :: IKey krs ts -> Index irs ts -> [Int] -- | Deletes EID fron an index. indexDeleteID :: IKey krs ts -> Int -> Index irs ts -> Index irs ts module Data.Store.Selection -- | The expression (sDim .< c) is a selection that includes -- value x if and only if it is indexed in the sDim -- dimension with a key k such that k < c. -- -- Complexity of resolve: O(log n + k) (.<) :: GetDimension n (Index irs ts) => (tag, n) -> DimensionType n irs ts -> Selection tag krs irs ts -- | The expression (sDim .<= c) is a selection that includes -- value x if and only if it is indexed in the sDim -- dimension with a key k such that k <= c. -- -- Complexity of resolve: O(log n + k) (.<=) :: GetDimension n (Index irs ts) => (tag, n) -> DimensionType n irs ts -> Selection tag krs irs ts -- | The expression (sDim .> c) is a selection that includes -- value x if and only if it is indexed in the sDim -- dimension with a key k such that k > c. -- -- Complexity of resolve: O(log n + k) (.>) :: GetDimension n (Index irs ts) => (tag, n) -> DimensionType n irs ts -> Selection tag krs irs ts -- | The expression (sDim .>= c) is a selection that includes -- value x if and only if it is indexed in the sDim -- dimension with a key k such that k >= c. -- -- Complexity of resolve: O(log n + k) (.>=) :: GetDimension n (Index irs ts) => (tag, n) -> DimensionType n irs ts -> Selection tag krs irs ts -- | The expression (sDim ./= c) is a selection that includes -- value x if and only if it is indexed in the sDim -- dimension with a key k such that k /= c. -- -- Complexity of resolve: O(n) (./=) :: GetDimension n (Index irs ts) => (tag, n) -> DimensionType n irs ts -> Selection tag krs irs ts -- | The expression (sDim .== c) is a selection that includes -- value x if and only if it is indexed in the sDim -- dimension with a key k such that k == c. -- -- Complexity of resolve: O(log n) (.==) :: GetDimension n (Index irs ts) => (tag, n) -> DimensionType n irs ts -> Selection tag krs irs ts -- | The expression (s1 .&& s2) is a selection that -- includes the intersection of the selections s1 and -- s2. -- -- Complexity of resolve: O(c(s1) + c(s2) + s(s1) + -- s(s2) (.&&) :: (IsSelection s1, IsSelection s2) => s1 tag krs irs ts -> s2 tag krs irs ts -> Selection tag krs irs ts -- | The expression (s1 .|| s2) is a selection that includes the -- union of the selections s1 and s2. -- -- Complexity of resolve: O(c(s1) + c(s2) + s(s1) + -- s(s2) (.||) :: (IsSelection s1, IsSelection s2) => s1 tag krs irs ts -> s2 tag krs irs ts -> Selection tag krs irs ts -- | The expression (not' sel) is a selection that includes all -- values except those that match the selection sel. not :: IsSelection sel => sel tag krs irs ts -> Selection tag krs irs ts -- | Selection that matches the intersection of all the selections in the -- list or everything if the list is empty. all :: [Selection tag krs irs ts] -> Selection tag krs irs ts -- | The expression (all1D d ss) is equivalent to -- (all' $ map ($ d) ss). all1D :: (tag, n) -> [(tag, n) -> Selection tag krs irs ts] -> Selection tag krs irs ts -- | Selection that matches the union of all the selections in the list or -- nothing if the list is empty. any :: [Selection tag krs irs ts] -> Selection tag krs irs ts -- | The expression (any1D d ss) is equivalent to -- (any' $ map ($ d) ss). any1D :: (tag, n) -> [(tag, n) -> Selection tag krs irs ts] -> Selection tag krs irs ts class IsSelection sel resolve :: IsSelection sel => sel tag krs irs ts -> Store tag krs irs ts v -> IntSet data Selection tag krs irs ts instance IsSelection (SelectionDimension n) instance IsSelection Selection -- | Dictionary with multidimensional keys and type-safe interface. -- -- These modules are intended to be imported qualified to avoid name -- clashes with prelude, e.g.: -- --
-- import qualified Data.Store as S -- import Data.Store (M, O, (.:), (.:.), (:.), (.<), (.<=), (.>), (.>=), (./=), (.==), (.&&), (.||)) ---- -- Throughout out the documentation, the examples will be based on this -- code: -- --
-- {-# LANGUAGE TypeOperators #-}
--
-- module Example01
-- where
--
-- --------------------------------------------------------------------------------
-- import Control.Applicative
-- import qualified Control.Monad.State as State
-- --------------------------------------------------------------------------------
-- import qualified Data.Store as S
-- import Data.Store (M, O, (.:), (.:.), (:.)(..), (.<), (.<=), (.>), (.>=), (./=), (.==), (.&&), (.||))
-- --------------------------------------------------------------------------------
--
-- data Content = Content
-- { contentName :: String
-- , contentBody :: String
-- , contentTags :: [String]
-- , contentRating :: Double
-- }
--
-- type ContentID = Int
--
-- -- Content has one ID, only one content can have a given ID.
-- -- Content has one name, only one content can have a given name.
-- -- Content has one body, many contents can have the same content.
-- -- Content has many tags, many contents can have the same tag.
-- -- Content has one rating, many contents can have the same rating.
--
-- data ContentStoreTag = ContentStoreTag
--
-- type ContentStoreTS = ContentID :. String :. String :. String :. Double
-- type ContentStoreKRS = O :. O :. O :. M :. O
-- type ContentStoreIRS = O :. O :. M :. M :. M
-- type ContentStore = S.Store ContentStoreTag ContentStoreKRS ContentStoreIRS ContentStoreTS Content
-- type ContentStoreKey = S.Key ContentStoreKRS ContentStoreTS
-- type ContentStoreSelection = S.Selection ContentStoreTag ContentStoreKRS ContentStoreIRS ContentStoreTS
--
-- sContentID :: (ContentStoreTag, S.N0)
-- sContentID = (ContentStoreTag, S.n0)
--
-- sContentName :: (ContentStoreTag, S.N1)
-- sContentName = (ContentStoreTag, S.n1)
--
-- sContentBody :: (ContentStoreTag, S.N2)
-- sContentBody = (ContentStoreTag, S.n2)
--
-- sContentTag :: (ContentStoreTag, S.N3)
-- sContentTag = (ContentStoreTag, S.n3)
--
-- sContentRating :: (ContentStoreTag, S.N4)
-- sContentRating = (ContentStoreTag, S.n4)
--
--
-- Glossary
--
-- -- type ContentStoreKRS = O :. O :. O :. M :. O -- type ContentStoreIRS = O :. O :. M :. M :. M -- type ContentStoreTS = ContentID :. String :. String :. String :. Double -- type ContentStore = Store ContentStoreKRS ContentStoreIRS ContentStoreTS Content ---- -- See also: -- -- data Store tag krs irs ts v type Key = GenericKey KeyDimension data KeyDimension r t -- | The pupose of the RawKey type family is to derive a -- type of a "raw key" that is easier to pattern match against than -- Key. -- -- Example: -- --
-- RawKey (O :. O :. O :. M :. O) (ContentID :. String :. String :. String :. Double) ~ (ContentID :. String :. String :. [String] :. Double) ---- | This is type-level tag for tagging dimensions of key and the index of -- a store. You can think of M as an abbreviation for -- many. -- --
-- M :. O :. O :. M ---- --
-- Int :. Double :. String :. String ---- --
-- [1, 2, 3] :. 3.5 :. "Foo" :. ["Bar1", "Bar2"] --data (:.) h t (:.) :: h -> t -> :. h t class (Ord k, Enum k, Bounded k) => Auto k empty :: Empty a => a -- | The expression (singleton k v) is store that contains -- only the (k, v) as a key-element pair. singleton :: Empty (Index irs ts) => Key krs ts -> v -> Store tag krs irs ts v -- | The expression (insert k e old) is either -- Nothing if inserting the (k, e) key-element pair -- would cause a collision or (Just (rk, new)), where -- rk is the raw key of k and new is store -- containing the same key-element pairs as old plus (k, -- e). -- -- Examples: -- --
-- >>> let content = Content "name" "body" ["t1", "t2"] 0.5 -- -- >>> insert (contentKey content) content store -- > Just (1 :. "name" :. "body" :. ["t1", "t2"] :. 0.5, <updated_store>) ---- -- See also: -- -- insert :: Key krs ts -> v -> Store tag krs irs ts v -> Maybe (RawKey krs ts, Store tag krs irs ts v) -- | The expression (insert' k v old) is (rk, -- new), where rk is the raw key of k and -- new is a store that contains the same key-element pairs as -- old plus (k, e). Any key-value pairs from -- old colliding with (k, e) are not included in -- new. -- -- See also: -- -- insert' :: Key krs ts -> e -> Store tag krs irs ts e -> (RawKey krs ts, Store tag krs irs ts e) -- | UNSAFE! This function can corrupt the store. -- -- The expression (unsafeInsert k v old) is (rk, -- new), where rk is the raw key of k and -- new is a store that contains the same key-element pairs as -- old plus (k, e). Any key-value pairs from -- old colliding with (k, e) will cause UNDEFINED -- BEHAVIOUR. -- -- See also: -- -- unsafeInsert :: Key krs ts -> e -> Store tag krs irs ts e -> (RawKey krs ts, Store tag krs irs ts e) -- | The expression (updateWithKey tr sel old) is (Just -- new) where new is a store containing the same -- key-element pairs as old except for any key-element pairs -- (k, e) that match the selection sel, those are -- updated as follows: -- --
-- instance Storable Content where -- type StoreKRS Content = O :. O :. O :. M :. O -- type StoreIRS Content = O :. O :. M :. M :. M -- type StoreTS Content = ContentID :. String :. String :. String :. Double -- -- key (Content cn cb cts cr) = -- S.dimA .: S.dimO cn .: S.dimO cb .: S.dimM cts .:. S.dimO cr --class Storable v where type family StoreKRS t :: * type family StoreIRS t :: * type family StoreTS t :: * key :: Storable v => v -> Key (StoreKRS v) (StoreTS v) -- | See insert. insert :: Storable v => v -> Store tag (StoreKRS v) (StoreIRS v) (StoreTS v) v -> Maybe (RawKey (StoreKRS v) (StoreTS v), Store tag (StoreKRS v) (StoreIRS v) (StoreTS v) v) -- | See insert'. insert' :: Storable v => v -> Store tag (StoreKRS v) (StoreIRS v) (StoreTS v) v -> (RawKey (StoreKRS v) (StoreTS v), Store tag (StoreKRS v) (StoreIRS v) (StoreTS v) v) -- | See updateWithKey. updateWithKey :: (Storable v, IsSelection sel) => (RawKey (StoreKRS v) (StoreTS v) -> v -> Maybe v) -> sel tag (StoreKRS v) (StoreIRS v) (StoreTS v) -> Store tag (StoreKRS v) (StoreIRS v) (StoreTS v) v -> Maybe (Store tag (StoreKRS v) (StoreIRS v) (StoreTS v) v) -- | See updateWithKey'. updateWithKey' :: (Storable v, IsSelection sel) => (RawKey (StoreKRS v) (StoreTS v) -> v -> Maybe v) -> sel tag (StoreKRS v) (StoreIRS v) (StoreTS v) -> Store tag (StoreKRS v) (StoreIRS v) (StoreTS v) v -> Store tag (StoreKRS v) (StoreIRS v) (StoreTS v) v -- | See update. update :: (Storable v, IsSelection sel) => (v -> Maybe v) -> sel tag (StoreKRS v) (StoreIRS v) (StoreTS v) -> Store tag (StoreKRS v) (StoreIRS v) (StoreTS v) v -> Maybe (Store tag (StoreKRS v) (StoreIRS v) (StoreTS v) v) -- | See update'. update' :: (Storable v, IsSelection sel) => (v -> Maybe v) -> sel tag (StoreKRS v) (StoreIRS v) (StoreTS v) -> Store tag (StoreKRS v) (StoreIRS v) (StoreTS v) v -> Store tag (StoreKRS v) (StoreIRS v) (StoreTS v) v -- | See fromList. fromList :: (Empty (Index (StoreIRS v) (StoreTS v)), Storable v) => [v] -> Maybe (Store tag (StoreKRS v) (StoreIRS v) (StoreTS v) v) -- | See fromList'. fromList' :: (Empty (Index (StoreIRS v) (StoreTS v)), Storable v) => [v] -> Store tag (StoreKRS v) (StoreIRS v) (StoreTS v) v module Data.Store.Lens class With sel with :: (With sel, Empty (Index irs ts)) => sel tag krs irs ts -> Lens' (Store tag krs irs ts v) (Store tag krs irs ts v) instance IsSelection sel => With sel