1 -- | Implementation of base-62 encoding, which we use when computing hashes
2 -- for fully instantiated unit ids.
3 module Distribution
.Utils
.Base62
(hashToBase62
) where
6 import GHC
.Fingerprint
(Fingerprint
(..), fingerprintString
)
7 import Numeric
(showIntAtBase
)
9 -- | Hash a string using GHC's fingerprinting algorithm (a 128-bit
10 -- MD5 hash) and then encode the resulting hash in base 62.
11 hashToBase62
:: String -> String
12 hashToBase62 s
= showFingerprint
$ fingerprintString s
14 showIntAtBase62 x
= showIntAtBase
62 representBase62 x
""
16 | x
< 10 = chr (48 + x
)
17 | x
< 36 = chr (65 + x
- 10)
18 | x
< 62 = chr (97 + x
- 36)
20 showFingerprint
(Fingerprint a b
) = showIntAtBase62 a
++ showIntAtBase62 b