<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Hashable struct for the GS::HashTable&amp;lt;Key, Value&amp;gt; in Archicad C++ API</title>
    <link>https://community.graphisoft.com/t5/Archicad-C-API/Hashable-struct-for-the-GS-HashTable-lt-Key-Value-gt/m-p/309253#M1822</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I need to create a struct that can be used as a Key in a hashtable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far I made this:&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;struct Item{
		GS::UInt8 parentId;
		GS::UInt8 itemId;
		const GS::UInt8 hash = this-&amp;gt;parentId + this-&amp;gt;itemId;

		GS::ULong Item::GenerateHashValue() {
			return GS::GenerateHashValue(this-&amp;gt;hash);
		}
		bool operator== (const Item&amp;amp; other) const {
			return (this-&amp;gt;parentId == other.parentId &amp;amp;&amp;amp; this-&amp;gt;itemId == other.itemId);
		}
	};&lt;/LI-CODE&gt;&lt;P&gt;It gives me the error:&lt;/P&gt;&lt;P&gt;Does not have a GenerateHashValue member or non-member function. I am pretty sure I have GenerateHashValue.&lt;/P&gt;&lt;P&gt;Can you please point some directions on this matter?&lt;/P&gt;</description>
    <pubDate>Thu, 14 Oct 2021 07:30:38 GMT</pubDate>
    <dc:creator>Mihalcea Bogdan</dc:creator>
    <dc:date>2021-10-14T07:30:38Z</dc:date>
    <item>
      <title>Hashable struct for the GS::HashTable&lt;Key, Value&gt;</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Hashable-struct-for-the-GS-HashTable-lt-Key-Value-gt/m-p/309253#M1822</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I need to create a struct that can be used as a Key in a hashtable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far I made this:&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;struct Item{
		GS::UInt8 parentId;
		GS::UInt8 itemId;
		const GS::UInt8 hash = this-&amp;gt;parentId + this-&amp;gt;itemId;

		GS::ULong Item::GenerateHashValue() {
			return GS::GenerateHashValue(this-&amp;gt;hash);
		}
		bool operator== (const Item&amp;amp; other) const {
			return (this-&amp;gt;parentId == other.parentId &amp;amp;&amp;amp; this-&amp;gt;itemId == other.itemId);
		}
	};&lt;/LI-CODE&gt;&lt;P&gt;It gives me the error:&lt;/P&gt;&lt;P&gt;Does not have a GenerateHashValue member or non-member function. I am pretty sure I have GenerateHashValue.&lt;/P&gt;&lt;P&gt;Can you please point some directions on this matter?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 07:30:38 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Hashable-struct-for-the-GS-HashTable-lt-Key-Value-gt/m-p/309253#M1822</guid>
      <dc:creator>Mihalcea Bogdan</dc:creator>
      <dc:date>2021-10-14T07:30:38Z</dc:date>
    </item>
    <item>
      <title>Re: Hashable struct for the GS::HashTable&lt;Key, Value&gt;</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Hashable-struct-for-the-GS-HashTable-lt-Key-Value-gt/m-p/309256#M1823</link>
      <description>&lt;P&gt;I know how to make it work with c++ standard std::unordered_map&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;struct Item
{
	int parentId;
	short itemId;

	bool operator==(const Item &amp;amp;other) const
	{
		return (parentId == other.parentId &amp;amp;&amp;amp; itemId == other.itemId);
	}
};

