snowchecked 0.0.1.0 → 0.0.1.1
raw patch · 7 files changed
+76/−48 lines, 7 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- package.yaml +32/−31
- snowchecked.cabal +5/−5
- src/Data/Snowchecked.hs +7/−5
- src/Data/Snowchecked/Encoding/Text.hs +3/−0
- stack.yaml +1/−1
- stack.yaml.lock +4/−4
- test/Spec.hs +24/−2
package.yaml view
@@ -1,5 +1,5 @@ name: snowchecked-version: 0.0.1.0+version: 0.0.1.1 github: robertfischer/hs-snowflake-checked license: Apache-2.0 author: Robert Fischer@@ -23,7 +23,7 @@ description: See the file ./README.md, which is included in the package and also on GitHub. dependencies:- - base >= 4.14.1.0 && < 4.15+ - base >= 4.14.1.0 && < 5 - bytestring >= 0.10.12.0 - wide-word >= 0.1.1.2 - data-default >= 0.7.1.1@@ -33,39 +33,40 @@ - text >= 1.2.4.1 ghc-options:- - -Wall- - -Wcompat- - -Widentities- - -Werror=unused-do-bind- - -Werror=incomplete-record-updates- - -Werror=incomplete-uni-patterns- - -Werror=partial-fields- - -Werror=incomplete-patterns- - -Wredundant-constraints- - -Werror=missing-exported-signatures- - -Wmissed-specializations- - -Wno-unused-packages- - -Wunused-type-patterns- - -Werror=warnings-deprecations- - -Wnoncanonical-monad-instances- - -Wno-type-defaults - -Wno-tabs- - -feager-blackholing- - -fexcess-precision- - -flate-dmd-anal- - -fmax-inline-alloc-size=1024- - -fmax-simplifier-iterations=8- - -fpedantic-bottoms- - -fregs-iterative- - -fsimplifier-phases=4- - -fspec-constr-count=10- - -fspecialise-aggressively- - -flate-specialise- - -fstatic-argument-transformation- - -fstrictness-before=3 library: source-dirs: src+ ghc-options:+ - -Wall+ - -Wcompat+ - -Wno-type-defaults+ - -Wno-tabs+ - -Widentities+ - -Werror=unused-do-bind+ - -Werror=incomplete-record-updates+ - -Werror=incomplete-uni-patterns+ - -Werror=partial-fields+ - -Werror=incomplete-patterns+ - -Wredundant-constraints+ - -Werror=missing-exported-signatures+ - -Wmissed-specializations+ - -Wunused-type-patterns+ - -Werror=warnings-deprecations+ - -Wnoncanonical-monad-instances+ - -feager-blackholing+ - -fexcess-precision+ - -flate-dmd-anal+ - -fmax-inline-alloc-size=1024+ - -fmax-simplifier-iterations=8+ - -fpedantic-bottoms+ - -fregs-iterative+ - -fsimplifier-phases=4+ - -fspec-constr-count=10+ - -fspecialise-aggressively+ - -flate-specialise+ - -fstatic-argument-transformation+ - -fstrictness-before=3 tests: test-suite:
snowchecked.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: snowchecked-version: 0.0.1.0+version: 0.0.1.1 synopsis: A checksummed variation on Twitter's Snowflake UID generation algorithm description: See the file ./README.md, which is included in the package and also on GitHub. category: Data@@ -42,9 +42,9 @@ Paths_snowchecked hs-source-dirs: src- ghc-options: -Wall -Wcompat -Widentities -Werror=unused-do-bind -Werror=incomplete-record-updates -Werror=incomplete-uni-patterns -Werror=partial-fields -Werror=incomplete-patterns -Wredundant-constraints -Werror=missing-exported-signatures -Wmissed-specializations -Wno-unused-packages -Wunused-type-patterns -Werror=warnings-deprecations -Wnoncanonical-monad-instances -Wno-type-defaults -Wno-tabs -feager-blackholing -fexcess-precision -flate-dmd-anal -fmax-inline-alloc-size=1024 -fmax-simplifier-iterations=8 -fpedantic-bottoms -fregs-iterative -fsimplifier-phases=4 -fspec-constr-count=10 -fspecialise-aggressively -flate-specialise -fstatic-argument-transformation -fstrictness-before=3+ ghc-options: -Wno-tabs -Wall -Wcompat -Wno-type-defaults -Wno-tabs -Widentities -Werror=unused-do-bind -Werror=incomplete-record-updates -Werror=incomplete-uni-patterns -Werror=partial-fields -Werror=incomplete-patterns -Wredundant-constraints -Werror=missing-exported-signatures -Wmissed-specializations -Wunused-type-patterns -Werror=warnings-deprecations -Wnoncanonical-monad-instances -feager-blackholing -fexcess-precision -flate-dmd-anal -fmax-inline-alloc-size=1024 -fmax-simplifier-iterations=8 -fpedantic-bottoms -fregs-iterative -fsimplifier-phases=4 -fspec-constr-count=10 -fspecialise-aggressively -flate-specialise -fstatic-argument-transformation -fstrictness-before=3 build-depends:- base >=4.14.1.0 && <4.15+ base >=4.14.1.0 && <5 , bytestring >=0.10.12.0 , data-default >=0.7.1.1 , deepseq >=1.4.4.0@@ -67,9 +67,9 @@ Paths_snowchecked hs-source-dirs: test- ghc-options: -Wall -Wcompat -Widentities -Werror=unused-do-bind -Werror=incomplete-record-updates -Werror=incomplete-uni-patterns -Werror=partial-fields -Werror=incomplete-patterns -Wredundant-constraints -Werror=missing-exported-signatures -Wmissed-specializations -Wno-unused-packages -Wunused-type-patterns -Werror=warnings-deprecations -Wnoncanonical-monad-instances -Wno-type-defaults -Wno-tabs -feager-blackholing -fexcess-precision -flate-dmd-anal -fmax-inline-alloc-size=1024 -fmax-simplifier-iterations=8 -fpedantic-bottoms -fregs-iterative -fsimplifier-phases=4 -fspec-constr-count=10 -fspecialise-aggressively -flate-specialise -fstatic-argument-transformation -fstrictness-before=3 -threaded -rtsopts -with-rtsopts=-N+ ghc-options: -Wno-tabs -threaded -rtsopts -with-rtsopts=-N build-depends:- base >=4.14.1.0 && <4.15+ base >=4.14.1.0 && <5 , bytestring >=0.10.12.0 , data-default >=0.7.1.1 , deepseq >=1.4.4.0
src/Data/Snowchecked.hs view
@@ -1,6 +1,5 @@-{-# LANGUAGE BlockArguments #-}-{-# LANGUAGE RecordWildCards #-}-{-# LANGUAGE TypeApplications #-}+{-# LANGUAGE BlockArguments #-}+{-# LANGUAGE RecordWildCards #-} {-| Description : Unique id generator derived from Twitter's Snowflake. License : Apache 2.0@@ -46,7 +45,7 @@ startTimeBits <- currentTimestampBits confTimeBits SnowcheckedGen <$> newMVar Flake { flakeTime = startTimeBits- , flakeCount = 0+ , flakeCount = maxBound , flakeNodeId = cutBits nodeId confNodeBits , flakeConfig = conf }@@ -101,5 +100,8 @@ -- | Provides the count of total number of unique flakes possibly generated by a node using -- this configuration. uniqueFlakeCount :: SnowcheckedConfig -> Integer-uniqueFlakeCount SnowcheckedConfig{..} = toInteger confCountBits * toInteger confTimeBits+uniqueFlakeCount SnowcheckedConfig{..}+ | confCountBits == 0 = 2^confTimeBits+ | confTimeBits == 0 = 2^confCountBits+ | otherwise = 2^confCountBits * 2^confTimeBits {-# INLINE uniqueFlakeCount #-}
src/Data/Snowchecked/Encoding/Text.hs view
@@ -55,6 +55,7 @@ c 14 = 'e' c 15 = 'f' c _ = '\0'+{-# INLINE c #-} -- | Converts a character to a hex value (if there is one). b :: Char -> Maybe Word8@@ -74,6 +75,7 @@ 'F' -> Just 15 'f' -> Just 15 _ -> Nothing+{-# INLINE b #-} -- | Converts a byte to two hex characters: low nibble and then high nibble. byteToHex :: Word8 -> (Char,Char)@@ -81,6 +83,7 @@ where lowNibble = cutBits w8 4 highNibble = shiftCutBits w8 4 4+{-# INLINE byteToHex #-} instance {-# INCOHERENT #-} (ToText a, FromText a) => IsFlake (Base16 a) where fromFlake flake = Base16 $ convertText str
stack.yaml view
@@ -17,7 +17,7 @@ # # resolver: ./custom-snapshot.yaml # resolver: https://example.com/snapshots/2018-01-01.yaml-resolver: lts-18.5+resolver: lts-19.15 # User packages to be built. # Various formats can be used as shown in the example below.
stack.yaml.lock view
@@ -6,7 +6,7 @@ packages: [] snapshots: - completed:- size: 585817- url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/18/5.yaml- sha256: 22d24d0dacad9c1450b9a174c28d203f9bb482a2a8da9710a2f2a9f4afee2887- original: lts-18.5+ size: 618952+ url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/19/15.yaml+ sha256: 82e5ccb47b068521de4055034e8aa278eab430b586881d9cc29ba8b382ce3253+ original: lts-19.15
test/Spec.hs view
@@ -15,10 +15,10 @@ import qualified Hedgehog.Range as Range import qualified Integer+import qualified String+import qualified Text import qualified Word32 import qualified Word64-import qualified Text-import qualified String main :: IO () main = do@@ -49,3 +49,25 @@ prop_flakeCanBeNFed = property $ do flake <- forAllFlake void $ evalNF flake++prop_generatesUniqueValuesWithZeroCheckBits :: Property+prop_generatesUniqueValuesWithZeroCheckBits = property $ do+ lst <- forAll $ Gen.list (Range.linear 2 1024) (return ())+ cfgBase <- forAll genConfig+ let cfg = cfgBase { confCheckBits = 0 }+ unless ( uniqueFlakeCount cfg > toInteger (length lst) ) discard+ nodeId <- forAll genWord256+ flakeGen <- newSnowcheckedGen cfg nodeId+ resultLst <- mapM (\_ -> nextFlake flakeGen) lst+ resultLst === nub resultLst++prop_generatesUniqueValuesWithZeroNodeIdBits :: Property+prop_generatesUniqueValuesWithZeroNodeIdBits = property $ do+ lst <- forAll $ Gen.list (Range.linear 2 1024) (return ())+ cfgBase <- forAll genConfig+ let cfg = cfgBase { confNodeBits = 0 }+ unless ( uniqueFlakeCount cfg > toInteger (length lst) ) discard+ nodeId <- forAll genWord256+ flakeGen <- newSnowcheckedGen cfg nodeId+ resultLst <- mapM (\_ -> nextFlake flakeGen) lst+ resultLst === nub resultLst