[Haskell-cafe] Weird and entirely random problem...

Neil Brown nccb2 at kent.ac.uk
Wed Jun 10 12:58:36 EDT 2009


Hi,

I'm presuming the problem with your result is that the "<span..." String 
is in the times map, and not in the store map (you weren't clear on the 
exact problem).

I took a look at the code, here's my thoughts on why this occurs.  If 
you start by putting something in the cache with key "foo", an entry is 
created in the times map, say: fromList [(0, "foo")].  If you then get 
the item from the cache, you add another item to the times map, giving 
you: fromList [(0, "foo"), (1, "foo")].  Another get operation, and 
you'll have fromList [(0, "foo"), (1, "foo"), (2, "foo")].  If you now 
call free on the cache, it finds the value associated with the minimum 
key: "foo".  But it only deletes the minimum key in the times map, 
leaving: fromList [(1, "foo"), (2, "foo")].  Thus you can have entries 
in the times map without them being in the store.  put would clear them 
out (perhaps this was the self-correction you saw), but get adds one 
each item, and free only clears one.  So you either need to fix get, or 
free.

Does that help, or was your question something else entirely? :-)

BTW, IntMap.fromList . filter (f . snd) . IntMap.toList is more 
concisely (and efficiently) written as: IntMap.filter f

Thanks,

Neil.

Jeff Heard wrote:
> The code that causes it is here:
>
> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=5731#a5731
>
> This is the strangest thing.  Occasionally, using nothing but gets and
> puts and frees on a non-full Cache will result in this:
>
> Cache {
>       store = fromList
>         [("(\"icons/addBookmark.png\",False)",TextureObject {textureID = 4})
>         ,("(\"icons/addCircle.png\",False)",TextureObject {textureID = 1})
>         ,("(\"icons/addContent.png\",False)",TextureObject {textureID = 2})
>         ,("(\"icons/addElsewhereLink.png\",False)",TextureObject
> {textureID = 3})]
>     , times = fromList
>         [(61314,"(\"<span font_desc='sans
> 8'>294.0</span>\",AlignLeft,Nothing,WrapWholeWords,False,0.0,0.0)")
>         ,(61316,"(\"icons/addBookmark.png\",False)"),(61318,"(\"icons/addCircle.png\",False)")
>         ,(61320,"(\"icons/addContent.png\",False)"),(61322,"(\"icons/addElsewhereLink.png\",False)")]
>
>     , now = 61323
>     , maxsize = 1024768000
>     , size = 4
>     , decimation = 0
> }
>
>
> Sometimes the problem is self-correcting.  Sometimes it is most
> certainly not.  But I don't understand how my code can possibly allow
> for this.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>   



More information about the Haskell-Cafe mailing list