forked from schmittlauch/Hash2Pub
This commit brings in an HLint configuration file and several recommended modifications such as: * End-of-line extra spaces removal; * Import lines ordering; * Redundant $ removal; * Generalisation of ++ and map to <> and fmap; * Preferring `pure` over `return`; * Removing extraenous extensions. And finally, a `stylish-haskell` helper script that detects if code files are dirty. Can be useful for CI, although manually calling it can be nice if you would rather first implement then beautify.
30 lines
1.2 KiB
Haskell
30 lines
1.2 KiB
Haskell
import Data.Map.Internal.Debug (showTree)
|
|
import qualified Data.Map.Strict as Map
|
|
import Hash2Pub.FediChord
|
|
|
|
giebMalCache :: [Integer] -> Map.Map NodeID ()
|
|
giebMalCache = Map.fromList . fmap (mkCacheEntry . fromInteger)
|
|
where
|
|
mkCacheEntry nodeid = (nodeid, ())
|
|
|
|
testCache1 = giebMalCache [1, -1, 2^50]
|
|
testFirstHalf = giebMalCache [3, 2^254-2, 2^255]
|
|
testOverlap = giebMalCache [2^255+2^254+3, 2, 2^253]
|
|
|
|
nidLookup m = flip Map.lookup m . fromInteger
|
|
nidLookupLT m = flip Map.lookupLT m . fromInteger
|
|
nidLookupGT m = flip Map.lookupGT m . fromInteger
|
|
|
|
edgeCase1 :: IO ()
|
|
edgeCase1 = do
|
|
putStrLn "Let there be a Map with the keys [2^255+2^254+3, 2, 2^253], all keys are NodeIDs mod 2^256."
|
|
print testOverlap
|
|
putStrLn "\nWhile (NodeID 2^255+2^254+3) > (NodeID 2^254 + 14) …"
|
|
print $ toNodeID (2^255+2^254+3) > toNodeID (2^254+14)
|
|
putStrLn "… and 2^255+2^254+3 is an element of the map…"
|
|
print $ Map.member (fromInteger (2^255+2^254+3)) testOverlap
|
|
putStrLn "… looking for an element larger than 2^254 + 14 doesn't yield any."
|
|
print $ nidLookupGT testOverlap (2^254+14)
|
|
putStrLn "\nThat's the tree of the map:"
|
|
putStrLn $ showTree testOverlap
|