on master help sign in
Merge pull request #7 from BardurArantsson/split-types

Split UUID data type out into separate Cabal package

commita7329bbb30b42b3630ebf29ff67e64c5916c85c5 authorAntoine Latter <aslatter@gmail.com> dateSun 18 Jan 2015, 09:13 (12 years ago) parentf02a16603b5bcf
33 files changed+422−159
.gitignore+4−4 .travis.yml+4 travis-scripts/build.sh+27 travis-scripts/install.sh+13 uuid-types/CHANGES+3 CONTRIBUTORS → uuid-types/CONTRIBUTORS+2−1 uuid-types/Data/UUID/Types.hs+37 Data/UUID/Internal.hs → uuid-types/Data/UUID/Types/Internal.hs+12−5 Data/UUID/Builder.hs → uuid-types/Data/UUID/Types/Internal/Builder.hs+2−2 LICENSE → uuid-types/LICENSE Setup.hs → uuid-types/Setup.hs tests/BenchByteString.hs → uuid-types/tests/BenchByteString.hs+1−1 tests/BenchUUID.hs → uuid-types/tests/BenchUUID.hs+1−23 tests/TestUUID.hs → uuid-types/tests/TestUUID.hs+3−79 tests/summarize-bench-results.pl → uuid-types/tests/summarize-bench-results.pl uuid.cabal → uuid-types/uuid-types.cabal+14−26 CHANGES → uuid/CHANGES+5 uuid/CONTRIBUTORS+13 Data/UUID.hs → uuid/Data/UUID.hs+5−5 Data/UUID/Named.hs → uuid/Data/UUID/Named.hs+1−1 Data/UUID/Util.hs → uuid/Data/UUID/Util.hs+1−1 Data/UUID/V1.hs → uuid/Data/UUID/V1.hs+2−2 Data/UUID/V3.hs → uuid/Data/UUID/V3.hs+1−1 Data/UUID/V4.hs → uuid/Data/UUID/V4.hs Data/UUID/V5.hs → uuid/Data/UUID/V5.hs+1−1 Data/Word/Util.hs → uuid/Data/Word/Util.hs−7 Demo.hs → uuid/Demo.hs uuid/LICENSE+28 uuid/Setup.hs+4 uuid/tests/BenchUUID.hs+34 uuid/tests/TestUUID.hs+107 uuid/tests/summarize-bench-results.pl+14 uuid/uuid.cabal+83
.gitignore+4−4
@@ -1,9 +1,9 @@
11
22# Sandboxing
3−/.cabal-sandbox/
4−/cabal.sandbox.config
3+.cabal-sandbox/
4+cabal.sandbox.config
55
66# Cabal stuff
7−/dist/
8−/cabal.config
7+dist/
8+cabal.config
99
.travis.yml+4
@@ -5,3 +5,7 @@ ghc:
55 - 7.4
66
77sudo: false
8+install:
9+ - ./travis-scripts/install.sh
10+script:
11+ - ./travis-scripts/build.sh
travis-scripts/build.shnew file+27
@@ -0,0 +1,27 @@
1+#!/usr/bin/env sh
2+echo "==========================================="
3+echo "= Building and installing 'uuid-types'... ="
4+echo "==========================================="
5+
6+# We install here because "uuid" is going to need it.
7+(cd "uuid-types" && \
8+ cabal configure --enable-tests && \
9+ cabal build && \
10+ cabal test && \
11+ cabal install) || exit 1
12+
13+echo "========================================="
14+echo "= Installing dependencies for 'uuid'... ="
15+echo "========================================="
16+
17+(cd "uuid" && \
18+ cabal install --dependencies-only --enable-tests) || exit 1
19+
20+echo "======================"
21+echo "= Building 'uuid'... ="
22+echo "======================"
23+
24+(cd "uuid" && \
25+ cabal configure --enable-tests && \
26+ cabal build && \
27+ cabal test) || exit 1
travis-scripts/install.shnew file+13
@@ -0,0 +1,13 @@
1+#!/usr/bin/env sh
2+
3+# We can only pre-install dependencies for the "uuid-types" project
4+# since the "uuid" project depends on "uuid-types". We could use
5+# sandboxing and "add-source", but it seems quite wasteful of
6+# CPU-cycles to compile everything twice for each version of GHC.
7+
8+echo "==============================================="
9+echo "= Installing dependencies for 'uuid-types'... ="
10+echo "==============================================="
11+
12+(cd "uuid-types" && \
13+ cabal install --dependencies-only --enable-tests) || exit 1
uuid-types/CHANGESnew file+3
@@ -0,0 +1,3 @@
1+1.0.0
2+
3+- Initial split from "uuid-1.3.8"
CONTRIBUTORS → uuid-types/CONTRIBUTORSrenamed+2−1
@@ -9,4 +9,5 @@ Bas van Dijk
99Sergei Trofimovich
1010davean
1111Francesco Mazzoli
12−Michael Snoyman
12+Michael Snoyman
13+Bardur Arantsson
uuid-types/Data/UUID/Types.hsnew file+37
@@ -0,0 +1,37 @@
1+{- |
2+Module : Data.UUID.Types
3+Copyright : (c) 2008,2012 Antoine Latter
4+
5+License : BSD-style
6+
7+Maintainer : aslatter@gmail.com
8+Stability : experimental
9+Portability : portable
10+
11+
12+This library is useful for comparing, parsing and
13+printing Universally Unique Identifiers.
14+See <http://en.wikipedia.org/wiki/UUID> for the general idea.
15+See <http://tools.ietf.org/html/rfc4122> for the specification.
16+
17+-}
18+module Data.UUID.Types(UUID
19+ ,toString
20+ ,fromString
21+ ,toASCIIBytes
22+ ,fromASCIIBytes
23+ ,toLazyASCIIBytes
24+ ,fromLazyASCIIBytes
25+ ,toByteString
26+ ,fromByteString
27+ ,toWords
28+ ,fromWords
29+ ,null
30+ ,nil
31+ ) where
32+
33+import Prelude () -- we need to hide Prelude.null
34+import Data.UUID.Types.Internal
35+
36+-- Everything is really implemented in Data.UUID.Types.Internal, but I
37+-- don't want to export the constructors out of the package.
Data/UUID/Internal.hs → uuid-types/Data/UUID/Types/Internal.hsrenamed+12−5
@@ -1,7 +1,7 @@
11{-# LANGUAGE DeriveDataTypeable, TypeFamilies, CPP #-}
22
33-- |
4−-- Module : Data.UUID
4+-- Module : Data.UUID.Types.Internal
55-- Copyright : (c) 2008-2009, 2012 Antoine Latter
66-- (c) 2009 Mark Lentczner
77--
@@ -11,7 +11,7 @@
1111-- Stability : experimental
1212-- Portability : portable
1313
14−module Data.UUID.Internal
14+module Data.UUID.Types.Internal
1515 (UUID(..)
1616 ,null
1717 ,nil
@@ -61,8 +61,7 @@ import qualified Data.ByteString.Internal as BI
6161import qualified Data.ByteString.Lazy as BL
6262import qualified Data.ByteString.Unsafe as BU
6363
64−import Data.UUID.Builder
65−import Data.Word.Util
64+import Data.UUID.Types.Internal.Builder
6665
6766import System.Random
6867
@@ -167,6 +166,14 @@ word a b c d = (fromIntegral a `shiftL` 24)
167166byte :: Int -> Word32 -> Word8
168167byte i w = fromIntegral (w `shiftR` (i * 8))
169168
169+-- |Build a Word16 from two Word8 values, presented in big-endian order.
170+w8to16 :: Word8 -> Word8 -> Word16
171+w8to16 w0s w1s =
172+ (w0 `shiftL` 8) .|. w1
173+ where
174+ w0 = fromIntegral w0s
175+ w1 = fromIntegral w1s
176+
170177
171178-- |Make a UUID from sixteen Word8 values
172179makeFromBytes :: Word8 -> Word8 -> Word8 -> Word8
@@ -521,7 +528,7 @@ instance Data UUID where
521528 dataTypeOf _ = uuidType
522529
523530uuidType :: DataType
524−uuidType = mkNoRepType "Data.UUID.UUID"
531+uuidType = mkNoRepType "Data.UUID.Types.UUID"
525532
526533#if !(MIN_VERSION_base(4,2,0))
527534mkNoRepType :: String -> DataType
Data/UUID/Builder.hs → uuid-types/Data/UUID/Types/Internal/Builder.hsrenamed+2−2
@@ -1,6 +1,6 @@
11{-# LANGUAGE TypeFamilies #-}
22
3−-- Module : Data.UUID.Builder
3+-- Module : Data.UUID.Types.Internal.Builder
44-- Copyright : (c) 2009 Mark Lentczner
55--
66-- License : BSD-style
@@ -28,7 +28,7 @@
2828-- code was ungainly. Using this module makes the code very
2929-- concise, and turns out to optimize to just as fast, or faster!
3030
31−module Data.UUID.Builder
31+module Data.UUID.Types.Internal.Builder
3232 (ByteSource(..)
3333 ,ByteSink
3434 ,Takes1Byte
LICENSE → uuid-types/LICENSErenamed

The content is the same.

Setup.hs → uuid-types/Setup.hsrenamed

The content is the same.

tests/BenchByteString.hs → uuid-types/tests/BenchByteString.hsrenamed+1−1
@@ -9,7 +9,7 @@ import Test.QuickCheck
99import Criterion
1010import Criterion.Main
1111
12−import Data.UUID
12+import Data.UUID.Types
1313
1414instance Arbitrary UUID where
1515 arbitrary =
tests/BenchUUID.hs → uuid-types/tests/BenchUUID.hsrenamed+1−23
@@ -6,19 +6,12 @@ import Control.DeepSeq
66import qualified Data.ByteString.Lazy.Internal as BL
77#endif
88import Criterion.Main
9−import Data.Char (ord)
10−import Data.IORef
119import Data.Maybe (fromJust)
12−import Data.Word
1310import qualified Data.Set as Set
1411import qualified Data.ByteString.Lazy as BL
15−import qualified Data.UUID as U
16−import qualified Data.UUID.V1 as U
17−import qualified Data.UUID.V3 as U3
18−import qualified Data.UUID.V5 as U5
12+import qualified Data.UUID.Types as U
1913import Foreign (alloca, peek, poke)
2014import System.Random
21−import System.Random.Mersenne.Pure64
2215
2316#if !(MIN_VERSION_bytestring(0,10,0))
2417instance NFData BL.ByteString where
@@ -31,7 +24,6 @@ main = do
3124 u1 <- randomIO
3225 let s1 = U.toString u1
3326 b1 = U.toByteString u1
34− n1 = (map (fromIntegral . ord) "http://www.haskell.org/") :: [Word8]
3527 nil2 = fromJust $
3628 U.fromString "00000000-0000-0000-0000-000000000000"
3729 u2a = fromJust $ U.fromString "169a5a43-c051-4a16-98f4-08447ddd5dc0"
@@ -40,14 +32,6 @@ main = do
4032 0x98, 0xf4, 0x08, 0x44, 0x7d, 0xdd, 0x5d, 0xc0]
4133 u3 = fromJust $ U.fromString "dea6f619-1038-438b-b4af-f1cdec1e6e23"
4234
43− -- setup for random generation
44− randomState <- newPureMT >>= newIORef
45− let randomUUID = do
46− state <- readIORef randomState
47− let (uuid, state') = random state
48− writeIORef randomState state'
49− return uuid
50−
5135 -- setup for Storable benchmark
5236 alloca $ \ uuidPtr -> do
5337
@@ -67,12 +51,6 @@ main = do
6751 bench "toByteString" $ nf U.toByteString u1,
6852 bench "fromByteString" $ nf U.fromByteString b1
6953 ],
70− bgroup "generation" [
71− bench "V1" $ nfIO U.nextUUID,
72− bench "V4" $ nfIO (randomUUID :: IO U.UUID),
73− bench "V3" $ nf (U3.generateNamed U3.namespaceURL) n1,
74− bench "V5" $ nf (U5.generateNamed U5.namespaceURL) n1
75− ],
7654 bench "set making" $ nf Set.fromList uuids,
7755
7856 bgroup "storable" [
tests/TestUUID.hs → uuid-types/tests/TestUUID.hsrenamed+3−79
@@ -1,18 +1,11 @@
11{-# LANGUAGE ViewPatterns #-}
2−import Control.Monad (replicateM)
3−import Data.Bits
42import qualified Data.ByteString.Lazy as BL
53import qualified Data.ByteString.Lazy.Char8 as BL8
64import qualified Data.ByteString.Char8 as BC8
75import Data.Char (ord)
86import Data.Functor ((<$>))
9−import Data.List (nub, (\\))
10−import Data.Maybe
117import Data.Word
12−import qualified Data.UUID as U
13−import qualified Data.UUID.V1 as U
14−import qualified Data.UUID.V3 as U3
15−import qualified Data.UUID.V5 as U5
8+import qualified Data.UUID.Types as U
169import Foreign (alloca, peek, poke)
1710import System.IO.Unsafe (unsafePerformIO)
1811import qualified Test.HUnit as H
@@ -23,14 +16,6 @@ import Test.Framework.Providers.HUnit (hUnitTestToTests)
2316import Test.Framework.Providers.QuickCheck2 (testProperty)
2417
2518
26−isValidVersion :: Int -> U.UUID -> Bool
27−isValidVersion v u = lenOK && variantOK && versionOK
28− where bs = U.toByteString u
29− lenOK = BL.length bs == 16
30− variantOK = (BL.index bs 8) .&. 0xc0 == 0x80
31− versionOK = (BL.index bs 6) .&. 0xf0 == fromIntegral (v `shiftL` 4)
32−
33−
3419instance Arbitrary U.UUID where
3520 -- the UUID random instance ignores bounds
3621 arbitrary = choose (U.nil, U.nil)
@@ -38,8 +23,7 @@ instance Arbitrary U.UUID where
3823
3924test_null :: H.Test
4025test_null = H.TestList [
41− "nil is null" ~: assertBool "" (U.null U.nil),
42− "namespaceDNS is not null" ~: assertBool "" (not $ U.null U3.namespaceDNS)
26+ "nil is null" ~: assertBool "" (U.null U.nil)
4327 ]
4428
4529test_nil :: H.Test
@@ -58,32 +42,6 @@ test_conv = H.TestList [
5842 where b16 = BL.pack [1..16]
5943 s16 = "01020304-0506-0708-090a-0b0c0d0e0f10"
6044
61−test_v1 :: [Maybe U.UUID] -> H.Test
62−test_v1 v1s = H.TestList [
63− "V1 unique" ~: nub (v1s \\ nub v1s) @?= [],
64− "V1 not null" ~: H.TestList $ map (testUUID (not . U.null)) v1s,
65− "V1 valid" ~: H.TestList $ map (testUUID (isValidVersion 1)) v1s
66− ]
67− where testUUID :: (U.UUID -> Bool) -> Maybe U.UUID -> H.Test
68− testUUID p u = maybe False p u ~? show u
69−
70−test_v3 :: H.Test
71−test_v3 = H.TestList [
72− "V3 computation" ~:
73− U3.generateNamed U3.namespaceDNS name @?= uV3
74− ]
75− where name = map (fromIntegral . ord) "www.widgets.com" :: [Word8]
76− uV3 = fromJust $ U.fromString "3d813cbb-47fb-32ba-91df-831e1593ac29"
77−
78−test_v5 :: H.Test
79−test_v5 = H.TestList [
80− "V5 computation" ~:
81− U5.generateNamed U5.namespaceDNS name @?= uV5
82− ]
83− where name = map (fromIntegral . ord) "www.widgets.com" :: [Word8]
84− uV5 = fromJust $ U.fromString "21f7f8de-8051-5b89-8680-0195ef798b6a"
85−
86−
8745-- | Test fromByteString with a fixed-input.
8846test_fromByteString :: H.Test
8947test_fromByteString =
@@ -131,31 +89,6 @@ prop_randomNotNull = testProperty "Random not null" randomNotNull
13189 where randomNotNull :: U.UUID -> Bool
13290 randomNotNull = not. U.null
13391
134−prop_randomsValid :: Test
135−prop_randomsValid = testProperty "Random valid" randomsValid
136− where randomsValid :: U.UUID -> Bool
137− randomsValid = isValidVersion 4
138−
139−prop_v3NotNull :: Test
140−prop_v3NotNull = testProperty "V3 not null" v3NotNull
141− where v3NotNull :: [Word8] -> Bool
142− v3NotNull = not . U.null . U3.generateNamed U3.namespaceDNS
143−
144−prop_v3Valid :: Test
145−prop_v3Valid = testProperty "V3 valid" v3Valid
146− where v3Valid :: [Word8] -> Bool
147− v3Valid = isValidVersion 3 . U3.generateNamed U3.namespaceDNS
148−
149−prop_v5NotNull :: Test
150−prop_v5NotNull = testProperty "V5 not null" v5NotNull
151− where v5NotNull :: [Word8] -> Bool
152− v5NotNull = not . U.null . U5.generateNamed U5.namespaceDNS
153−
154−prop_v5Valid :: Test
155−prop_v5Valid = testProperty "V5 valid" v5Valid
156− where v5Valid :: [Word8] -> Bool
157− v5Valid = isValidVersion 5 . U5.generateNamed U5.namespaceDNS
158−
15992prop_readShowRoundTrip :: Test
16093prop_readShowRoundTrip = testProperty "Read/Show round-trip" prop
16194 where -- we're using 'Maybe UUID' to add a bit of
@@ -210,16 +143,12 @@ prop_storableRoundTrip =
210143
211144main :: IO ()
212145main = do
213− v1s <- replicateM 100 U.nextUUID
214146 defaultMain $
215147 concat $
216148 [ hUnitTestToTests $ H.TestList [
217149 test_null,
218150 test_nil,
219151 test_conv,
220− test_v1 v1s,
221− test_v3,
222− test_v5,
223152 test_fromByteString,
224153 test_fromWords
225154 ]
@@ -230,12 +159,7 @@ main = do
230159 prop_stringLength,
231160 prop_byteStringLength,
232161 prop_randomsDiffer,
233− prop_randomNotNull,
234− prop_randomsValid,
235− prop_v3NotNull,
236− prop_v3Valid,
237− prop_v5NotNull,
238− prop_v5Valid
162+ prop_randomNotNull
239163 ]
240164 , [ testProperty "fromASCIIBytes_fromString1" fromASCIIBytes_fromString1
241165 , testProperty "fromASCIIBytes_fromString2" fromASCIIBytes_fromString2
tests/summarize-bench-results.pl → uuid-types/tests/summarize-bench-results.plrenamed

The content is the same.

uuid.cabal → uuid-types/uuid-types.cabalrenamed+14−26
@@ -1,5 +1,5 @@
1−Name: uuid
2−Version: 1.3.8
1+Name: uuid-types
2+Version: 1.0.0
33Copyright: (c) 2008-2014 Antoine Latter
44Author: Antoine Latter
55Maintainer: aslatter@gmail.com
@@ -11,11 +11,12 @@ Build-Type: Simple
1111Cabal-Version: >= 1.8
1212
1313Description:
14− This library is useful for creating, comparing, parsing and
15− printing Universally Unique Identifiers.
14+ This library contains type definitions for Universally Unique Identifiers
15+ and basic conversion functions.
16+
1617 See <http://en.wikipedia.org/wiki/UUID> for the general idea.
1718
18−Synopsis: For creating, comparing, parsing and printing Universally Unique Identifiers
19+Synopsis: Type definitions for Universally Unique Identifiers
1920
2021Homepage: https://github.com/aslatter/uuid
2122Bug-Reports: https://github.com/aslatter/uuid/issues
@@ -29,26 +30,15 @@ Library
2930 Build-Depends: base >=3 && < 5,
3031 binary >= 0.4 && < 0.8,
3132 bytestring >= 0.9 && < 1.1,
32− cryptohash >= 0.7 && < 0.12,
3333 deepseq >= 1.3 && < 1.5,
3434 hashable (>= 1.1.1.0 && < 1.2.0) || (>= 1.2.1 && < 1.3),
35− network-info == 0.2.*,
36− random >= 1.0.1 && < 1.2,
37− time >= 1.1 && < 1.6
35+ random >= 1.0.1 && < 1.2
3836
3937 Exposed-Modules:
40− Data.UUID
41− Data.UUID.Util
42− Data.UUID.V1
43− Data.UUID.V3
44− Data.UUID.V4
45− Data.UUID.V5
46−
47− Other-Modules:
48− Data.UUID.Builder
49− Data.UUID.Internal
50− Data.UUID.Named
51− Data.Word.Util
38+ Data.UUID.Types
39+ -- Exposed for companion projects; *NOT* part of the official API:
40+ Data.UUID.Types.Internal.Builder
41+ Data.UUID.Types.Internal
5242
5343 Extensions: DeriveDataTypeable
5444 Ghc-Options: -Wall
@@ -64,11 +54,10 @@ Test-Suite testuuid
6454 Extensions: DeriveDataTypeable
6555 Ghc-Options: -Wall -fno-warn-orphans
6656 Build-Depends: base >= 3 && < 5,
67− uuid,
57+ uuid-types,
6858 bytestring >= 0.9 && < 1.1,
6959 HUnit >=1.2 && < 1.3,
7060 QuickCheck >=2.4 && < 2.8,
71− random >= 1.0.1 && < 1.2,
7261 test-framework == 0.8.*,
7362 test-framework-hunit == 0.3.*,
7463 test-framework-quickcheck2 == 0.3.*
@@ -80,12 +69,11 @@ benchmark benchmark
8069 Extensions: DeriveDataTypeable, CPP
8170 Ghc-Options: -Wall -fno-warn-orphans
8271 Build-depends: base == 4.*,
83− uuid,
72+ uuid-types,
8473 bytestring >= 0.9 && < 1.1,
8574 containers >= 0.4 && < 0.6,
8675 criterion >= 0.4 && < 0.9,
8776 deepseq >= 1.1 && < 1.4,
88− mersenne-random-pure64,
8977 random >= 1.0.1 && < 1.2
9078
9179benchmark benchbytestring
@@ -94,7 +82,7 @@ benchmark benchbytestring
9482 Main-Is: BenchByteString.hs
9583 Ghc-Options: -threaded -rtsopts -Wall -O2 -fno-warn-orphans
9684 Build-Depends: base >= 4 && < 5
97− , uuid
85+ , uuid-types
9886 , bytestring >= 0.10
9987 , criterion >= 0.8
10088 , random >= 1.0
CHANGES → uuid/CHANGESrenamed+5
@@ -1,3 +1,8 @@
1+1.3.9
2+
3+- Split definition of UUID data type into separate Cabal package to
4+ enable 3rd party libraries to avoid some of the larger dependencies.
5+
161.3.8
27
38- Allow building against newer deepseq.
uuid/CONTRIBUTORSnew file+13
@@ -0,0 +1,13 @@
1+In order of appearance:
2+
3+Antoine Latter
4+Jason Dusek
5+Tim Newsham
6+Mark Lentczner
7+Neil Mitchell
8+Bas van Dijk
9+Sergei Trofimovich
10+davean
11+Francesco Mazzoli
12+Michael Snoyman
13+Bardur Arantsson
Data/UUID.hs → uuid/Data/UUID.hsrenamed+5−5
@@ -23,7 +23,6 @@ MAC address and current system time in "Data.UUID.V1".
2323* For name-based generation of UUIDs using SHA-1 hashing see
2424"Data.UUID.V5".
2525-}
26−
2726module Data.UUID(UUID
2827 ,toString
2928 ,fromString
@@ -40,8 +39,9 @@ module Data.UUID(UUID
4039 ) where
4140
4241import Prelude () -- we need to hide Prelude.null
43−import Data.UUID.Internal
42+import Data.UUID.Types
4443
45−-- Everything is really implemented in Data.UUID.Internal,
46−-- but I don't want to export the constructors out of the
47−-- package.
44+-- We use explicit re-exports of everything from Data.UUID.Types in
45+-- preference to just re-exporting the whole module. This is to avoid
46+-- unforeseen transitive API breakage if the Data.UUID.Types module
47+-- should change.
Data/UUID/Named.hs → uuid/Data/UUID/Named.hsrenamed+1−1
@@ -26,7 +26,7 @@ module Data.UUID.Named
2626 ,namespaceX500
2727 ) where
2828
29−import Data.UUID.Internal
29+import Data.UUID.Types.Internal
3030
3131import Control.Applicative ((<*>),(<$>))
3232import Data.Binary.Get (runGet, getWord32be)
Data/UUID/Util.hs → uuid/Data/UUID/Util.hsrenamed+1−1
@@ -12,7 +12,7 @@ import Prelude hiding (null)
1212import Data.Word
1313import Data.Word.Util
1414import Data.Bits
15−import Data.UUID.Internal
15+import Data.UUID.Types.Internal
1616import Network.Info
1717import Data.Int (Int64)
1818
Data/UUID/V1.hs → uuid/Data/UUID/V1.hsrenamed+2−2
@@ -39,8 +39,8 @@ import qualified System.Random as R
3939
4040import Network.Info
4141
42−import Data.UUID.Builder
43−import Data.UUID.Internal
42+import Data.UUID.Types.Internal.Builder
43+import Data.UUID.Types.Internal
4444
4545-- | Returns a new UUID derived from the local hardware MAC
4646-- address and the current system time.
Data/UUID/V3.hs → uuid/Data/UUID/V3.hsrenamed+1−1
@@ -33,7 +33,7 @@ module Data.UUID.V3
3333
3434import Data.Word
3535
36−import Data.UUID.Internal
36+import Data.UUID.Types.Internal
3737import qualified Data.UUID.Named as Shared
3838import qualified Crypto.Hash.MD5 as MD5
3939
Data/UUID/V4.hs → uuid/Data/UUID/V4.hsrenamed

The content is the same.

Data/UUID/V5.hs → uuid/Data/UUID/V5.hsrenamed+1−1
@@ -28,7 +28,7 @@ module Data.UUID.V5
2828
2929import Data.Word
3030
31−import Data.UUID.Internal
31+import Data.UUID.Types.Internal
3232import qualified Data.UUID.Named as Shared
3333import qualified Crypto.Hash.SHA1 as SHA1
3434
Data/Word/Util.hs → uuid/Data/Word/Util.hsrenamed−7
@@ -5,13 +5,6 @@ module Data.Word.Util where
55import Data.Bits
66import Data.Word
77
8−w8to16 :: Word8 -> Word8 -> Word16
9−w8to16 w0s w1s =
10− (w0 `shiftL` 8) .|. w1
11− where
12− w0 = fromIntegral w0s
13− w1 = fromIntegral w1s
14−
158w16to32 :: Word16 -> Word16 -> Word32
169w16to32 w0s w1s =
1710 (w0 `shiftL` 16) .|. w1
Demo.hs → uuid/Demo.hsrenamed

The content is the same.

uuid/LICENSEnew file+28
@@ -0,0 +1,28 @@
1+Copyright (c) 2008, Antoine Latter
2+
3+All rights reserved.
4+
5+Redistribution and use in source and binary forms, with or without
6+modification, are permitted provided that the following conditions are
7+met:
8+
9+ * Redistributions of source code must retain the above copyright
10+notice, this list of conditions and the following disclaimer.
11+ * Redistributions in binary form must reproduce the above copyright
12+notice, this list of conditions and the following disclaimer in the
13+documentation and/or other materials provided with the distribution.
14+ * The names of the authors may not be used to endorse or promote
15+products derived from this software without specific prior written
16+permission.
17+
18+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24+TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
uuid/Setup.hsnew file+4
@@ -0,0 +1,4 @@
1+import Distribution.Simple
2+main :: IO ()
3+main = defaultMain
4+
uuid/tests/BenchUUID.hsnew file+34
@@ -0,0 +1,34 @@
1+{-# LANGUAGE CPP #-}
2+
3+import Criterion.Main
4+import Data.Char (ord)
5+import Data.IORef
6+import Data.Word
7+import qualified Data.UUID as U
8+import qualified Data.UUID.V1 as U
9+import qualified Data.UUID.V3 as U3
10+import qualified Data.UUID.V5 as U5
11+import System.Random
12+import System.Random.Mersenne.Pure64
13+
14+main :: IO ()
15+main = do
16+ let n1 = (map (fromIntegral . ord) "http://www.haskell.org/") :: [Word8]
17+
18+ -- setup for random generation
19+ randomState <- newPureMT >>= newIORef
20+ let randomUUID = do
21+ state <- readIORef randomState
22+ let (uuid, state') = random state
23+ writeIORef randomState state'
24+ return uuid
25+
26+ -- benchmark UUID generation
27+ defaultMain [
28+ bgroup "generation" [
29+ bench "V1" $ nfIO U.nextUUID,
30+ bench "V4" $ nfIO (randomUUID :: IO U.UUID),
31+ bench "V3" $ nf (U3.generateNamed U3.namespaceURL) n1,
32+ bench "V5" $ nf (U5.generateNamed U5.namespaceURL) n1
33+ ]
34+ ]
uuid/tests/TestUUID.hsnew file+107
@@ -0,0 +1,107 @@
1+{-# LANGUAGE ViewPatterns #-}
2+import Control.Monad (replicateM)
3+import Data.Bits
4+import qualified Data.ByteString.Lazy as BL
5+import Data.Char (ord)
6+import Data.List (nub, (\\))
7+import Data.Maybe
8+import Data.Word
9+import qualified Data.UUID as U
10+import qualified Data.UUID.V1 as U
11+import qualified Data.UUID.V3 as U3
12+import qualified Data.UUID.V5 as U5
13+import qualified Test.HUnit as H
14+import Test.HUnit hiding (Test)
15+import Test.QuickCheck hiding ((.&.))
16+import Test.Framework (defaultMain, Test)
17+import Test.Framework.Providers.HUnit (hUnitTestToTests)
18+import Test.Framework.Providers.QuickCheck2 (testProperty)
19+
20+
21+isValidVersion :: Int -> U.UUID -> Bool
22+isValidVersion v u = lenOK && variantOK && versionOK
23+ where bs = U.toByteString u
24+ lenOK = BL.length bs == 16
25+ variantOK = (BL.index bs 8) .&. 0xc0 == 0x80
26+ versionOK = (BL.index bs 6) .&. 0xf0 == fromIntegral (v `shiftL` 4)
27+
28+
29+instance Arbitrary U.UUID where
30+ -- the UUID random instance ignores bounds
31+ arbitrary = choose (U.nil, U.nil)
32+
33+
34+test_null :: H.Test
35+test_null = H.TestList [
36+ "namespaceDNS is not null" ~: assertBool "" (not $ U.null U3.namespaceDNS)
37+ ]
38+
39+test_v1 :: [Maybe U.UUID] -> H.Test
40+test_v1 v1s = H.TestList [
41+ "V1 unique" ~: nub (v1s \\ nub v1s) @?= [],
42+ "V1 not null" ~: H.TestList $ map (testUUID (not . U.null)) v1s,
43+ "V1 valid" ~: H.TestList $ map (testUUID (isValidVersion 1)) v1s
44+ ]
45+ where testUUID :: (U.UUID -> Bool) -> Maybe U.UUID -> H.Test
46+ testUUID p u = maybe False p u ~? show u
47+
48+test_v3 :: H.Test
49+test_v3 = H.TestList [
50+ "V3 computation" ~:
51+ U3.generateNamed U3.namespaceDNS name @?= uV3
52+ ]
53+ where name = map (fromIntegral . ord) "www.widgets.com" :: [Word8]
54+ uV3 = fromJust $ U.fromString "3d813cbb-47fb-32ba-91df-831e1593ac29"
55+
56+test_v5 :: H.Test
57+test_v5 = H.TestList [
58+ "V5 computation" ~:
59+ U5.generateNamed U5.namespaceDNS name @?= uV5
60+ ]
61+ where name = map (fromIntegral . ord) "www.widgets.com" :: [Word8]
62+ uV5 = fromJust $ U.fromString "21f7f8de-8051-5b89-8680-0195ef798b6a"
63+
64+
65+prop_randomsValid :: Test
66+prop_randomsValid = testProperty "Random valid" randomsValid
67+ where randomsValid :: U.UUID -> Bool
68+ randomsValid = isValidVersion 4
69+
70+prop_v3NotNull :: Test
71+prop_v3NotNull = testProperty "V3 not null" v3NotNull
72+ where v3NotNull :: [Word8] -> Bool
73+ v3NotNull = not . U.null . U3.generateNamed U3.namespaceDNS
74+
75+prop_v3Valid :: Test
76+prop_v3Valid = testProperty "V3 valid" v3Valid
77+ where v3Valid :: [Word8] -> Bool
78+ v3Valid = isValidVersion 3 . U3.generateNamed U3.namespaceDNS
79+
80+prop_v5NotNull :: Test
81+prop_v5NotNull = testProperty "V5 not null" v5NotNull
82+ where v5NotNull :: [Word8] -> Bool
83+ v5NotNull = not . U.null . U5.generateNamed U5.namespaceDNS
84+
85+prop_v5Valid :: Test
86+prop_v5Valid = testProperty "V5 valid" v5Valid
87+ where v5Valid :: [Word8] -> Bool
88+ v5Valid = isValidVersion 5 . U5.generateNamed U5.namespaceDNS
89+
90+main :: IO ()
91+main = do
92+ v1s <- replicateM 100 U.nextUUID
93+ defaultMain $
94+ concat $
95+ [ hUnitTestToTests $ H.TestList [
96+ test_null,
97+ test_v1 v1s,
98+ test_v3,
99+ test_v5
100+ ]
101+ , [ prop_randomsValid,
102+ prop_v3NotNull,
103+ prop_v3Valid,
104+ prop_v5NotNull,
105+ prop_v5Valid
106+ ]
107+ ]
uuid/tests/summarize-bench-results.plnew file+14
@@ -0,0 +1,14 @@
1+#!/usr/bin/env perl
2+
3+
4+while(<>) {
5+ if (/^benchmarking (.*)$/) {
6+ $name = $1;
7+ }
8+ if (/^mean:\s*([\d.]*) (\w*),/) {
9+ $mean = 1 * $1;
10+ $units = $2;
11+
12+ printf "%-30s %10.2f %2s\n", $name, $mean, $units;
13+ }
14+}
uuid/uuid.cabalnew file+83
@@ -0,0 +1,83 @@
1+Name: uuid
2+Version: 1.3.9
3+Copyright: (c) 2008-2014 Antoine Latter
4+Author: Antoine Latter
5+Maintainer: aslatter@gmail.com
6+License: BSD3
7+License-file: LICENSE
8+
9+Category: Data
10+Build-Type: Simple
11+Cabal-Version: >= 1.8
12+
13+Description:
14+ This library is useful for creating, comparing, parsing and
15+ printing Universally Unique Identifiers.
16+ See <http://en.wikipedia.org/wiki/UUID> for the general idea.
17+
18+Synopsis: For creating, comparing, parsing and printing Universally Unique Identifiers
19+
20+Homepage: https://github.com/aslatter/uuid
21+Bug-Reports: https://github.com/aslatter/uuid/issues
22+
23+Extra-Source-Files:
24+ CHANGES
25+ CONTRIBUTORS
26+
27+
28+Library
29+ Build-Depends: base >=3 && < 5,
30+ binary >= 0.4 && < 0.8,
31+ bytestring >= 0.9 && < 1.1,
32+ cryptohash >= 0.7 && < 0.12,
33+ network-info == 0.2.*,
34+ random >= 1.0.1 && < 1.2,
35+ time >= 1.1 && < 1.6,
36+ uuid-types >= 1.0 && < 2
37+
38+ Exposed-Modules:
39+ Data.UUID
40+ Data.UUID.Util
41+ Data.UUID.V1
42+ Data.UUID.V3
43+ Data.UUID.V4
44+ Data.UUID.V5
45+
46+ Other-Modules:
47+ Data.UUID.Named
48+ Data.Word.Util
49+
50+ Extensions: DeriveDataTypeable
51+ Ghc-Options: -Wall
52+
53+source-repository head
54+ type: git
55+ location: https://github.com/aslatter/uuid.git
56+
57+Test-Suite testuuid
58+ Type: exitcode-stdio-1.0
59+ Main-is: TestUUID.hs
60+ Hs-source-dirs: tests
61+ Extensions: DeriveDataTypeable
62+ Ghc-Options: -Wall -fno-warn-orphans
63+ Build-Depends: base >= 3 && < 5,
64+ uuid,
65+ bytestring >= 0.9 && < 1.1,
66+ HUnit >=1.2 && < 1.3,
67+ QuickCheck >=2.4 && < 2.8,
68+ random >= 1.0.1 && < 1.2,
69+ test-framework == 0.8.*,
70+ test-framework-hunit == 0.3.*,
71+ test-framework-quickcheck2 == 0.3.*
72+
73+benchmark benchmark
74+ Type: exitcode-stdio-1.0
75+ Main-is: BenchUUID.hs
76+ Hs-source-dirs: tests
77+ Extensions: DeriveDataTypeable, CPP
78+ Ghc-Options: -Wall -fno-warn-orphans
79+ Build-depends: base == 4.*,
80+ uuid,
81+ criterion >= 0.4 && < 0.9,
82+ mersenne-random-pure64,
83+ random >= 1.0.1 && < 1.2