Opened 12 years ago

Closed 12 years ago

Last modified 4 years ago

#661 closed bug (fixed)

Serious Data.HashTable bug

Reported by: jwr@… Owned by:
Priority: high Milestone: 6.4.2
Component: libraries/base Version: 6.4.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


The program below illustrates a difference between the description of the semantics of insert (given below) and the implementation. Try calling the function "test" with values greater than 2047. For instance:

HT> test 2048 0 1024

The documentation states: insert :: HashTable key val -> key -> val -> IO ()

Inserts an key/value mapping into the hash table.

Note that insert doesn't remove the old entry from the table

  • the behaviour is like an association list, where lookup returns

the most-recently-inserted mapping for a key in the table. The reason for this is to keep insert as efficient as possible. If you need to update a mapping, then we provide update.

module HT where

import Data.HashTable
import qualified Data.HashTable as HT

test :: Int -> IO ()
test n = do ht <- new (==) hashInt
            sequence_ [ insert ht key 0 | key <- [0..n]]
            sequence_ [ insert ht key 1 | key <- [0..n]]
            let check key = do (Just val) <- HT.lookup ht key
                               if val==1 then return () else putStrLn $ show key 
            sequence_ [ check key | key <- [0..n]]

Change History (6)

comment:1 Changed 12 years ago by jwr@…

Formatting messed up the example. It should be:

HT> test 2048 

comment:2 Changed 12 years ago by simonmar

Milestone: 6.4.2

comment:3 Changed 12 years ago by simonmar

Resolution: fixed
Status: newclosed

Fixed, thanks.

comment:4 Changed 9 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:5 Changed 9 years ago by simonmar

Operating System: UnknownUnknown/Multiple

comment:6 Changed 4 years ago by Simon Marlow <simonmar@…>

Note: See TracTickets for help on using tickets.