<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>cat brain.log &#124; less &#187; function</title>
	<atom:link href="http://log.largevoid.com/tag/function/feed/" rel="self" type="application/rss+xml" />
	<link>http://log.largevoid.com</link>
	<description>Getting it down on `paper`</description>
	<lastBuildDate>Mon, 06 Feb 2012 06:23:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Fast Hash Function for Strings</title>
		<link>http://log.largevoid.com/2010/07/fast-hash-function-for-strings/</link>
		<comments>http://log.largevoid.com/2010/07/fast-hash-function-for-strings/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 03:20:05 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[Reference]]></category>
		<category><![CDATA[double-hashing]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[hash function]]></category>
		<category><![CDATA[hash table]]></category>
		<category><![CDATA[int]]></category>
		<category><![CDATA[key]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[table]]></category>

		<guid isPermaLink="false">http://log.largevoid.com/?p=410</guid>
		<description><![CDATA[Pre-condition: str is null terminated. int hash&#40;const void * str&#41; &#123; int val = 0; const char *ptr; int tmp; &#160; while &#40;*ptr != '\0'&#41; &#123; val = &#40;val &#60;&#60; 4&#41; + &#40;*ptr&#41;; if &#40;tmp = &#40;val &#38; 0xf0000000&#41;&#41; &#123; val = val ^ &#40;tmp &#62;&#62; 24&#41;; val = val ^ tmp; &#125; &#125; ptr++; [...]]]></description>
			<content:encoded><![CDATA[<p>Pre-condition: str is null terminated.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> hash<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span> str<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">int</span> val <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
  <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>ptr<span style="color: #339933;">;</span>
  <span style="color: #993333;">int</span> tmp<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>ptr <span style="color: #339933;">!=</span> <span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    val <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>val <span style="color: #339933;">&lt;&lt;</span> <span style="color: #0000dd;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>ptr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>tmp <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>val <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0xf0000000</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      val <span style="color: #339933;">=</span> val <span style="color: #339933;">^</span> <span style="color: #009900;">&#40;</span>tmp <span style="color: #339933;">&gt;&gt;</span> <span style="color: #0000dd;">24</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      val <span style="color: #339933;">=</span> val <span style="color: #339933;">^</span> tmp<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
  ptr<span style="color: #339933;">++;</span>
  <span style="color: #b1b100;">return</span> val<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Or in PHP:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">hash</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$val</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$n</span><span style="color: #339933;">=</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$n</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$val</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #339933;">&lt;&lt;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #990000;">ord</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$tmp</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span> <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0xf0000000</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
      <span style="color: #000088;">$val</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$val</span> ^ <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmp</span><span style="color: #339933;">&gt;&gt;</span><span style="color: #cc66cc;">24</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$val</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$val</span> ^ <span style="color: #000088;">$tmp</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$val</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now all you have to do is mod the returned value by the size of the hash table and you have the target address for the first pass of a hash table with double-hashing.</p>
]]></content:encoded>
			<wfw:commentRss>http://log.largevoid.com/2010/07/fast-hash-function-for-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Form Follows Function</title>
		<link>http://log.largevoid.com/2009/11/form-follows-function/</link>
		<comments>http://log.largevoid.com/2009/11/form-follows-function/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 04:37:32 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[Socratic deductions]]></category>
		<category><![CDATA[Thought Fragments]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[trade-offs]]></category>

		<guid isPermaLink="false">http://log.largevoid.com/?p=57</guid>
		<description><![CDATA[What do you picture when you hear the phrase &#8220;form follows function&#8221;? Do you envision an architectural structure? An artist&#8217;s painting? A toothbrush? Clearly, we mean that form is the after-thought and function is the primary objective. Or do we mean that the form of an object is driven by its function? When looking for [...]]]></description>
			<content:encoded><![CDATA[<p>What do you picture when you hear the phrase &#8220;form follows function&#8221;?  Do you envision an architectural structure?  An artist&#8217;s painting?  A toothbrush?</p>
<p>Clearly, we mean that form is the after-thought and function is the primary objective. Or do we mean that the form of an object is driven by its function?</p>
<p>When looking for ideas, switch between the two mantras, &#8220;<strong>form follows function</strong>&#8221; and &#8220;<strong>form vs. function</strong>.&#8221;  Does your product change?  Try to answer the question: Does the product have to change?</p>
<p>WordPress is the function, the theme is its form.  The form can sometimes be a separate product entirely.</p>
]]></content:encoded>
			<wfw:commentRss>http://log.largevoid.com/2009/11/form-follows-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  log.largevoid.com/tag/function/feed/ ) in 0.38210 seconds, on Feb 8th, 2012 at 12:29 pm UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 8th, 2012 at 1:29 pm UTC -->
