Google Answers Logo
View Question
 
Q: dogbite-ga: Modification of hashing program. ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: dogbite-ga: Modification of hashing program.
Category: Computers > Programming
Asked by: lighthousedweller-ga
List Price: $7.00
Posted: 04 May 2003 14:19 PDT
Expires: 03 Jun 2003 14:19 PDT
Question ID: 199323
Hi again-

I would like help modifying the program to work with strings instead
of ints. Here is a sample input file that I would like it to work
with.
apple:a fruit to eat
bat:a weapon, or a flying mammal
and so on
I realize I should have been more specific now in the intial post.
Also please use strings intead of chars and C++ syntax where
applicable.

Thanks alot for the help.

Request for Question Clarification by dogbite-ga on 04 May 2003 15:40 PDT
Hi lighthousedweller-ga,

  Sure, I will answer this tonight.

       dogbite-ga
Answer  
Subject: Re: dogbite-ga: Modification of hashing program.
Answered By: dogbite-ga on 04 May 2003 18:32 PDT
Rated:5 out of 5 stars
 
Hi lighthousedweller-ga,

  Okay, the modified program is here:

http://nms.lcs.mit.edu/~gch/google/hashtablestr.tar.gz

  Let me know how it works for you.

         dogbite-ga

Request for Answer Clarification by lighthousedweller-ga on 04 May 2003 19:34 PDT
OK great thanks a bunch. It works great.

While I have you though I have two questions.

1) oneWord.definition =
oneline.substr(colonindex+1,oneline.length()-colonindex+1); is a part
in the program which finds the defintion.  I can't figure out how this
is working though. because the definitions and words sometimes
overlap. like "...fruit to eatbat:a weapon..." how does the program
know to stop after eat for the definition and that bat is a new word?

2) what does labs(hc); do?

3) and just my last question is this and any hashing program relies on
the idea that the keyword you're using to hash is unique, right?

thanks again for your help and quick response yet again.

Request for Answer Clarification by lighthousedweller-ga on 04 May 2003 19:34 PDT
Make that three questions, ;)

Clarification of Answer by dogbite-ga on 04 May 2003 20:01 PDT
Hey lighthousedweller-ga,

  Sure, I can answer your questions
  (all three) :-)

1) oneWord.definition =
oneline.substr(colonindex+1,oneline.length()-colonindex+1); is a part
in the program which finds the defintion.  I can't figure out how this
is working though. because the definitions and words sometimes
overlap. like "...fruit to eatbat:a weapon..." how does the program
know to stop after eat for the definition and that bat is a new word?
 
   What do you mean that words and definitions
   sometimes overlap?  Are you saying the program
   isn't working?

   Otherwise, the substr() command returns all of
   the text on the line after the first colon.

2) what does labs(hc); do? 

   It just takes the absolute value of hc, which
   is a long, hence the 'l. 

3) and just my last question is this and any hashing program relies on
the idea that the keyword you're using to hash is unique, right?
 
   Yes, every key (here, word) has to be unique.

thanks again for your help and quick response yet again.

             dogbite-ga

Request for Answer Clarification by lighthousedweller-ga on 04 May 2003 20:40 PDT
Thanks again.

In regards to question one, no the program is working perfectly fine.
You kinda answered my question with: "substr() command returns all of
the text on the line after the first colon."

Because when I was opening the data file in notepad on windows, it was
showing up as all on one line. So i was wondering would substr know to
split the definition and word it up if it was all on one line. But I
opened it with a different text editor, and they appeared on different
lines, as they would have to for this to work. So this makes sense
now.

Last thing, I'm pretty sure about this, but just want to make sure.
The part where you hash the string, you are just trying to convert it
to a random number which you'll then % by another number and use to
put in the hash table. Right?

Thanks for all the help!

Clarification of Answer by dogbite-ga on 04 May 2003 21:11 PDT
Hey lighthousedweller-ga,

  Yes, the hashCode function converts
  the string to a number.  The number
  isn't "random" (that has a strong
  mathematical meaning to me) -- it is 
  a rough binary representation of the 
  string.  But yes, the choice of function 
  is somewhat arbitrary.  

  Then we take the module of that number
  so it fits in our table.

  I'm glad the program is working for you.

                dogbite-ga
lighthousedweller-ga rated this answer:5 out of 5 stars
Thanks for your help, you really helped me understand everything.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy