packages feed

breve-0.0.2.0: src/Breve/UrlTable.hs

module Breve.UrlTable
( UrlTable
, records
, insert
, extract
) where

import Breve.Generator
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