First let's see what data struction he used.
struct entry
{
void *k, *v;
unsigned int h;
struct entry *next;
};
struct hashtable {
unsigned int tablelength;
struct entry **table;
unsigned int entrycount;
unsigned int loadlimit;
unsigned int primeindex;
unsigned int (*hashfn) (void *k);
int (*eqfn) (void *k1, void *k2);
};
static const unsigned int primes[] = {
53, 97, 193, 389,
769, 1543, 3079, 6151,
12289, 24593, 49157, 98317,
196613, 393241, 786433, 1572869,
3145739, 6291469, 12582917, 25165843,
50331653, 100663319, 201326611, 402653189,
805306457, 1610612741
};
const unsigned int prime_table_length = sizeof(primes)/sizeof(primes[0]);
const float max_load_factor = 0.65;
The import function is creat_hashtable here.
struct hashtable *create_hashtable(unsigned int minsize,
unsigned int (*hashf) (void*),
int (*eqf) (void*,void*))
{
struct hashtable *h;
unsigned int pindex, size = primes[0];
/* Check requested hashtable isn't too large */
if (minsize > (1u << 30)) return NULL;
/* Enforce size as prime */
for (pindex=0; pindex < prime_table_length; pindex++) {
if (primes[pindex] > minsize) { size = primes[pindex]; break; }
}
h = (struct hashtable *)malloc(sizeof(struct hashtable));
if (NULL == h) return NULL; /*oom*/
h->table = (struct entry **)malloc(sizeof(struct entry*) * size);
if (NULL == h->table) { free(h); return NULL; } /*oom*/
memset(h->table, 0, size * sizeof(struct entry *));
h->tablelength = size;
h->primeindex = pindex;
h->entrycount = 0;
h->hashfn = hashf;
h->eqfn = eqf;
h->loadlimit = (unsigned int) ceil(size * max_load_factor);
return h;
}
We can find that "creat_hashtable" is initialing some data.
unsigned int hash(struct hashtable *h, void *k)
{
/* Aim to protect against poor hash functions by adding logic here
* - logic taken from java 1.4 hashtable source */
unsigned int i = h->hashfn(k);
i += ~(i << 9);
i ^= ((i >> 14) | (i <<>>> */
i += (i << 4);
i ^= ((i >> 10) | (i <<>>> */
return i;
}
I have not understood hash(struct hashtable,void *);
25 件のコメント:
I precisely desired to thank you very much again. I'm not certain the things that I might have carried out without the ideas revealed by you on such a situation. It has been the fearsome setting in my position, however , taking a look at your expert manner you treated that made me to weep for contentment. I am happy for this work and believe you recognize what a great job you are always accomplishing teaching many people through your blog post. Most likely you have never come across any of us.
Feel free to visit my web-site - blake griffin shoes
My spouse and i felt lucky when Louis could conclude his inquiry through the
ideas he obtained out of the blog. It is now and again
perplexing to just possibly be offering instructions that many a number of
people have been making money from. And now we realize we now have
you to give thanks to because of that. The type of
explanations you've made, the straightforward site navigation, the friendships you make it possible to create - it's got all
terrific, and it is helping our son and the family believe that that subject is entertaining, and that is wonderfully fundamental.
Thank you for everything!
Look at my webpage: nike hyperdunk
I precisely wanted to say thanks yet again. I do not know what I might have carried out without those points revealed by you concerning my industry.
Previously it was the alarming matter for me, but encountering the
very specialised manner you treated it made me to
weep over delight. I will be grateful for the advice as well as wish you
know what an amazing job you happen to be undertaking training the others all through your website.
I am sure you've never got to know all of us.
Feel free to visit my site - michael kors watch sale
I'm still learning from you, but I'm trying to reach my goals.
I certainly enjoy reading all that is written on
your site.Keep the aarticles coming. I loved it!
Feel free to surf to my webpage: red bottom shoes
Hey there would you mind stating which blog platform you're working with? I'm looking
to start my own blog in the near future but I'm having a tough time deciding between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your layout seems different then most blogs and I'm looking for something
completely unique. P.S Apologies for
getting off-topic but I had to ask!
Check out my web-site: michael kors tote bag
excellent publish, very informative. I'm wondering why the opposite specialists of this sector do not notice this. You must continue your writing. I am sure, you've a great readers' base already!
Feel free to surf to my web blog ... michael kors mens watches
Most of what you say is astonishingly accurate and
that makes me ponder the reason why I had not looked
at this in this light previously. This particular article really did switch
the light on for me personally as far as this specific topic goes.
But there is actually just one factor I am not really too comfortable with and while I
attempt to reconcile that with the actual main idea of your point, allow
me see just what the rest of your visitors have
to say.Well done.
Also visit my homepage ... kobe bryant shoes
Excellent goods from you, man. I have remember your stuff previous to and you are
simply extremely magnificent. I really like what you've got right here, really like what you're stating and the way during which you assert it.
You are making it entertaining and you continue to
take care of to stay it sensible. I can't wait to learn far more from you. That is actually a wonderful web site.
my weblog :: michael kors outlet locations
Aw, this was a really nice post. In idea I would like to
put in writing like this additionally � taking time and actual effort to make a very good article�
but what can I say� I procrastinate alot and certainly not seem to get one thing done.
Also visit my webpage rose gold michael kors watch
Fantastic blog! Do you have any hints for aspiring writers?
I'm planning to start my own blog soon but I'm a little lost on everything.
Would you recommend starting with a free platform like Wordpress or go for a
paid option? There are so many options out there that
I'm totally overwhelmed .. Any recommendations? Thanks!
Stop by my blog post; adidas pro model
I am curious to find out what blog platform you
have been using? I'm experiencing some small security problems with my latest site and I would like to find something more safeguarded. Do you have any suggestions?
Also visit my weblog; michael kors women's mk5161
I simply wanted to construct a brief comment to
be able to say thanks to you for these remarkable guides you
are giving at this website. My time intensive internet look up has at the end of the
day been recognized with high-quality facts to write about with my neighbours.
I would point out that we website visitors actually
are truly fortunate to live in a very good network
with many marvellous professionals with valuable solutions.
I feel very much blessed to have seen the web site and look forward
to so many more amazing moments reading here. Thanks once more for
a lot of things.
Also visit my web site: michael kors mens watch sale
Well I really liked reading it. This information
provided by you is very constructive for proper planning.
Feel free to visit my homepage ... jordans 2013
Heya i�m for the first time here. I came across this board and I in finding It truly helpful & it helped
me out a lot. I hope to give one thing back and help others like
you helped me.
my site; nike free 2013
Oh my goodness! an amazing article dude. Thanks
Nevertheless I'm experiencing challenge with ur rss . Don�t know why Unable to subscribe to it. Is there anyone getting equivalent rss drawback? Anyone who knows kindly respond. Thnkx
Here is my web page; authentic retro jordans
A powerful share, I just given this onto a colleague who was doing a bit analysis on this.
And he in reality bought me breakfast as a result
of I discovered it for him.. smile. So let me reword that: Thnx for the treat!
But yeah Thnkx for spending the time to discuss this,
I feel strongly about it and love studying more on this topic.
If doable, as you turn out to be expertise, would you mind
updating your weblog with extra particulars?
It is highly useful for me. Huge thumb up for this weblog put up!
Feel free to surf to my web blog; shox nz
Have you ever considered publishing an ebook or guest authoring on other websites?
I have a blog based on the same ideas you discuss and would
love to have you share some stories/information. I know my subscribers would value your work.
If you're even remotely interested, feel free to send me an e-mail.
Feel free to surf to my web blog ... michael kors uk
Hey! This is my 1st comment here so I just wanted to give a quick
shout out and tell you I really enjoy reading through your blog
posts. Can you suggest any other blogs/websites/forums that cover the same topics?
Thank you!
Feel free to surf to my site - lebron james shoes
It is really a great and helpful piece of information.
I�m glad that you shared this helpful information with us.
Please keep us informed like this. Thank you for sharing.
Also visit my weblog :: adidas f50
I love your blog.. very nice colors & theme. Did
you create this website yourself or did you hire someone
to do it for you? Plz respond as I'm looking to design my own blog and would like to know where u got this from. many thanks
Review my web page: jordan 7 bordeaux
Aw, this was a really nice post. In idea I would like to put in writing like this additionally � taking time and precise effort
to make an excellent article� but what can I say� I procrastinate alot and
under no circumstances seem to get one thing done.
Feel free to visit my site: authentic jordans
I'm also commenting to let you be aware of of the superb discovery our child undergone browsing your webblog. She noticed a wide variety of details, including what it is like to have a wonderful giving heart to have certain people smoothly master several grueling subject matter. You really did more than her expectations. I appreciate you for coming up with those good, trustworthy, informative and in addition fun thoughts on this topic to Janet.
Also visit my blog post jordan bred 11
Hello, i think that i saw you visited my website thus i
came to �go back the prefer�.I am attempting to to find things to enhance my site!
I assume its ok to make use of a few of your concepts!!
Stop by my weblog; michael kors uk
Nice post. I was checking continuously this weblog
and I'm impressed! Very useful information particularly the remaining phase :) I handle such info a lot. I was seeking this particular information for a long time. Thank you and good luck.
my site jordan 4 bred
I�ve learn a few good stuff here. Definitely value bookmarking for revisiting.
I wonder how so much attempt you set to make one of these excellent informative site.
Here is my homepage:
コメントを投稿