Subj : Re: Order-preserving hash of strings To : comp.programming From : William Date : Fri Sep 16 2005 02:41 pm "Alex Fraser" wrote in message news:_cCdnTe9YZC-FbfenZ2dnUVZ8qCdnZ2d@eclipse.net.uk... > "Digital Puer" wrote in message > news:1126832235.004650.149620@g43g2000cwa.googlegroups.com... > > Hi, suppose I have a list of character strings and want > > to hash them to integers for use in a lookup table. The > > problem is that the hashed values need to preserve the > > order that the strings occurred in the list. For example, > > a possible hashing of a list of three strings would be > > is 9, 12, 30 respectively; an illegal hashing would be > > 7, 5, 2 (this hashing does not preserve the order). > > This sounds tricky at best, if the list of strings is known in advance and > fixed, and probably totally impractical otherwise. > > Would an array (or list) of the strings in order, and a hash table > containing array indexes (or pointers to list items) solve the problem? That's how I did it. I needed to parse ordered properties files and rewrite them (using Java) so I rolled my own properties class that provided an ordered array and a hash of indices. Simple and fun. -Wm .