2006-08-20

Sold Arrays, Delivered Maps

The first idea was use Judy to backend implementation of arrays in Haskell. But, as became clear after a little thought and discussion (and specially pointed by Bulat++ in haskell-cafe), Judy library focus on good performance in dynamic arrays, but this wouldn't beat an memory region and data stored one next to another. The natural way to go was implementing a Map-like type. For this purpose was created a MapM type class to serve as interface for all possible Maps created (also tip by Bulat++)

Judy.IntMap is based on JudyL and allows as key-type any type that could be transformed into a word size representation. Judy.StrMap allows as key-type anything that could be stringable into a CString ending with a \0 character. Both Maps have a ordered traversal into its contents. Then Judy.Hash is based on JudyHS which allows as keys strings containing the \0 character in its strings (it stores the length of string instead of having an end identifier), but doesn't have ordered traversal.

To allow any Haskell type to be used as value for these Maps, was created an interface on top of StablePtrs that would create and deallocate them as needed. This can be modified for specific cases, e.g. Int types doesn't use StablePtrs since they fit in the Word reserved for values in Judy C library.

Saying that, all the tests I proposed in my application do benefit from Maps: Pugs project (as I already described), RBR (which was bounded by its use of Data.Map) and K-Nucleotide naive adaptation (in tests/k-judy.hs).

No comments:

About Me