template &amp;lt;&amp;gt;
struct std::hash&amp;lt;Item&amp;gt;
{
	std::size_t operator()(const Item&amp;amp; k) const
	{
		return (k.itemId + k.parentId);
	}
};&lt;/LI-CODE&gt;&lt;P&gt;with the above struct I can use the following:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Item itm = { 10, 20 };
Item itm2 = { 10, 20 };
std::unordered_map&amp;lt;Item, int&amp;gt; hashMap;
hashMap[itm] = 10;
hashMap[itm2] = 30;
std::cout &amp;lt;&amp;lt; hashMap[itm2] &amp;lt;&amp;lt; std::endl;&lt;/LI-CODE&gt;&lt;P&gt;Output will be 30.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 08:03:46 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Hashable-struct-for-the-GS-HashTable-lt-Key-Value-gt/m-p/309256#M1823</guid>
      <dc:creator>Mihalcea Bogdan</dc:creator>
      <dc:date>2021-10-14T08:03:46Z</dc:date>
    </item>
    <item>
      <title>Re: Hashable struct for the GS::HashTable&lt;Key, Value&gt;</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Hashable-struct-for-the-GS-HashTable-lt-Key-Value-gt/m-p/309276#M1824</link>
      <description>&lt;P&gt;I think you need to mplement the GenerateHashValue as non member function.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;GS::ULong GenerateHashValue( const Item&amp;amp; item )
{
	return GS::GenerateHashValue( item.parentId + item.itemId );
}&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 14 Oct 2021 10:42:22 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Hashable-struct-for-the-GS-HashTable-lt-Key-Value-gt/m-p/309276#M1824</guid>
      <dc:creator>Oleg</dc:creator>
      <dc:date>2021-10-14T10:42:22Z</dc:date>
    </item>
    <item>
      <title>Re: Hashable struct for the GS::HashTable&lt;Key, Value&gt;</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Hashable-struct-for-the-GS-HashTable-lt-Key-Value-gt/m-p/309277#M1825</link>
      <description>&lt;P&gt;And I guess there is other variant.&lt;BR /&gt;Inherit your Item from GS::Hashable and implement virtual member&amp;nbsp;&lt;BR /&gt;virtual ULong GenerateHashValue (void) const = 0;&lt;BR /&gt;&lt;BR /&gt;like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;struct Item : public GS::Hashable
{
	virtual ULong	GenerateHashValue (void) const { return this-&amp;gt;hash; }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Oct 2021 00:58:14 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Hashable-struct-for-the-GS-HashTable-lt-Key-Value-gt/m-p/309277#M1825</guid>
      <dc:creator>Oleg</dc:creator>
      <dc:date>2021-10-18T00:58:14Z</dc:date>
    </item>
    <item>
      <title>Re: Hashable struct for the GS::HashTable&lt;Key, Value&gt;</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Hashable-struct-for-the-GS-HashTable-lt-Key-Value-gt/m-p/309297#M1826</link>
      <description>&lt;P&gt;It says it is already declared in the .obj file. GIS is my namespace.&lt;/P&gt;&lt;P&gt;Error LNK2005 "unsigned int __cdecl GIS::GenerateHashValue(struct GIS::Item const &amp;amp;)" (?GenerateHashValue@GIS@@YAIAEBUItem@1@@Z) already defined in AddOnMain.obj AddOn \polyGIS\Build\Source.obj&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 13:19:31 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Hashable-struct-for-the-GS-HashTable-lt-Key-Value-gt/m-p/309297#M1826</guid>
      <dc:creator>Mihalcea Bogdan</dc:creator>
      <dc:date>2021-10-14T13:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: Hashable struct for the GS::HashTable&lt;Key, Value&gt;</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Hashable-struct-for-the-GS-HashTable-lt-Key-Value-gt/m-p/309299#M1827</link>
      <description>&lt;P&gt;I can't find the GS::Hashable class.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 13:20:06 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Hashable-struct-for-the-GS-HashTable-lt-Key-Value-gt/m-p/309299#M1827</guid>
      <dc:creator>Mihalcea Bogdan</dc:creator>
      <dc:date>2021-10-14T13:20:06Z</dc:date>
    </item>
    <item>
      <title>Re: Hashable struct for the GS::HashTable&lt;Key, Value&gt;</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Hashable-struct-for-the-GS-HashTable-lt-Key-Value-gt/m-p/309316#M1828</link>
      <description>&lt;P&gt;Sorry.&amp;nbsp; I worked on old project and checked it for old API.&lt;BR /&gt;&lt;SPAN&gt;It seem GS::Hashable was before AC24&amp;nbsp; and implementation of the HashTable was changed.&lt;BR /&gt;&lt;/SPAN&gt;I will try it for API 24 and 25 later.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 15:07:31 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Hashable-struct-for-the-GS-HashTable-lt-Key-Value-gt/m-p/309316#M1828</guid>
      <dc:creator>Oleg</dc:creator>
      <dc:date>2021-10-14T15:07:31Z</dc:date>
    </item>
    <item>
      <title>Re: Hashable struct for the GS::HashTable&lt;Key, Value&gt;</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Hashable-struct-for-the-GS-HashTable-lt-Key-Value-gt/m-p/309317#M1829</link>
      <description>&lt;P&gt;I was looking at other data structures which work with the GS::hashTable, the GS::Pair&amp;lt;T1, T2&amp;gt;. It has an implementation of the&amp;nbsp; GenerateHashValue() like you said.&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;//This is from the GS::Pair&amp;lt;&amp;gt;
template &amp;lt;class Type1, class Type2&amp;gt;
ULong	GenerateHashValue (const Pair&amp;lt;Type1, Type2&amp;gt;&amp;amp; pair)
{
	return GS::GenerateHashValue (pair.first, pair.second);
}&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 14 Oct 2021 15:11:23 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Hashable-struct-for-the-GS-HashTable-lt-Key-Value-gt/m-p/309317#M1829</guid>
      <dc:creator>Mihalcea Bogdan</dc:creator>
      <dc:date>2021-10-14T15:11:23Z</dc:date>
    </item>
    <item>
      <title>Re: Hashable struct for the GS::HashTable&lt;Key, Value&gt;</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Hashable-struct-for-the-GS-HashTable-lt-Key-Value-gt/m-p/309320#M1830</link>
      <description>&lt;P&gt;Fast tests. Works for me. VisualStudio.&lt;BR /&gt;Using test is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;GS::HashTable&amp;lt;Item,int&amp;gt; table;
Item itm = { 10, 20 };
table.Add(itm, 2);
table[itm] = 3;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;AC24 (you need &lt;STRONG&gt;const&amp;nbsp;&lt;/STRONG&gt;qualifier)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;GS::ULong Item::GenerateHashValue() const 
{
	return GS::GenerateHashValue(this-&amp;gt;hash);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;AC25 (dont have time to study it )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;GS::ULong Item::GenerateHashValue() const 
{
	return GS::CalculateHashValue(this-&amp;gt;hash);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And just reply. Are you shure to use summary Ids for hashe generation ?&lt;BR /&gt;May be beter like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;GS::ULong Item::GenerateHashValue() const 
{
	return ((ULong) parentId &amp;lt;&amp;lt; 8 ) | itemId;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 16:57:59 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Hashable-struct-for-the-GS-HashTable-lt-Key-Value-gt/m-p/309320#M1830</guid>
      <dc:creator>Oleg</dc:creator>
      <dc:date>2021-10-14T16:57:59Z</dc:date>
    </item>
    <item>
      <title>Re: Hashable struct for the GS::HashTable&lt;Key, Value&gt;</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Hashable-struct-for-the-GS-HashTable-lt-Key-Value-gt/m-p/309321#M1831</link>
      <description>&lt;P&gt;I was pretty sure that there will be no conflict. Now that I think more about it will not work.&amp;nbsp; Your solution works for me too, I forgot about the const, it is the same behavior as with operator overriding. Thank you very much!&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 17:02:49 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Hashable-struct-for-the-GS-HashTable-lt-Key-Value-gt/m-p/309321#M1831</guid>
      <dc:creator>Mihalcea Bogdan</dc:creator>
      <dc:date>2021-10-14T17:02:49Z</dc:date>
    </item>
  </channel>
</rss>

