<?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/"
		>
<channel>
	<title>Comments on: Using Gcc C++ Hash Classes With Strings</title>
	<atom:link href="http://www.moosechips.com/2008/10/using-gcc-c-hash-classes-with-strings/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.moosechips.com/2008/10/using-gcc-c-hash-classes-with-strings/</link>
	<description>leaving my mark on the internet</description>
	<lastBuildDate>Sun, 01 Jan 2012 16:09:23 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: David</title>
		<link>http://www.moosechips.com/2008/10/using-gcc-c-hash-classes-with-strings/comment-page-1/#comment-214</link>
		<dc:creator>David</dc:creator>
		<pubDate>Thu, 30 Jun 2011 18:36:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.moosechips.com/?p=387#comment-214</guid>
		<description>mmm... something strange happend when I wrote my comment...  My question is about hash functions for unsigned long long int type!</description>
		<content:encoded><![CDATA[<p>mmm&#8230; something strange happend when I wrote my comment&#8230;  My question is about hash functions for unsigned long long int type!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David</title>
		<link>http://www.moosechips.com/2008/10/using-gcc-c-hash-classes-with-strings/comment-page-1/#comment-213</link>
		<dc:creator>David</dc:creator>
		<pubDate>Thu, 30 Jun 2011 18:34:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.moosechips.com/?p=387#comment-213</guid>
		<description>Hi! I&#039;ve been looking for a long time how to add hash support to my old gcc version! Now I am facing a new problem : how can I add hash support ? Thanks in advance!</description>
		<content:encoded><![CDATA[<p>Hi! I&#8217;ve been looking for a long time how to add hash support to my old gcc version! Now I am facing a new problem : how can I add hash support ? Thanks in advance!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MLRUS</title>
		<link>http://www.moosechips.com/2008/10/using-gcc-c-hash-classes-with-strings/comment-page-1/#comment-50</link>
		<dc:creator>MLRUS</dc:creator>
		<pubDate>Mon, 17 Aug 2009 03:04:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.moosechips.com/?p=387#comment-50</guid>
		<description>Thank you for this example.  I have a more complex template usage, and your example showed me that I simply have to dereference the iterator to get the results back.  I suppose I should add a typedef to make things readable, since now I have the following &quot;easy to read&quot; code:

  for( __gnu_cxx::_Hashtable_const_iterator&lt;const char*, const char*, __gnu_cxx::hash, 
          std::_Identity, Dictionary::eqstr, std::allocator &gt; 
       xit = dictionary.words.begin();  xit != dictionary.words.end(); xit++) {
      cout &lt;&lt; *xit &lt;&lt; endl;
  }



class Dictionary: public Storable {
    struct eqstr
    {
        bool operator()(const char* s1, const char* s2) const
        {
            return strcmp(s1, s2) == 0;
        }
    };

    __gnu_cxx::hash_set&lt;const char*,__gnu_cxx:: hash, eqstr&gt; words;

    inline const bool lookup(const __gnu_cxx::hash_set&lt;const char*, __gnu_cxx::hash, eqstr&gt;&amp; words,
            const char* word)
    {
        __gnu_cxx::hash_set&lt;const char*, __gnu_cxx::hash, eqstr&gt;::const_iterator it = words.find(word);
        return it!=words.end();
    }

    inline const bool lookup(const string&amp; word) {
        return lookup(words,word.c_str());
    }

    inline const bool lookup(const char *word) {
        return lookup(words,word);
    }


    public:

        inline const bool contains(const string &amp;entry) {
            return lookup(entry);
        }

        inline const bool contains(const char *entry) {
            return lookup(entry);
        }

        void clear() {
            words.clear();
        }

        inline int wordCount() {
            return words.size();
        }

        void read(const std::string &amp;filename) {
            try {
                ifstream infile(filename.c_str(), std::ios_base::in);
                string line;
                while (getline(infile, line, &#039;\n&#039;)) {
                    Util::trim(line);
                    Util::upperCase(line);
                    words.insert(strdup(line.c_str()));
                }
                infile.close();
            } catch (...) {
                cerr &lt;&lt; &quot;Error reading &quot; &lt;&lt; filename &lt;&lt; endl;
            }
        }

        Dictionary() :
            words() {

        }
        Dictionary(string &amp;filename) :
            words() {
            read(filename);
        }

        virtual ~Dictionary() {
            words.clear();
        }
};</description>
		<content:encoded><![CDATA[<p>Thank you for this example.  I have a more complex template usage, and your example showed me that I simply have to dereference the iterator to get the results back.  I suppose I should add a typedef to make things readable, since now I have the following &#8220;easy to read&#8221; code:</p>
<p>  for( __gnu_cxx::_Hashtable_const_iterator&lt;const char*, const char*, __gnu_cxx::hash,<br />
          std::_Identity, Dictionary::eqstr, std::allocator &gt;<br />
       xit = dictionary.words.begin();  xit != dictionary.words.end(); xit++) {<br />
      cout &lt;&lt; *xit &lt;&lt; endl;<br />
  }</p>
<p>class Dictionary: public Storable {<br />
    struct eqstr<br />
    {<br />
        bool operator()(const char* s1, const char* s2) const<br />
        {<br />
            return strcmp(s1, s2) == 0;<br />
        }<br />
    };</p>
<p>    __gnu_cxx::hash_set&lt;const char*,__gnu_cxx:: hash, eqstr&gt; words;</p>
<p>    inline const bool lookup(const __gnu_cxx::hash_set&lt;const char*, __gnu_cxx::hash, eqstr&gt;&amp; words,<br />
            const char* word)<br />
    {<br />
        __gnu_cxx::hash_set&lt;const char*, __gnu_cxx::hash, eqstr&gt;::const_iterator it = words.find(word);<br />
        return it!=words.end();<br />
    }</p>
<p>    inline const bool lookup(const string&amp; word) {<br />
        return lookup(words,word.c_str());<br />
    }</p>
<p>    inline const bool lookup(const char *word) {<br />
        return lookup(words,word);<br />
    }</p>
<p>    public:</p>
<p>        inline const bool contains(const string &amp;entry) {<br />
            return lookup(entry);<br />
        }</p>
<p>        inline const bool contains(const char *entry) {<br />
            return lookup(entry);<br />
        }</p>
<p>        void clear() {<br />
            words.clear();<br />
        }</p>
<p>        inline int wordCount() {<br />
            return words.size();<br />
        }</p>
<p>        void read(const std::string &amp;filename) {<br />
            try {<br />
                ifstream infile(filename.c_str(), std::ios_base::in);<br />
                string line;<br />
                while (getline(infile, line, &#8216;\n&#8217;)) {<br />
                    Util::trim(line);<br />
                    Util::upperCase(line);<br />
                    words.insert(strdup(line.c_str()));<br />
                }<br />
                infile.close();<br />
            } catch (&#8230;) {<br />
                cerr &lt;&lt; &#8220;Error reading &#8221; &lt;&lt; filename &lt;&lt; endl;<br />
            }<br />
        }</p>
<p>        Dictionary() :<br />
            words() {</p>
<p>        }<br />
        Dictionary(string &amp;filename) :<br />
            words() {<br />
            read(filename);<br />
        }</p>
<p>        virtual ~Dictionary() {<br />
            words.clear();<br />
        }<br />
};</p>
]]></content:encoded>
	</item>
</channel>
</rss>

