Re: [Haskell-cafe] Very imperfect hash function

2010-02-02 Thread Hans Aberg
On 2 Feb 2010, at 03:05, Richard O'Keefe wrote: A simple hash-function for strings is to simply exclusive-or the bytes and then reduce modulo a prime number, Simply exclusive-oring the bytes will give you at most 256 distinct results. (For an ASCII source, 128 distinct results.) After

Re: [Haskell-cafe] Very imperfect hash function

2010-02-01 Thread Richard O'Keefe
On Feb 1, 2010, at 9:04 AM, Hans Aberg wrote: A simple hash-function for strings is to simply exclusive-or the bytes and then reduce modulo a prime number, Simply exclusive-oring the bytes will give you at most 256 distinct results. (For an ASCII source, 128 distinct results.) After that,

Re: [Haskell-cafe] Very imperfect hash function

2010-01-31 Thread John Lato
On Fri, Jan 29, 2010 at 9:26 AM, Hans Aberg hab...@math.su.se wrote: On 29 Jan 2010, at 15:57, John Lato wrote: Are you basically just suggesting to stick everything in an array with the key as an index? You still need to fold the key values onto some interval. Not with a suitably large

Re: [Haskell-cafe] Very imperfect hash function

2010-01-31 Thread Hans Aberg
On 31 Jan 2010, at 20:07, John Lato wrote: Or are you suggesting an actual hash table? The hash function folds the keys onto an interval. Since you have Int values k, you might just use a mod k n function for that. If it's the latter, I'm not certain where the array fits into the

Re: [Haskell-cafe] Very imperfect hash function

2010-01-29 Thread John Lato
From: Hans Aberg hab...@math.su.se On 28 Jan 2010, at 20:07, Steve Schafer wrote: The data are currently in a large lookup table. To save space, I'd like to convert that into a sort of hash function: hash :: key - value My question is this: Is there any kind of generic approach that can

Re: [Haskell-cafe] Very imperfect hash function

2010-01-29 Thread Hans Aberg
On 29 Jan 2010, at 12:52, John Lato wrote: There are minimal perfect hash functions; there are some libraries mentioned here, though they are not in Haskell code: http://en.wikipedia.org/wiki/Perfect_hash_function This is suitable when you do a lot of lookups with few key updates. An

Re: [Haskell-cafe] Very imperfect hash function

2010-01-29 Thread John Lato
On Fri, Jan 29, 2010 at 12:46 PM, Hans Aberg hab...@math.su.se wrote: On 29 Jan 2010, at 12:52, John Lato wrote: There are minimal perfect hash functions; there are some libraries mentioned here, though they are not in Haskell code:  http://en.wikipedia.org/wiki/Perfect_hash_function This

Re: [Haskell-cafe] Very imperfect hash function

2010-01-29 Thread Hans Aberg
On 29 Jan 2010, at 15:57, John Lato wrote: That looks interesting too. Yet another idea: use arrays http://haskell.org/haskellwiki/Arrays Then build a hash table, say just taking mod k n, and have values in some lookup map. If n set of keys, average time complexity is O(1), and arrays

[Haskell-cafe] Very imperfect hash function

2010-01-28 Thread Steve Schafer
I'm looking for some algorithmic suggestions: I have a set of several hundred key/value pairs. The keys are 32-bit integers, and are all distinct. The values are also integers, but the number of values is small (only six in my current problem). So, obviously, several keys map to the same value.

Re: [Haskell-cafe] Very imperfect hash function

2010-01-28 Thread Hans Aberg
On 28 Jan 2010, at 20:07, Steve Schafer wrote: The data are currently in a large lookup table. To save space, I'd like to convert that into a sort of hash function: hash :: key - value My question is this: Is there any kind of generic approach that can make use of the knowledge about the