found an edge case where a Data.Map tree map does not work properly for retrieving a successor.

Need to find a better data structure
This commit is contained in:
Trolli Schmittlauch 2020-04-14 00:45:25 +02:00
parent f4847da295
commit 3db7fcfba5

View file

@ -0,0 +1,29 @@
import Hash2Pub.FediChord
import Data.Map.Internal.Debug (showTree)
import qualified Data.Map.Strict as Map
giebMalCache :: [Integer] -> Map.Map NodeID ()
giebMalCache = Map.fromList . map (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