Note that there are some explanatory texts on larger screens.

plurals
  1. POConsistent String#hash based only on the string's content
    primarykey
    data
    text
    <p><strong>GOAL:</strong> Map every URL handled by a server to 0, 1, 2, or 3, distributing as uniformly as possible.</p> <p>While the <a href="http://www.ruby-doc.org/core/classes/String.html#M001123">documentation</a> for ruby's String#hash method says it will "return a hash based on the string‘s length and content," this clearly isn't the whole story. A given string's hash is not consistent across invocations of the interpreter:</p> <pre><code>$ irb ruby-1.9.2-p180 :001 &gt; "foo".hash =&gt; 360517580588231756 ruby-1.9.2-p180 :002 &gt; ^D $ irb ruby-1.9.2-p180 :001 &gt; "foo".hash =&gt; -2716152678666510148 </code></pre> <p>This means a particular string's hash value may differ across, say, servers. Rails uses <code>String#hash</code> internally to map a URL path to one of four asset hosts (if the app's asset_host is <a href="http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html">so configured</a>), but this feature is a lot less efficient than it could be because of the cross-machine inconsistencies; different servers may map the same URL to different asset hosts, reducing the effectiveness of caches, clouding skies, cooling cups of tea prematurely, besmirching the reputations of otherwise fine programmers.</p> <p>Can you suggest an alternate hash function that could effectively and speedily distribute hashes across a typical app's URL space, preferably one that produces a Fixnum since, in the end, I'll want to map it into one of four asset hosts?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload