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