Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 05-04-2005, 01:03 PM   #1 (permalink)
xangel31x
Registered User
 
Join Date: May 2005
Posts: 4
xangel31x is on a distinguished road
hashing

i am stuck on my program. i have to make a hash table and enter the data from the list of into the table. i have amount of data that i need and the loadfactor(the number of slots) i just don't know how to go about actually creating the initTable. it is suppose to initialize the hash table size. i am confused and hope that some one understands what i am trying to say. thanks in advance.
xangel31x is offline   Reply With Quote
Old 05-04-2005, 05:05 PM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,166
Belisarius is on a distinguished road
I'm not quite following what the problem is . . . you don't know how to create the underlying data structure for the hash table? Or is it something else?
__________________
GitS
Belisarius is offline   Reply With Quote
Old 05-05-2005, 03:34 PM   #3 (permalink)
xangel31x
Registered User
 
Join Date: May 2005
Posts: 4
xangel31x is on a distinguished road
yes i don't know how to create the actual table to then insert the data into it.
xangel31x is offline   Reply With Quote
Old 05-05-2005, 04:58 PM   #4 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,166
Belisarius is on a distinguished road
It's not actually a table, but rather an array. The hash() method returns a suitably random number (but will always return the same number for the same value). The position in the array is that hash value. As a result, in an infinitely large hash table, there is no searching for values, you just go to it's position and retrieve it. Of course, no hash table is of infinite size, so the question becomes "what if the hash value is outside the length of the array"? You use a modulus operator to loop back around and start from the beginning.

Say you have a hash table of size "10", but your Object has a hash value of "11" - where does it get inserted? At position "1", because 11 % 10 = 1.

Now, what if that spot is already occupied? That is known as a collision. There are a number of different ways of dealing with it, but the simplest is to merely move down the array until you find an empty spot. When someone wants to look up an object in the hash table, you look at what's contained at the spot that it hashes to. If it doesn't match the key of the object you're looking for, continue down the array until you either find it or loop. It's not terribly efficient in the case of collisions, but it's easy to code and I assume that's what you're looking for right now.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 05-05-2005, 07:01 PM   #5 (permalink)
xangel31x
Registered User
 
Join Date: May 2005
Posts: 4
xangel31x is on a distinguished road
thanks for all the information but i already knew that. i have to create a initTable and that sets the table size and puts all the strings to empty and i am not really sure what to do for that. i really lost on this lab.
xangel31x is offline   Reply With Quote
Old 05-06-2005, 02:54 AM   #6 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,166
Belisarius is on a distinguished road
Are you talking about initializing the array?
__________________
GitS
Belisarius is offline   Reply With Quote
Old 05-06-2005, 05:25 AM   #7 (permalink)
xangel31x
Registered User
 
Join Date: May 2005
Posts: 4
xangel31x is on a distinguished road
yes
xangel31x is offline   Reply With Quote
Old 05-06-2005, 09:39 AM   #8 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,166
Belisarius is on a distinguished road
Object[] array = new Object[initSize];
__________________
GitS
Belisarius is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hashing problem jodders Standard C, C++ 1 02-09-2005 01:51 PM
hashing help saiz66 Standard C, C++ 2 06-28-2004 01:39 AM


All times are GMT -8. The time now is 05:50 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting