Skip to content

Instantly share code, notes, and snippets.

@rblaze
Created March 30, 2012 14:20
Show Gist options
  • Save rblaze/2251860 to your computer and use it in GitHub Desktop.
Save rblaze/2251860 to your computer and use it in GitHub Desktop.
5,569,024,484 bytes allocated in the heap
4,241,345,748 bytes copied during GC
188,880,976 bytes maximum residency (32 sample(s))
1,712,696 bytes maximum slop
504 MB total memory in use (0 MB lost due to fragmentation)
Generation 0: 8811 collections, 0 parallel, 8.56s, 8.57s elapsed
Generation 1: 32 collections, 0 parallel, 4.10s, 4.51s elapsed
INIT time 0.00s ( 0.00s elapsed)
MUT time 18.55s ( 18.77s elapsed)
GC time 12.66s ( 13.07s elapsed)
EXIT time 0.00s ( 0.00s elapsed)
Total time 31.21s ( 31.84s elapsed)
%GC time 40.6% (41.1% elapsed)
Alloc rate 300,295,548 bytes per MUT second
Productivity 59.4% of total user, 58.2% of total elapsed
module Main where
import Codec.Digest.SHA
import Data.Bits
import Data.ByteString as BS(ByteString, pack, unpack)
import qualified Data.Map as M
import Data.Word
import Data.Vector.Storable as V(Vector, last)
import Data.Vector.Storable.ByteString
mkWord :: ByteString -> Word64
mkWord str = V.last vec .&. 0xFFFFFFFFFFF --0x3FFFFFFFFFFFF
where
vec :: Vector Word64
vec = byteStringToVector str
mkByteString :: Int -> ByteString
mkByteString i = pack (mksplit i)
where
mksplit :: Int -> [Word8]
mksplit 0 = []
mksplit n = fromIntegral r : mksplit q
where
(q, r) = quotRem n 256
hilo :: Word64 -> (Word, Word)
hilo w = (hi, lo)
where
hi = fromIntegral (shiftR w 32)
lo = fromIntegral (w .&. 0xffffffff)
findColl :: Int -> M.Map Word64 Int -> (Int, Int)
findColl i ht
| M.member hv ht = (i, ht M.! hv)
| otherwise = findColl (i + 1) (M.insert hv i ht)
where
str = mkByteString i
hv = mkWord (hash SHA256 str)
main::IO()
main = do
let (i1, i2) = findColl 1 M.empty
print (show (unpack $ mkByteString i1) ++ " " ++ show (unpack $ mkByteString i2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment