Skip to content

Serious Data.HashTable bug

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]]
Trac metadata
Trac field Value
Version 6.4.1
Type Bug
TypeOfFailure OtherFailure
Priority high
Resolution Unresolved
Component libraries/base
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system Unknown
Architecture Unknown
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information