<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>Elliott Back's Blog - Latest Comments in Hashmap Implementation in C &amp;mdash; Elliott C. Back</title><link>http://elliottbacksblog.disqus.com/</link><description></description><language>en</language><lastBuildDate>Tue, 20 Jan 2009 11:55:21 -0000</lastBuildDate><item><title>Re: Hashmap Implementation in C &amp;mdash; Elliott C. Back</title><link>http://elliottback.com/wp/hashmap-implementation-in-c/#comment-5395105</link><description>You hashmap overwrites existing values!</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Joe</dc:creator><pubDate>Tue, 20 Jan 2009 11:55:21 -0000</pubDate></item><item><title>Re: Hashmap Implementation in C &amp;mdash; Elliott C. Back</title><link>http://elliottback.com/wp/hashmap-implementation-in-c/#comment-3186583</link><description>Hi Elliot,&lt;br&gt;I find the code useful..&lt;br&gt;Could you please forward me the include file so that i can do some modifications to it to serve my purpose.&lt;br&gt;&lt;br&gt;Thanks...&lt;br&gt;Vikas</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">vikas</dc:creator><pubDate>Mon, 24 Dec 2007 02:30:29 -0000</pubDate></item><item><title>Re: Hashmap Implementation in C &amp;mdash; Elliott C. Back</title><link>http://elliottback.com/wp/hashmap-implementation-in-c/#comment-3186582</link><description>Hello Elliot, &lt;br&gt;&lt;br&gt;Thanks for this posting of the code. I was wondering if you could send me the include files so that I get the fully functional code. As part of my project, I am doing a study of some of the implementations for hash table for space consumption check. &lt;br&gt;&lt;br&gt;Thanks.&lt;br&gt;&lt;br&gt;Regards, &lt;br&gt;Kajal</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Kajal</dc:creator><pubDate>Mon, 05 Nov 2007 15:11:25 -0000</pubDate></item><item><title>Re: Hashmap Implementation in C &amp;mdash; Elliott C. Back</title><link>http://elliottback.com/wp/hashmap-implementation-in-c/#comment-3186581</link><description>Hi, Could you please let me know the steps to include n compile in windows ? I am using Win 32 C/C++ compiler comes with Windows SDK.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Srinivas</dc:creator><pubDate>Mon, 15 Oct 2007 22:54:08 -0000</pubDate></item><item><title>Re: Hashmap Implementation in C &amp;mdash; Elliott C. Back</title><link>http://elliottback.com/wp/hashmap-implementation-in-c/#comment-3186580</link><description>Yo! You really didn't understand the various hash methods (i.e. mod, knuth, etc). I mean, you used them all in your hash function. Read some more :)</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">saark</dc:creator><pubDate>Sat, 01 Sep 2007 04:03:29 -0000</pubDate></item><item><title>Re: Hashmap Implementation in C &amp;mdash; Elliott C. Back</title><link>http://elliottback.com/wp/hashmap-implementation-in-c/#comment-3186579</link><description>厉害,不知道你能不能看懂汉字,cool, good</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">骋</dc:creator><pubDate>Mon, 23 Jul 2007 04:37:59 -0000</pubDate></item><item><title>Re: Hashmap Implementation in C &amp;mdash; Elliott C. Back</title><link>http://elliottback.com/wp/hashmap-implementation-in-c/#comment-3186578</link><description>I made a improment to your code and it's 100 times faster now. Even 40% faster than the stdext::hash_map in VC2005.&lt;br&gt;&lt;br&gt;I will post my code in my blog latter tonight.&lt;br&gt;&lt;br&gt;The basic idea is that:&lt;br&gt;1. hashmap_get should exit at the first encouter with an empty slot. Or else it will loop through all elements at a miss.&lt;br&gt;&lt;br&gt;2. hashmap_remove should rehash the elements between the deleted element and the first empty slot after it.&lt;br&gt;&lt;br&gt;3. table_size should always be two times bigger than size. &lt;br&gt;This will ensure that there will always be a empty slot not too far way. This will make hashmap_get and hashmap_remove 20 times faster in my case.&lt;br&gt;&lt;br&gt;4. some other bug fixes.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">kingsimba</dc:creator><pubDate>Tue, 26 Jun 2007 01:42:19 -0000</pubDate></item><item><title>Re: Hashmap Implementation in C &amp;mdash; Elliott C. Back</title><link>http://elliottback.com/wp/hashmap-implementation-in-c/#comment-3186577</link><description>It's pretty cool to see everybody with interesting names demanding additional work on your part, Mr. Back.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">art Zweiban</dc:creator><pubDate>Wed, 11 Apr 2007 14:06:08 -0000</pubDate></item><item><title>Re: Hashmap Implementation in C &amp;mdash; Elliott C. Back</title><link>http://elliottback.com/wp/hashmap-implementation-in-c/#comment-3186576</link><description>Hi all,&lt;br&gt;&lt;br&gt;i find this project very interesting. thanks a lot Elliot. But i need the file sync.h. can you provide it to me please.&lt;br&gt;&lt;br&gt;regards</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">mdiarra</dc:creator><pubDate>Sat, 17 Mar 2007 22:45:10 -0000</pubDate></item><item><title>Re: Hashmap Implementation in C &amp;mdash; Elliott C. Back</title><link>http://elliottback.com/wp/hashmap-implementation-in-c/#comment-3186575</link><description>it would be better if you gave a more clear example to use the module.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">gruva</dc:creator><pubDate>Sat, 10 Feb 2007 16:00:53 -0000</pubDate></item><item><title>Re: Hashmap Implementation in C &amp;mdash; Elliott C. Back</title><link>http://elliottback.com/wp/hashmap-implementation-in-c/#comment-3186574</link><description>Hey, thx a lot, ur code is great, it really helped me alot...but It just took me along time to figure out. but thx so much...</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">tiku</dc:creator><pubDate>Tue, 05 Dec 2006 19:43:17 -0000</pubDate></item><item><title>Re: Hashmap Implementation in C &amp;mdash; Elliott C. Back</title><link>http://elliottback.com/wp/hashmap-implementation-in-c/#comment-3186573</link><description>Java Collections Framework provides a well designed set of  interfaces and classes that support operations on a collections of objects.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Collections</dc:creator><pubDate>Sat, 25 Nov 2006 15:30:55 -0000</pubDate></item><item><title>Re: Hashmap Implementation in C &amp;mdash; Elliott C. Back</title><link>http://elliottback.com/wp/hashmap-implementation-in-c/#comment-3186572</link><description>Hi Elliott.&lt;br&gt;            The code looks good and also easly usable but the 2 include files are  needed to you this code and hence makes it un-useable. pls provide me those include files as soon as possible.&lt;br&gt;&lt;br&gt;Thanks&lt;br&gt;Sunil</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">sunil</dc:creator><pubDate>Fri, 14 Jul 2006 05:40:16 -0000</pubDate></item><item><title>Re: Hashmap Implementation in C &amp;mdash; Elliott C. Back</title><link>http://elliottback.com/wp/hashmap-implementation-in-c/#comment-3186571</link><description>Can you please attach the sync.h file and any associated implementation file, as I can see many semaphore related calls but have no idea where to find them !</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">mans</dc:creator><pubDate>Thu, 19 Jan 2006 03:21:24 -0000</pubDate></item><item><title>Re: Hashmap Implementation in C &amp;mdash; Elliott C. Back</title><link>http://elliottback.com/wp/hashmap-implementation-in-c/#comment-3186570</link><description>Can you give an example of how to use the iteration function?&lt;br&gt;&lt;br&gt;Thanks</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Boris</dc:creator><pubDate>Thu, 20 Oct 2005 18:57:31 -0000</pubDate></item><item><title>Re: Hashmap Implementation in C &amp;mdash; Elliott C. Back</title><link>http://elliottback.com/wp/hashmap-implementation-in-c/#comment-3186569</link><description>Hey Sujay.  It's not obvious, but the hashmap_put function calls hashmap_hash to find an index.  Hashmap_hash uses linear probing to find the next available spot.  Of course, if the hashmap is full when you call hashmap_put, a resize call will be issued.  Therefore, two keys never "hash" to the same array location.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Elliott Back</dc:creator><pubDate>Fri, 03 Jun 2005 20:50:05 -0000</pubDate></item><item><title>Re: Hashmap Implementation in C &amp;mdash; Elliott C. Back</title><link>http://elliottback.com/wp/hashmap-implementation-in-c/#comment-3186568</link><description>I think the put function will fail, if you have two key values generating the same hash value in the array range. (say keys "abc" and "xyz" generate a hash code of '99' in the array range 0-1024 (According to the program i think the key value will be '99'..right ??). How will this put function deal with this?? It will overwrite the existing one.&lt;br&gt;&lt;br&gt;I think the solution to this is to store even the key values ("abc" or "xyz" ) in the structure hash_element, so that we can compare this while inserting and this must be unique.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">sujay</dc:creator><pubDate>Fri, 03 Jun 2005 17:50:05 -0000</pubDate></item><item><title>Re: Hashmap Implementation in C &amp;mdash; Elliott C. Back</title><link>http://elliottback.com/wp/hashmap-implementation-in-c/#comment-3186567</link><description>As you can tell from the datastructure, you need to be passing pointers to the object memory.  If you allocate a static struct "s", to put it in the map you would call the &lt;br&gt;&lt;br&gt;hashmap_put(map_t in, int key, any_t value)&lt;br&gt;&lt;br&gt;method.  You can think of any_t as an alias for void *: it's defined in the header somewhere,  So, you'd call:&lt;br&gt;&lt;br&gt;&lt;blockquote&gt;hashmap_put(in, 1337, &amp;s;);&lt;/blockquote&gt;&lt;br&gt;&lt;br&gt;If s is already a pointer type, just call:&lt;br&gt;&lt;br&gt;&lt;blockquote&gt;hashmap_put(in, 1337, s);&lt;/blockquote&gt;&lt;br&gt;&lt;br&gt;To get something out of the datastructure, again just pass a pointer:&lt;br&gt;&lt;br&gt;&lt;blockquote&gt;your_struct_name s;&lt;br&gt;hashmap_get(in, 1337, &amp;s;);&lt;/blockquote&gt;&lt;br&gt;&lt;br&gt;Don't forget to check the return values!  All the hashmap methods should return a constant indicating success.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Elliott Back</dc:creator><pubDate>Thu, 05 May 2005 22:55:01 -0000</pubDate></item><item><title>Re: Hashmap Implementation in C &amp;mdash; Elliott C. Back</title><link>http://elliottback.com/wp/hashmap-implementation-in-c/#comment-3186566</link><description>Thanks for the example.&lt;br&gt;Can we store any type of variable e.g. struture as a value ?&lt;br&gt;If yes how can I retrieve the values from the hash map.&lt;br&gt;The hashmap_get is returning me junk values.I would appreciate a code sample.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">vinod</dc:creator><pubDate>Thu, 05 May 2005 15:51:59 -0000</pubDate></item><item><title>Re: Hashmap Implementation in C &amp;mdash; Elliott C. Back</title><link>http://elliottback.com/wp/hashmap-implementation-in-c/#comment-3186565</link><description>The above code allocates a datastructure for a filesystem I wrote, allocates the blocks hashmap, which keeps track of all the physical blocks of memory we can use, and then I show a for loop which puts the blocks into the hashmap indexed by the current length of the hashmap, i.e. 0, 1, ... , n.  This way I end up with a hashmap of all the blocks currently in use in the filesystem (upon load).</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Elliott Back</dc:creator><pubDate>Wed, 04 May 2005 21:10:39 -0000</pubDate></item><item><title>Re: Hashmap Implementation in C &amp;mdash; Elliott C. Back</title><link>http://elliottback.com/wp/hashmap-implementation-in-c/#comment-3186564</link><description>struct minifile {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* Other blocks */&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;map_t blocks;&lt;br&gt;};&lt;br&gt;&lt;br&gt;typedef struct minifile* minifile_t;&lt;br&gt;&lt;br&gt;...&lt;br&gt;&lt;br&gt;// Allocate a file&lt;br&gt;file = (minifile_t) malloc(sizeof(struct minifile));&lt;br&gt;if(!file) return NULL;&lt;br&gt;&lt;br&gt;// Initialize blocks&lt;br&gt;file-&amp;gt;blocks = hashmap_new();&lt;br&gt;if (!file-&amp;gt;blocks) return NULL;&lt;br&gt;&lt;br&gt;...&lt;br&gt;&lt;br&gt;/* Get blocks */&lt;br&gt;for(i = 0; i &amp;lt; num_blocks; i++){&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int *temp = (int *) malloc(sizeof(1));&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*temp = *inode; inode++;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if(hashmap_put(file-&amp;gt;blocks, hashmap_length(file-&amp;gt;blocks), temp) != MAP_OK)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return NULL;&lt;br&gt;}</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Elliott Back</dc:creator><pubDate>Wed, 04 May 2005 21:08:36 -0000</pubDate></item><item><title>Re: Hashmap Implementation in C &amp;mdash; Elliott C. Back</title><link>http://elliottback.com/wp/hashmap-implementation-in-c/#comment-3186563</link><description>can you send me sample example  on how to use this hashmap ?</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">vinod</dc:creator><pubDate>Wed, 04 May 2005 18:05:34 -0000</pubDate></item></channel></rss>