English 中文(简体)
鲁比拉1.8和1.9是否有同样的 has法?
原标题:Do Ruby 1.8 and 1.9 have the same hash code for a string?
  • 时间:2010-12-15 16:15:39
  •  标签:
  • ruby
  • hash

我想使用<代码>String.hash来生成散射代码,但我担心,如果我稍晚将版本从1.8升至1.9,所产生的散射代码也将发生变化。

Do Ruby 1.8 and 1.9 have the same hash code for a string?

最佳回答

幸运的是,答案是容易的,因为它们没有:

~$ ruby1.8 -e  p "hello world".hash 
444332266
~$ ruby1.9 -e  p "hello world".hash 
-194819219

如果你使用 built法,我建议将文字作为制造必要 has码的建筑过程的一部分。 请注意,即使从一台机器到另一台机器也不能保证相同。

如果您需要连贯一致的洗衣,则使用,CRC32:

>> require  zlib 
>> Zlib.crc32 "hello world"
=> 222957957
>> require  digest 
>> Digest::SHA1.hexdigest "hello world"
=> "2aae6c35c94fcfb415dbe95f408b9ce91ee846ed"
>> Digest::MD5.hexdigest "hello world"
=> "5eb63bbbe01eeed093cb22bb8f5acdc3"

它们的目的差别很大,但《儿童权利公约》32 具有将32个字数退回和相当快的优势,而《公约》1 是80个字数,但更有保障。 (我假定这并非出于加密目的,而是在需要时看一下SHA-256。)

问题回答

暂无回答




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签