473,394 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Hash function

Osoascam
Hi there!
I have to do a B-tree, which can use strings or ints as keys. Anyway, keys can be repeated, and I have to use a has function in order to converto from string to int...

My teacher said he doesn't care about the function we use, and that he wouldn't care if we used an already done one. He even told us we didn't loose time in implementing one ourselves.

The thing is, I haven't find one... COuld you help me?
It just has to work, no need of it to be efficient.

THANKS!! :D :D
May 20 '07 #1
2 1557
JosAH
11,448 Expert 8TB
Hi there!
I have to do a B-tree, which can use strings or ints as keys. Anyway, keys can be repeated, and I have to use a has function in order to converto from string to int...

My teacher said he doesn't care about the function we use, and that he wouldn't care if we used an already done one. He even told us we didn't loose time in implementing one ourselves.

The thing is, I haven't find one... COuld you help me?
It just has to work, no need of it to be efficient.

THANKS!! :D :D
Good hash functions are written by alchemists, not computer scientists ;-)
It's a dark branch where creativity is badly needed. I prefer a simple hash
function that does fairly well. Have a look at this one (I assume C code):
Expand|Select|Wrap|Line Numbers
  1. int hashCode(char* c) {
  2.    int hash= 0;
  3.    if (!c) return 0;
  4.    for (; *c; c++)
  5.       hash= (hash<<1)^*c^((hash>>21)&0x3ff);
  6.    return hash;
  7. }
This function slowly rotates the 'hash' value while 'xoring' every character to it.
The 11 most significant bits are also 'xored' in therefore all characters are
significant in the resulting hash value.

kind regards,

Jos
May 20 '07 #2
Ok, thank you very much.
That's all I needed to start my B+-tree... That is, if I can do it ;-)
May 20 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Markus Dehmann | last post by:
I have a class "Data" and I store Data pointers in an STL set. But I have millions of inserts and many more lookups, and my profiler found that they cost a lot of runtime. Therefore, I want to...
2
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to...
4
by: flipdog | last post by:
Hello all, I didn't know there is a thread on hash function started in this newsgroup so reposted my posting from another group. Hope I can have some feedbacks. I am new to hash table. I came...
6
by: barcaroller | last post by:
I'm looking for a hash function (in C) that will convert a string of arbitrary length (but less than 1024 chars) to a reasonably-unique 16-bit short integer. Can anyone point me to such a hash...
6
by: thecodemachine | last post by:
Hi, I'm looking for a fast and simple one to one hash function, suitable for longer strings (up to 2048 in length). I'd like keys to be relatively short, I doubt I'd be creating more than 256...
12
by: Arash Partow | last post by:
Hi all, I've ported various hash functions to python if anyone is interested: def RSHash(key): a = 378551 b = 63689 hash = 0
21
by: Johan Tibell | last post by:
I would be grateful if someone had a minute or two to review my hash table implementation. It's not yet commented but hopefully it's short and idiomatic enough to be readable. Some of the code...
21
by: Hallvard B Furuseth | last post by:
Is the code below valid? Generally a value must be accessed through the same type it was stored as, but there is an exception for data stored through a character type. I'm not sure if that...
11
by: Douglas Dude | last post by:
how much time does it take to lok for a value - key in a hash_map ? Thanks
139
by: ravi | last post by:
Hi can anybody tell me that which ds will be best suited to implement a hash table in C/C++ thanx. in advanced
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.