Skip to content

Instantly share code, notes, and snippets.

@timjb
Created June 27, 2016 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timjb/2d476d8fa60d4d5eece769f6d5a92b42 to your computer and use it in GitHub Desktop.
Save timjb/2d476d8fa60d4d5eece769f6d5a92b42 to your computer and use it in GitHub Desktop.
HashTable-Lückencode
#!/usr/bin/env stack
-- stack --resolver lts-6.4 --install-ghc runghc --package primitive --package hashable --package vector
module HashTable where
import Prelude hiding (lookup)
import Control.Monad.Primitive (PrimMonad (..))
import Data.Hashable (Hashable (..))
import qualified Data.List as L
import qualified Data.Vector.Mutable as VM
data MutHashTable s k v
= MutHashTable ()
htSize :: Int
htSize = 2 ^ 12
empty :: PrimMonad m => m (MutHashTable (PrimState m) k v)
empty = _
lookup
:: (Hashable k, Eq k, PrimMonad m)
=> k
-> MutHashTable (PrimState m) k v
-> m (Maybe v)
lookup key (MutHashTable vec) =
_
insert
:: (Hashable k, Eq k, PrimMonad m)
=> k
-> v
-> MutHashTable (PrimState m) k v
-> m ()
insert key value (MutHashTable vec) =
_
delete
:: (Hashable k, Eq k, PrimMonad m)
=> k
-> MutHashTable (PrimState m) k v
-> m ()
delete key (MutHashTable vec) =
_
main :: IO ()
main = do
ht <- empty
lookup "bar" ht >>= assertEqual Nothing
insert "bar" 42 ht
lookup "bar" ht >>= assertEqual (Just 42)
lookup "foo" ht >>= assertEqual Nothing
delete "bar" ht
lookup "bar" ht >>= assertEqual Nothing
where
assertEqual expected actual =
if expected == actual then
return ()
else
fail $ "expected " ++ show actual ++ " to be " ++ show expected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment