packages feed

refcount 0.0.1 → 0.1.1

raw patch · 3 files changed

+61/−6 lines, 3 filesdep +Cabaldep +HUnitdep +QuickCheckdep ~basedep ~hashabledep ~unordered-containersPVP ok

version bump matches the API change (PVP)

Dependencies added: Cabal, HUnit, QuickCheck, refcount, test-framework, test-framework-hunit, test-framework-quickcheck2, test-framework-th

Dependency ranges changed: base, hashable, unordered-containers

API changes (from Hackage documentation)

+ Data.Refcount: fromList :: (Hashable a, Eq a) => [a] -> Refcount a
+ Data.Refcount: instance (Arbitrary a, Hashable a, Eq a) => Arbitrary (Refcount a)
+ Data.Refcount: instance Constructor C1_0Refcount
+ Data.Refcount: instance Datatype D1Refcount
+ Data.Refcount: instance Eq a => Eq (Refcount a)
+ Data.Refcount: instance Generic (Refcount a)
+ Data.Refcount: instance Selector S1_0_0Refcount
+ Data.Refcount: instance Show a => Show (Refcount a)

Files

Data/Refcount.hs view
@@ -1,27 +1,40 @@+{-# LANGUAGE DeriveGeneric #-} module Data.Refcount ( Refcount (..)                      , refcount                      , refcounted                      , insertRef                      , deleteRef                      , removeRef+                     , Data.Refcount.fromList                      ) where  import Control.Applicative ((<$>))+import Data.Foldable as Foldable import Data.Maybe import Data.Monoid import Data.Hashable import Data.HashMap.Strict as HashMap+import GHC.Generics+import Test.QuickCheck (Arbitrary (..))  -- | Maintain a collection of objects with duplication counts. newtype Refcount a = Refcount { unRefcount :: HashMap a Int }+  deriving (Show, Generic, Eq)  instance (Hashable a, Eq a) => Monoid (Refcount a) where   mempty = Refcount empty   mappend (Refcount a) (Refcount b) = Refcount $ unionWith (+) a b +instance (Arbitrary a, Hashable a, Eq a) => Arbitrary (Refcount a) where+  arbitrary = Data.Refcount.fromList <$> arbitrary+ -- | Retrieve the refcounted objects. refcounted :: Refcount a -> [a] refcounted = keys . unRefcount++-- | Create a counted structure from a list of elements.+fromList :: (Hashable a, Eq a) => [a] -> Refcount a+fromList = Foldable.foldl' (\rc r -> insertRef r rc) mempty  -- | Lookup the count of an object. refcount :: (Hashable a, Eq a) => a -> Refcount a -> Int
refcount.cabal view
@@ -1,5 +1,5 @@ name:               refcount-version:            0.0.1+version:            0.1.1 synopsis:           Container with element counts category:           Data license:            MIT@@ -10,15 +10,34 @@ build-type:         Simple cabal-version:      >= 1.9.2 +source-repository head+  type: git+  location: https://github.com/RobotGymnast/refcount.git+ library     hs-source-dirs:   .     ghc-options:      -Wall     exposed-modules:  Data.Refcount      build-depends: base == 4.*-                 , hashable == 1.2.1.*-                 , unordered-containers == 0.2.4.*+                 , hashable == 1.2.*+                 , unordered-containers == 0.2.*+                 , QuickCheck >= 2.6 && < 2.8 -source-repository head-  type: git-  location: https://github.com/RobotGymnast/refcount+test-suite Tests+    type:           exitcode-stdio-1.0+    hs-source-dirs: . test+    main-is:        TestMain.hs+    GHC-Options:    -Wall -fno-warn-missing-signatures++    build-depends : base+                  , hashable+                  , refcount+                  , HUnit == 1.2.*+                  , QuickCheck+                  , test-framework-quickcheck2 == 0.3.*+                  , test-framework-hunit == 0.3.*+                  , test-framework-th+                  , test-framework+                  , unordered-containers+                  , Cabal
+ test/TestMain.hs view
@@ -0,0 +1,23 @@+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TemplateHaskell #-}+import Control.Applicative+import Data.Refcount+import Test.Framework.Providers.QuickCheck2+import Test.Framework.TH++main = $(defaultMainGenerator)++infix 4 ==.++(==.) :: (Applicative f, Eq a) => f a -> f a -> f Bool+(==.) = liftA2 (==)++prop_insert_remove :: a ~ Integer => a -> Refcount a -> Bool+prop_insert_remove a = (deleteRef a . insertRef a) ==. Just++prop_insert_remove_refcount :: a ~ Integer => a -> Refcount a -> Bool+prop_insert_remove_refcount a r+    = let i = insertRef a r+          d = deleteRef a i+      in refcount a i == refcount a r + 1+      && (refcount a <$> d) == Just (refcount a i - 1)