What I mean is, if I repeatedly call a String’s hash method (i.e. like
using it regularly to access a Hash) will the hash value get
recalculated every time?
Yes, it will. Have you considered unsing Symbols instead of Strings?
The hash value “calculation” of a Symbol is O(1).
···
On Tue, 2003-12-23 at 01:56, Asfand Yar Qazi wrote:
What I mean is, if I repeatedly call a String’s hash method (i.e. like
using it regularly to access a Hash) will the hash value get
recalculated every time?
–
o=lambda{|o|p o};O=Struct.new(:a,:b,:c);e=%q((?h,(?h,(?\ ,(?s,(?u,(74)),
(?t)),(?t,(?o,(?n,(?a))))),(82,(?r,(?e),(32)),(32,(98,(?u),(?y)))
)),(?r,(99,(97),(?k,nil,(?e))),_(10))));def _(*a)O.new(*a)end;class O;def
e(&o)b&&b.e(&o);o[a];c&&c.e(&o)end;end;def p(o)print(‘’<<o)end;eval(e).e(&o)
Hi,
···
At Tue, 23 Dec 2003 09:56:53 +0900, Asfand Yar Qazi wrote:
What I mean is, if I repeatedly call a String’s hash method (i.e. like
using it regularly to access a Hash) will the hash value get
recalculated every time?
Hash (accurately, st library) has cache, but String doesn’t.
–
Nobu Nakada
Florian Frank wrote:
···
On Tue, 2003-12-23 at 01:56, Asfand Yar Qazi wrote:
What I mean is, if I repeatedly call a String’s hash method (i.e. like
using it regularly to access a Hash) will the hash value get
recalculated every time?Yes, it will. Have you considered unsing Symbols instead of Strings?
The hash value “calculation” of a Symbol is O(1).
Depends… if Symbols are used as the keys for a hash table, can they be
as easily accessed from extension modules as if Strings were used?
–
why the should’nt ? Many lybraries make use of symbols as constants,
ruby-gtk or Pdf::Writer are examples… and, btw “everything is an
object” make everything work as everything else
···
il Wed, 24 Dec 2003 00:11:27 +0000, Asfand Yar Qazi <im_not_giving_it_here@i_hate_spam.com> ha scritto::
Yes, it will. Have you considered unsing Symbols instead of Strings?
The hash value “calculation” of a Symbol is O(1).Depends… if Symbols are used as the keys for a hash table, can they be
as easily accessed from extension modules as if Strings were used?
I don’t understand your question.
MyModule.config(:bar => “baz”)
You will need to document the hash parameters regardless of whether it’s
“bar” or :bar. Strings can also be converted to Symbols with #intern.
-austin
···
On Wed, 24 Dec 2003 09:06:51 +0900, Asfand Yar Qazi wrote:
Florian Frank wrote:
On Tue, 2003-12-23 at 01:56, Asfand Yar Qazi wrote:
What I mean is, if I repeatedly call a String’s hash method (i.e.
like using it regularly to access a Hash) will the hash value get
recalculated every time?
Yes, it will. Have you considered unsing Symbols instead of Strings?
The hash value “calculation” of a Symbol is O(1).
Depends… if Symbols are used as the keys for a hash table, can they be
as easily accessed from extension modules as if Strings were used?
–
austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2003.12.23
* 19.47.42
You can use ID2SYM(rb_intern(“foo”)) to get the VALUE of symbol :foo. I
don’t think it’s too complicated.
···
On Wed, 2003-12-24 at 01:06, Asfand Yar Qazi wrote:
Depends… if Symbols are used as the keys for a hash table, can they be
as easily accessed from extension modules as if Strings were used?
–
o=lambda{|o|p o};O=Struct.new(:a,:b,:c);e=%q((?h,(?h,(?\ ,(?s,(?u,(74)),
(?t)),(?t,(?o,(?n,(?a))))),(82,(?r,(?e),(32)),(32,(98,(?u),(?y)))
)),(?r,(99,(97),(?k,nil,(?e))),_(10))));def _(*a)O.new(*a)end;class O;def
e(&o)b&&b.e(&o);o[a];c&&c.e(&o)end;end;def p(o)print(‘’<<o)end;eval(e).e(&o)
Florian Frank wrote:
···
On Wed, 2003-12-24 at 01:06, Asfand Yar Qazi wrote:
Depends… if Symbols are used as the keys for a hash table, can they be
as easily accessed from extension modules as if Strings were used?You can use ID2SYM(rb_intern(“foo”)) to get the VALUE of symbol :foo. I
don’t think it’s too complicated.
WOW DAT WAS KWICK U R LEE7!!!11111
–