From: Marcin 'Qrczak' Kowalczyk Date: 2002-10-22T00:25:08+09:00 Subject: Re: Checking hash key's and values, with case insensitivity Tue, 24 Sep 2002 15:43:41 +0900, Gavin Sinclair pisze: > I think Matz intended that the keys get case-neutralised upon entry into the > hash. Naturally, that stuffs you if you input both "Key" and "kEy" into the > hash, but as someone pointed out, if genuine case-insensitive retrieval is what > you want, then hash is not what you need. A hash table is as good for a case-insensitive dictionary as for a case-sensitive one. Just use appropriate equality and hash function. If equality is known to work like this. f(k1) == f(k2) (for some function f) and hashing is f(k).hash, then a better implementation is to cache values of f for all keys. Ruby's Hash can't use explicitly-provided equality and hashing, right? So a programmer it's forced to cache them, and store unmodified keys elsewhere if case should be preserved. In my language I would write 'hashMap (by: lowercase)' to obtain a case-insensitive hash. The implementation must use a somewhat changed representation to store both original and transformed keys. In Ruby it would be something like Hash.new_by {|k| k.tolower}, except that the block for a constructor conflicts with specifying the behavior on absent keys - Ruby methods take at most one block. So maybe something like Hash.new(by => proc {|k| k.tolower})? -- __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/