Skip to content

Instantly share code, notes, and snippets.

View rblaze's full-sized avatar

Andrey Sverdlichenko rblaze

View GitHub Profile
@rblaze
rblaze / problemK.hs
Created May 12, 2011 16:33
Problem K
import Data.Char
import Data.Map (Map, keys, fromList, toList, adjust)
import qualified Data.Map
import Data.Maybe
import Data.List (intercalate)
data Cell = StrConst String |
Empty |
Number Int |
Expr String |
@rblaze
rblaze / mersenne32.hs
Created August 1, 2011 15:40
32-bit Mersenne Twister in Haskell
import Data.Bits
import Data.Word
import System.Random
mtN = 624
mtM = 397
data MersenneTwister = MersenneTwister [Word32] Int
deriving Show
module Main where
import Control.Monad.State
import Data.Word
type Counter = Word64
type MyState = State Counter
mergesort :: (a -> a -> Ordering) -> [a] -> MyState [a]
mergesort cmp = mergesort' cmp . map wrap
module Main where
import Codec.Digest.SHA
import Control.Monad
import Data.Bits
import Data.ByteString as BS(ByteString, last, init, pack, unpack)
import Data.HashTable as H
import Data.Int
import Data.Maybe
import Data.Word
С созданием таблицы как new
4,068,203,620 bytes allocated in the heap
464,278,756 bytes copied during GC
196,619,868 bytes maximum residency (11 sample(s))
8,628,244 bytes maximum slop
323 MB total memory in use (0 MB lost due to fragmentation)
Generation 0: 5565 collections, 0 parallel, 34.72s, 34.86s elapsed
Generation 1: 11 collections, 0 parallel, 1.16s, 1.27s elapsed
type JSlice = JudyL Int
type JAll = JudyL JSlice
jinsert :: Word64 -> Int-> JAll -> IO ()
jinsert hv src ht = do
sl <- slice
insert keyl src sl
where
(keyh, keyl) = hilo hv
slice = do
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)
5,366,256,252 bytes allocated in the heap
3,725,456 bytes copied during GC
2,664,388 bytes maximum residency (3 sample(s))
86,768 bytes maximum slop
5 MB total memory in use (0 MB lost due to fragmentation)
Generation 0: 8444 collections, 0 parallel, 1.44s, 1.44s elapsed
Generation 1: 3 collections, 0 parallel, 0.00s, 0.00s elapsed
INIT time 0.00s ( 0.00s elapsed)
@rblaze
rblaze / gist:2775009
Created May 23, 2012 12:30
Recursive descent parser for grammar S -> baSab ∣ baS ∣ b
module Main where
import Debug.Trace
import Control.Applicative
import Control.Monad
{-- recursive descent parser for grammar S -> baSab ∣ baS ∣ b --}
term :: Char -> String -> Maybe String
term _ [] = Nothing
module LangParser(parseGrammar, Token(..)) where
import Control.Applicative
import Control.Monad
data Token =
Return |
Simple Char |
OctalConst String |
DecimalConst String |