<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: String Search: Boyer-Moore</title>
	<atom:link href="http://programmingpraxis.com/2009/08/28/string-search-boyer-moore/feed/" rel="self" type="application/rss+xml" />
	<link>http://programmingpraxis.com/2009/08/28/string-search-boyer-moore/</link>
	<description>A collection of etudes, updated weekly, for the education and enjoyment of the savvy programmer</description>
	<lastBuildDate>Sat, 11 Feb 2012 09:48:16 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Vikas Tandi</title>
		<link>http://programmingpraxis.com/2009/08/28/string-search-boyer-moore/#comment-3006</link>
		<dc:creator><![CDATA[Vikas Tandi]]></dc:creator>
		<pubDate>Mon, 09 May 2011 06:28:02 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1228#comment-3006</guid>
		<description><![CDATA[Here is my code in C
[sourcecode lang=&quot;cpp&quot;]
#include &lt;limits.h&gt;

/* Boyer–Moore–Horspool algorithm */
int string_index_3(char *s, int str_size, char *p, int pattern_size)
{
	int i, j;
	int bad_char_shift[UCHAR_MAX+1];

	/* sanity check */
	if(!s &#124;&#124; !p &#124;&#124; pattern_size &lt;= 0)
		return -1;

	/* initialize shift table */
	for(i = 0; i &lt;= UCHAR_MAX; i++)
		bad_char_shift[i] = pattern_size;

	/* build shift table */
	for(i = pattern_size-2; i &gt;= 0; i--)
		if(bad_char_shift[p[i]] == pattern_size)
			bad_char_shift[p[i]] = pattern_size - i - 1;

	/* search pattern */
	for(i = 0; i &lt; str_size;)
	{
		/* check the substring from right to left */
		for(j = pattern_size -1; p[j] == s[i+j]; j--)
			if(j == 0)
				return i+1;

		/* move right using skip table */
		i += bad_char_shift[s[i+pattern_size-1]];
	}
	return -1;
}
[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>Here is my code in C</p>
<pre class="brush: cpp;">
#include &lt;limits.h&gt;

/* Boyer–Moore–Horspool algorithm */
int string_index_3(char *s, int str_size, char *p, int pattern_size)
{
	int i, j;
	int bad_char_shift[UCHAR_MAX+1];

	/* sanity check */
	if(!s || !p || pattern_size &lt;= 0)
		return -1;

	/* initialize shift table */
	for(i = 0; i &lt;= UCHAR_MAX; i++)
		bad_char_shift[i] = pattern_size;

	/* build shift table */
	for(i = pattern_size-2; i &gt;= 0; i--)
		if(bad_char_shift[p[i]] == pattern_size)
			bad_char_shift[p[i]] = pattern_size - i - 1;

	/* search pattern */
	for(i = 0; i &lt; str_size;)
	{
		/* check the substring from right to left */
		for(j = pattern_size -1; p[j] == s[i+j]; j--)
			if(j == 0)
				return i+1;

		/* move right using skip table */
		i += bad_char_shift[s[i+pattern_size-1]];
	}
	return -1;
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Remco Niemeijer</title>
		<link>http://programmingpraxis.com/2009/08/28/string-search-boyer-moore/#comment-556</link>
		<dc:creator><![CDATA[Remco Niemeijer]]></dc:creator>
		<pubDate>Sat, 29 Aug 2009 20:18:42 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1228#comment-556</guid>
		<description><![CDATA[My Haskell solution (see http://bonsaicode.wordpress.com/2009/08/29/programming-praxis-string-search-boyer-moore/ for a version with comments):

[sourcecode lang=&#039;css&#039;]
import Data.Map (findWithDefault, fromList, (!))

horspool :: Ord a =&gt; [a] -&gt; Maybe Int -&gt; [a] -&gt; Maybe Int
horspool pat skip xs = f (lp - 1 + maybe 0 id skip) p&#039; where
    (lp, lxs, p&#039;) = (length pat, length xs, reverse pat)
    t = fromList $ zip pat [lp - 1, lp - 2..]
    m = fromList $ zip [0..] xs
    f n []     = Just (n + 1)
    f n (p:ps) &#124; n &gt;= lxs   = Nothing
	           &#124; p == m ! n = f (n - 1) ps
               &#124; otherwise  = f (n + findWithDefault lp (m ! n) t) p&#039;
[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>My Haskell solution (see <a href="http://bonsaicode.wordpress.com/2009/08/29/programming-praxis-string-search-boyer-moore/" rel="nofollow">http://bonsaicode.wordpress.com/2009/08/29/programming-praxis-string-search-boyer-moore/</a> for a version with comments):</p>
<pre class="brush: css;">
import Data.Map (findWithDefault, fromList, (!))

horspool :: Ord a =&gt; [a] -&gt; Maybe Int -&gt; [a] -&gt; Maybe Int
horspool pat skip xs = f (lp - 1 + maybe 0 id skip) p' where
    (lp, lxs, p') = (length pat, length xs, reverse pat)
    t = fromList $ zip pat [lp - 1, lp - 2..]
    m = fromList $ zip [0..] xs
    f n []     = Just (n + 1)
    f n (p:ps) | n &gt;= lxs   = Nothing
	           | p == m ! n = f (n - 1) ps
               | otherwise  = f (n + findWithDefault lp (m ! n) t) p'
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Programming Praxis &#8211; String Search: Boyer-Moore &#171; Bonsai Code</title>
		<link>http://programmingpraxis.com/2009/08/28/string-search-boyer-moore/#comment-555</link>
		<dc:creator><![CDATA[Programming Praxis &#8211; String Search: Boyer-Moore &#171; Bonsai Code]]></dc:creator>
		<pubDate>Sat, 29 Aug 2009 20:18:18 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1228#comment-555</guid>
		<description><![CDATA[[...] Praxis &#8211; String Search:&#160;Boyer-Moore By Remco Niemeijer  In yesterday’s Programming Praxis problem we have to implement a more efficient string search algorithm than the [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Praxis &#8211; String Search:&nbsp;Boyer-Moore By Remco Niemeijer  In yesterday’s Programming Praxis problem we have to implement a more efficient string search algorithm than the [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Connochaetes</title>
		<link>http://programmingpraxis.com/2009/08/28/string-search-boyer-moore/#comment-554</link>
		<dc:creator><![CDATA[Connochaetes]]></dc:creator>
		<pubDate>Fri, 28 Aug 2009 13:32:09 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.com/?p=1228#comment-554</guid>
		<description><![CDATA[[sourcecode lang=&#039;ruby&#039;]
Maxchar = 256

def preprocess(pattern)
	length    = pattern.length
	skip 	  = Array.new(Maxchar, length)
	index     = -1 
	pattern.each_byte  do &#124;b&#124;
		skip[b] = length - (index += 1) - 1
	end
	skip
end

def horspool_search(str, pattern)
	m, n = pattern.length, str.length
	skip = preprocess(pattern)
	k, j = m-1, m-1
	while k &lt; n
		i = k
		while j&gt;=0 and str[i] == pattern[j]
			i -=1; j -= 1
		end
		return i+1 if j == -1
		k += skip[str[k]]
	end
	nil
end
[/sourcecode]]]></description>
		<content:encoded><![CDATA[<pre class="brush: ruby;">
Maxchar = 256

def preprocess(pattern)
	length    = pattern.length
	skip 	  = Array.new(Maxchar, length)
	index     = -1
	pattern.each_byte  do |b|
		skip[b] = length - (index += 1) - 1
	end
	skip
end

def horspool_search(str, pattern)
	m, n = pattern.length, str.length
	skip = preprocess(pattern)
	k, j = m-1, m-1
	while k &lt; n
		i = k
		while j&gt;=0 and str[i] == pattern[j]
			i -=1; j -= 1
		end
		return i+1 if j == -1
		k += skip[str[k]]
	end
	nil
end
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>

