-- 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.4 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. -- -- -- -- See also: -- -- data M -- | This is type-level tag for tagging dimensions of key and the index of -- a store. You can think of O as an abbreviation for -- one. -- -- -- -- See also: -- -- data O -- | Type-level zero. data Z Z :: Z -- | Type-level successor of a number. data S n S :: n -> S n type N0 = Z type N1 = S N0 type N2 = S N1 type N3 = S N2 type N4 = S N3 type N5 = S N4 type N6 = S N5 type N7 = S N6 type N8 = S N7 type N9 = S N8 type N10 = S N9 n0 :: N0 n1 :: N1 n2 :: N2 n3 :: N3 n4 :: N4 n5 :: N5 n6 :: N6 n7 :: N7 n8 :: N8 n9 :: N9 n10 :: N10 -- | 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)
--   
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: -- -- -- -- The ts (type specification) defines the type of the key's -- dimensions and finally v is the type of the elements stored. -- -- In our example with Content, we have five dimensions: ID, -- name, body, tags and rating. We would like our store to have these -- properties: -- -- -- -- So in our case, we define: -- --
--   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 -- -- -- -- The implementation is based on Data.Map, Data.Set, -- Data.IntMap and Data.IntSet. -- -- The following variables and constants are used in Big-O notation: -- -- module Data.Store -- | 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: -- -- -- -- The ts (type specification) defines the type of the key's -- dimensions and finally v is the type of the elements stored. -- -- In our example with Content, we have five dimensions: ID, -- name, body, tags and rating. We would like our store to have these -- properties: -- -- -- -- So in our case, we define: -- --
--   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. -- -- -- -- See also: -- -- data M -- | This is type-level tag for tagging dimensions of key and the index of -- a store. You can think of O as an abbreviation for -- one. -- -- -- -- See also: -- -- data O -- | 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 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>)
--   
-- -- Complexity: O(min(n, W) + k * (log n + min(n, W))) -- -- 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. -- -- Complexity: O(min(n, W) + k * (log n + min(n, W))) -- -- 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: -- -- -- -- If any of the updated key-element pairs would cause a collision, the -- result is Nothing. -- -- Complexity: O(c + s * (min(n, W) + k * (log n + min(n, W)))) -- -- See also: -- -- updateWithKey :: IsSelection sel => (RawKey krs ts -> v -> Maybe (v, Maybe (Key krs ts))) -> sel tag krs irs ts -> Store tag krs irs ts v -> Maybe (Store tag krs irs ts v) -- | The expression (updateWithKey' tr sel old) is -- 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: -- -- -- -- Any pairs of the original store old that would, after the -- update, cause collisons are not included in new. -- -- Complexity: O(c + s * d * (min(n, W) + k * (log n + min(n, -- W)))) -- -- See also: -- -- updateWithKey' :: IsSelection sel => (RawKey krs ts -> v -> Maybe (v, Maybe (Key krs ts))) -> sel tag krs irs ts -> Store tag krs irs ts v -> Store tag krs irs ts v -- | The expression (update tr sel s) is equivalent to -- (updateWithKey tr' sel s) where (tr' = (_ v -> -- tr v) = const tr). -- -- Complexity: O(c + s * (min(n, W) + q * log n)) update :: IsSelection sel => (v -> Maybe (v, Maybe (Key krs ts))) -> sel tag krs irs ts -> Store tag krs irs ts v -> Maybe (Store tag krs irs ts v) -- | The expression (update' tr sel s) is equivalent to -- (updateWithKey' tr' sel s) where (tr' = (_ v -> -- tr v) = const tr). -- -- Complexity: O(c + d * s * (min(n, W) + q * log n)) update' :: IsSelection sel => (v -> Maybe (v, Maybe (Key krs ts))) -> sel tag krs irs ts -> Store tag krs irs ts v -> Store tag krs irs ts v -- | The expression (updateElements tr sel s) is equivalent -- to (update tr' sel s) where (tr' = (maybe Nothing -- (v -> Just (v, Nothing)) . tr)). -- -- Complexity: O(c + s * min(n, W)) updateElements :: IsSelection sel => (v -> Maybe v) -> sel tag krs irs ts -> Store tag krs irs ts v -> Store tag krs irs ts v -- | The expression (delete sel old) is equivalent to -- (fromJust $ update (const Nothing) sel old). -- -- Complexity: O(c + s * (min(n, W) + q * log n) delete :: IsSelection sel => sel tag krs irs ts -> Store tag krs irs ts v -> Store tag krs irs ts v -- | The expression (map tr old) is store where every -- element of old was transformed using the function -- tr. map :: (v1 -> v2) -> Store tag krs irs ts v1 -> Store tag krs irs ts v2 -- | The expression (foldr f z s) folds the store using the -- given right-associative binary operator. foldr :: (v -> b -> b) -> b -> Store tag krs irs ts v -> b -- | The expression (foldrWithKey f z s) folds the store -- using the given right-associative operator. foldrWithKey :: (RawKey krs ts -> v -> b -> b) -> b -> Store tag krs irs ts v -> b -- | The expression (foldl f z s) folds the store using the -- given left-associative binary operator. foldl :: (b -> v -> b) -> b -> Store tag krs irs ts v -> b -- | The expression (foldlWithKey f z s) folds the store -- using the given left-associative operator. foldlWithKey :: (b -> RawKey krs ts -> v -> b) -> b -> Store tag krs irs ts v -> b -- | The expression (toList store) is a list of key-element -- pairs that are stored in store. toList :: Store tag krs irs ts v -> [(RawKey krs ts, v)] -- | The expression (elements store) is a list of elements -- that are stored in store. elements :: Store tag krs irs ts v -> [v] -- | The expression (keys store) is a list of pairs raw -- keys that are stored in store. keys :: Store tag krs irs ts v -> [RawKey krs ts] -- | The expression (fromList kvs) is either a) (Just -- store) where store is a store containing exactly the -- given key-element pairs or; b) Nothing if inserting any of -- the key-element pairs would cause a collision. -- -- See also: -- -- fromList :: Empty (Index irs ts) => [(Key krs ts, v)] -> Maybe (Store tag krs irs ts v) -- | The expression (fromList' kvs) is store -- containing the given key-element pairs (colliding pairs are not -- included). -- -- See also: -- -- fromList' :: Empty (Index irs ts) => [(Key krs ts, v)] -> Store tag krs irs ts v -- | UNSAFE! This function can corrupt the store. -- -- The expression (fromList' kvs) is store -- containing the given key-element pairs (colliding pairs cause -- UNDEFINED BEHAVIOUR). -- -- See also: -- -- unsafeFromList :: Empty (Index irs ts) => [(Key krs ts, v)] -> Store tag krs irs ts v -- | The expression (size store) is the number of elements -- in store. size :: Store tag krs irs ts v -> Int -- | The expression (lookup sel store) is list of (raw -- key)-element pairs that match the selection. -- -- Complexity: O(c + s * min(n, W)) lookup :: IsSelection sel => sel tag krs irs ts -> Store tag krs irs ts v -> [(RawKey krs ts, v)] data 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 -- | 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 -- | Function for creating an auto-increment dimension. Can be used instead -- of (dimO x) if the type is an instance of the -- Auto type-class. dimA :: Auto t => KeyDimension O t -- | Function for creating dimensions with the relation -- "one-anything". dimO :: Ord t => t -> KeyDimension O t -- | Function for creating dimensions with the relation -- "many-anything". dimM :: Ord t => [t] -> KeyDimension M t -- | Function for connecting one dimension and rest of the key. (.:) :: dim r t -> GenericKey dim rs1 ts1 -> GenericKey dim (r :. rs1) (t :. ts1) -- | Function for connecting one dimensions with another (most often the -- last dimension of the key). (.:.) :: dim r1 t1 -> dim r2 t2 -> GenericKey dim (r1 :. r2) (t1 :. t2) -- | Type-level successor of a number. data S n S :: n -> S n -- | Type-level zero. data Z type N0 = Z type N1 = S N0 type N2 = S N1 type N3 = S N2 type N4 = S N3 type N5 = S N4 type N6 = S N5 type N7 = S N6 type N8 = S N7 type N9 = S N8 type N10 = S N9 n0 :: N0 n1 :: N1 n2 :: N2 n3 :: N3 n4 :: N4 n5 :: N5 n6 :: N6 n7 :: N7 n8 :: N8 n9 :: N9 n10 :: N10 showIndex :: Show (Index irs ts) => Store tag krs irs ts v -> String printIndex :: Show (Index irs ts) => Store tag krs irs ts v -> IO () -- | The name of this module. moduleName :: String instance Empty (Index irs ts) => Monoid (Store tag krs irs ts v) instance Functor (Store tag krs irs ts) module Data.Store.Storable -- | This type-class facilitates the common use case where the key under -- which given values is to be indexed can be derived from the value. -- -- Example: -- -- The Storable type-class instance for our Content -- data type would look like this: -- --
--   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