29 lines
587 B
Haskell
29 lines
587 B
Haskell
module Breve.UrlTable
|
|
( UrlTable
|
|
, records
|
|
, insert
|
|
, extract
|
|
) where
|
|
|
|
import Breve.Generator
|
|
|
|
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
|