breve/Breve/UrlTable.hs

29 lines
587 B
Haskell
Raw Normal View History

2015-04-08 22:13:02 +02:00
module Breve.UrlTable
2015-04-08 12:47:56 +02:00
( UrlTable
, records
, insert
, extract
) where
2015-04-08 22:13:02 +02:00
import Breve.Generator
2015-04-08 12:47:56 +02:00
import Control.Applicative
import Control.Monad
import Data.Maybe
import qualified Data.HashTable.IO as H
type UrlTable = H.CuckooHashTable Word Url
--Empty url hash table
records :: IO UrlTable
records = H.new
-- Insert the url in the table and return the word
insert :: UrlTable -> Url -> IO Word
insert table url = H.insert table new url >> return new
where new = wordID url
-- Lookup the table for the associated url
extract :: UrlTable -> Word -> IO (Maybe Url)
extract = H.lookup