packages feed

HiggsSet 0.1 → 0.1.1

raw patch · 2 files changed

+30/−26 lines, 2 filesdep +th-expand-synsdep ~containers

Dependencies added: th-expand-syns

Dependency ranges changed: containers

Files

HiggsSet.cabal view
@@ -7,7 +7,7 @@ -- The package version. See the Haskell package versioning policy -- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for -- standards guiding when and how versions should be incremented.-Version:             0.1+Version:             0.1.1  -- A short (one-line) description of the package. Synopsis:            A multi-index set with advanced query capabilites@@ -31,7 +31,7 @@                      start an issue on github.  -- URL for the project homepage or repository.-Homepage:            github.com/lpeterse/HiggsSet+Homepage:            http://github.com/lpeterse/HiggsSet  -- The license under which the package is released. License:             BSD3@@ -69,11 +69,12 @@   Build-depends:       base >= 4.2 && < 6                      , vector                           , TrieMap    >= 4.0.1-                     , containers +                     , containers >= 0.4.2.0                      , mtl                              , deepseq                          , bytestring                        , text+                     , th-expand-syns >= 0.3.0.2       -- Packages needed in order to build this package.
src/Data/HiggsSet.hs view
@@ -120,15 +120,17 @@ -- --   >  instance Indexable Book where --   >    type IndexOf Book = BookIndex---   >    project (IIsbn _)               x = [isbn x]+--   >    project (IIsbn _)               x = [IIsbn (isbn x)] --   >    project (IAuthor _)             x = map IAuthor (toList $ authors x)---   >    project (IPriceInEuro _)        x = [priceInEuro (price x)]+--   >    project (IPriceInEuro _)        x = [IPriceInEuro $ priceInEuro (price x)] --   >    project (IPublisherAndYear _ _) x = [IPublisherAndYear (publisher x) (year x)] --   >    project (INewerThan2000 _)      x = [INewerThan2000 | year x >= 2000]  --   >    project (ITitle _)              x = map ITitle $ words $ title x  class Indexable a where   type IndexOf a   project    :: IndexOf a -> a -> [IndexOf a]+  share      :: HiggsSet a (IndexOf a) -> a -> a+  share _ a   = a  -- | The associated index type needs to be an instance of `Index`. --   First of all this means that it needs to be an instance of @@ -233,27 +235,28 @@  -- | Insert an element to an 'HiggsSet'. Indexing takes place according to the class instances defined before. It is not checked whether such an element (according to 'Eq') already exists. If so, the set contains more than once afterwards. In such a case you may rather want to use 'update'. insert    :: forall a i.(Indexable a, Index i, IndexOf a ~ i) => a -> HiggsSet a i -> HiggsSet a i-insert a s = s { elements = IM.insert key a (elements s)-               , maxKey   = key-               , indizes  = V.accum -                              (foldl' -                                (\x y-> case x of-                                          SingletonMap m -> SingletonMap $ TM.insert y key m-                                          MultiMap     m -> MultiMap     $ TM.insertWith       -                                                                             -- unite with elements already existing at index position -                                                                             IS.union            -                                                                             -- the index position "where"-                                                                             y -                                                                             -- the new elements' key is the value of the index map-                                                                             (IS.singleton key) -                                                                             -- the index (TMap i IntSet)-                                                                             m                  -                                )-                              ) -                              (indizes s)                     -- the vector-                              [(fromEnum x, project x a) | x <- [minBound..maxBound :: i]]-                                                              -- list of index sections with index positions to add-               }+insert x s = let a = share s x+             in  a `seq` s { elements = IM.insert key a (elements s)+                           , maxKey   = key+                           , indizes  = V.accum +                                          (foldl' +                                            (\x y-> case x of+                                                      SingletonMap m -> SingletonMap $ TM.insert y key m+                                                      MultiMap     m -> MultiMap     $ TM.insertWith       +                                                                                         -- unite with elements already existing at index position +                                                                                         IS.union            +                                                                                         -- the index position "where"+                                                                                         y +                                                                                         -- the new elements' key is the value of the index map+                                                                                         (IS.singleton key) +                                                                                         -- the index (TMap i IntSet)+                                                                                         m                  +                                            )+                                          ) +                                          (indizes s)                     -- the vector+                                          [(fromEnum x, project x a) | x <- [minBound..maxBound :: i]]+                                                                          -- list of index sections with index positions to add+                           }              where                key = succ $ maxKey s