Opened 10 years ago

Closed 10 years ago

Last modified 21 months 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: 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 10 years ago by jwr@…

Formatting messed up the example. It should be:

HT> test 2048 

comment:2 Changed 10 years ago by simonmar

  • Milestone set to 6.4.2

comment:3 Changed 10 years ago by simonmar

  • Resolution set to fixed
  • Status changed from new to closed

Fixed, thanks.

comment:4 Changed 7 years ago by simonmar

  • Architecture changed from Unknown to Unknown/Multiple

comment:5 Changed 7 years ago by simonmar

  • Operating System changed from Unknown to Unknown/Multiple

comment:6 Changed 21 months ago by Simon Marlow <simonmar@…>

Note: See TracTickets for help on using tickets.