on master help sign in
Expose `toWords64`/`fromWords64` de/constructors
commit583594f6c3fad188164a249c04dea1a36412b6d1 authorHerbert Valerio Riedel <hvr@gnu.org> dateSun 1 Apr 2018, 17:33 (9 years ago) parent5ff4e67
3 files changed+42−5
uuid-types/CHANGES+6 uuid-types/Data/UUID/Types.hs+4−1 uuid-types/Data/UUID/Types/Internal.hs+32−4
uuid-types/CHANGES+6
@@ -1,3 +1,9 @@
1+1.0.4
2+
3+- Use more compact heap object representation
4+ which saves 16 bytes on 64bit platforms.
5+- Add toWords64/fromWords64
6+
171.0.3
28
39- Bump package dependencies
uuid-types/Data/UUID/Types.hs+4−1
@@ -1,6 +1,7 @@
11{- |
22Module : Data.UUID.Types
3−Copyright : (c) 2008,2012 Antoine Latter
3+Copyright : (c) 2017-2018 Herbert Valerio Riedel
4+ (c) 2008,2012 Antoine Latter
45
56License : BSD-style
67
@@ -28,6 +29,8 @@ module Data.UUID.Types(UUID
2829 ,fromByteString
2930 ,toWords
3031 ,fromWords
32+ ,toWords64
33+ ,fromWords64
3134 ,null
3235 ,nil
3336 ) where
uuid-types/Data/UUID/Types/Internal.hs+32−4
@@ -27,6 +27,8 @@ module Data.UUID.Types.Internal
2727 , toText
2828 , fromWords
2929 , toWords
30+ , fromWords64
31+ , toWords64
3032 , toList
3133 , buildFromBytes
3234 , buildFromWords
@@ -94,10 +96,15 @@ data UUID = UUID {-# UNPACK #-} !Word64 {-# UNPACK #-} !Word64
9496 None was as fast, overall, as the representation used here.
9597-}
9698
97−-- | Covert a 'UUID' into a sequence of 'Word32' values.
99+-- | Convert a 'UUID' into a sequence of 'Word32' values.
98100-- Useful for when you need to serialize a UUID and
99101-- neither 'Storable' nor 'Binary' are appropriate.
100−-- Introduced in version 1.2.2.
102+--
103+-- See also 'toWords64'.
104+--
105+-- /Since: @uuid-1.2.2@/
106+--
107+-- @since 1.0.0
101108toWords :: UUID -> (Word32, Word32, Word32, Word32)
102109toWords (UUID w12 w34) = (w1, w2, w3, w4)
103110 where
@@ -107,12 +114,33 @@ toWords (UUID w12 w34) = (w1, w2, w3, w4)
107114 w4 = fromIntegral w34
108115
109116-- | Create a 'UUID' from a sequence of 'Word32'. The
110−-- opposite of 'toWords'. Useful when you need a total
117+-- inverse of 'toWords'. Useful when you need a total
111118-- function for constructing 'UUID' values.
112−-- Introduced in version 1.2.2.
119+--
120+-- See also 'fromWords64'.
121+--
122+-- /Since: @uuid-1.2.2@/
123+--
124+-- @since 1.0.0
113125fromWords :: Word32 -> Word32 -> Word32 -> Word32 -> UUID
114126fromWords w1 w2 w3 w4 = UUID (w32to64 w1 w2) (w32to64 w3 w4)
115127
128+-- | Convert a 'UUID' into a pair of 'Word64's.
129+--
130+-- See also 'toWords'.
131+--
132+-- @since 1.0.4
133+toWords64 :: UUID -> (Word64, Word64)
134+toWords64 (UUID w12 w34) = (w12,w34)
135+
136+-- | Create a 'UUID' from a pair of 'Word64's.
137+--
138+-- Inverse of 'toWords64'. See also 'fromWords'.
139+--
140+-- @since 1.0.4
141+fromWords64 :: Word64 -> Word64 -> UUID
142+fromWords64 = UUID
143+
116144data UnpackedUUID =
117145 UnpackedUUID {
118146 time_low :: Word32 -- 0-3