Hashmap array

  • (2 Pages)
  • +
  • 1
  • 2

27 Replies - 764 Views - Last Post: 26 April 2013 - 12:50 PM Rate Topic: -----

#1 iburres  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 05-September 12

Hashmap array

Posted 25 April 2013 - 02:41 PM

Under the following table, does the first number in the hashcode represent the index location, or should I find the index using the key(Patriots, etc.)% arraySize?

Item Hashcode
Patriots 1342415383
Steelers 700056533
Chargers 330628742
Texans 532139483
Packers 217142585
49ers 2112979549
Saints 207265348
Giants 1631149803

This post has been edited by iburres: 25 April 2013 - 03:45 PM

Is This A Good Question/Topic? 0
  • +

Replies To: Hashmap array

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Hashmap array

Posted 25 April 2013 - 04:31 PM

no have nothing to do...
Actually you should have notice that you have few hashcode with the same starting first 2 numbers like 21 :)
Was This Post Helpful? 0
  • +
  • -

#3 iburres  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 05-September 12

Re: Hashmap array

Posted 25 April 2013 - 06:07 PM

I did, which is what was throwing me off. I took the modulus of each hash code and found the index for each. I then created a separate chaining diagram, with the Chargers at index 2, Saints at 4, Texans at 5 with a chain to 49ers, Steelers at 7, and Patriots to Packers to Giants at 10. Is that right, or am I way off?
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Hashmap array

Posted 25 April 2013 - 07:18 PM

What the hell are you trying to do ?
Based on your previous posts, I can tell that you always over and over complicate simple things
Was This Post Helpful? 0
  • +
  • -

#5 iburres  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 05-September 12

Re: Hashmap array

Posted 25 April 2013 - 08:02 PM

Lol. I'm trying to map the teams to their appropriate cells in an array. There are 8 teams with their respective hash codes. That was all I was given. One array uses separate chaining and the other uses quadratic probing to avoid collisions. I had no idea how to determine the index for each team until I decided to divide each hash code value by the arraySize (which is 13) in this case. The modulus os the array index, i believe. The threshold is .75, but I dont think either array will have to be resized with only 8 items. Is that the right way to do it?
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Hashmap array

Posted 25 April 2013 - 08:07 PM

You try to do that for fun because you are masochist or it is a school assigment by a paranoiac teacher ?
Was This Post Helpful? 0
  • +
  • -

#7 iburres  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 05-September 12

Re: Hashmap array

Posted 25 April 2013 - 09:10 PM

View Postpbl, on 26 April 2013 - 03:07 AM, said:

You try to do that for fun because you are masochist or it is a school assigment by a paranoiac teacher ?


Its a school assignment

This post has been edited by iburres: 25 April 2013 - 09:13 PM

Was This Post Helpful? 0
  • +
  • -

#8 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7744
  • View blog
  • Posts: 13,083
  • Joined: 19-March 11

Re: Hashmap array

Posted 26 April 2013 - 05:28 AM

What was the actual assignment?
Was This Post Helpful? 0
  • +
  • -

#9 iburres  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 05-September 12

Re: Hashmap array

Posted 26 April 2013 - 06:35 AM

To show the locations of each team in a hash map array using a load factor of .75. The first problem uses separate chaining to avoid collisions. The second used quadratic probing to
avoid collisions. I created two diagrams showing the arrays and their respective locations, and I calculated the indexes based on modular division, wherein I divided the hashcode values by the array size, which was initialized at 13 in the assignment. Just wanted to know if that was the proper way to determine the index locations.

This post has been edited by iburres: 26 April 2013 - 06:36 AM

Was This Post Helpful? 0
  • +
  • -

#10 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2720
  • View blog
  • Posts: 11,433
  • Joined: 20-September 08

Re: Hashmap array

Posted 26 April 2013 - 06:56 AM

Quote

does the first number in the hashcode represent the index location
You mean the first digit? If so, why should it?
Was This Post Helpful? 0
  • +
  • -

#11 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2113
  • View blog
  • Posts: 3,235
  • Joined: 21-June 11

Re: Hashmap array

Posted 26 April 2013 - 06:58 AM

View Postiburres, on 26 April 2013 - 03:35 PM, said:

Just wanted to know if that was the proper way to determine the index locations.


Yes, hashCode % arraySize is the correct way to determine the index for an entry in a hash map.
Was This Post Helpful? 0
  • +
  • -

#12 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2720
  • View blog
  • Posts: 11,433
  • Joined: 20-September 08

Re: Hashmap array

Posted 26 April 2013 - 07:13 AM

I'm unclear as to where this 'array' is coming from. The generic answer is that the bucket containing the value is given normally by

hashCode % numberOfBuckets

Of course, you could use an array, but then it's what kind of array? It will need to be able to deal with three collisions in the values given with 13 buckets

This post has been edited by g00se: 26 April 2013 - 07:14 AM

Was This Post Helpful? 0
  • +
  • -

#13 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2113
  • View blog
  • Posts: 3,235
  • Joined: 21-June 11

Re: Hashmap array

Posted 26 April 2013 - 07:24 AM

View Postg00se, on 26 April 2013 - 04:13 PM, said:

Of course, you could use an array, but then it's what kind of array?


Pardon my ignorance, but what else would you use if not an array?
Was This Post Helpful? 0
  • +
  • -

#14 iburres  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 05-September 12

Re: Hashmap array

Posted 26 April 2013 - 07:35 AM

Bucket yes, but that's really just an abstraction for an array. Thanks guys. Hashcode % array size is the correct way, so I'm good. I appreciate it
Was This Post Helpful? 0
  • +
  • -

#15 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2720
  • View blog
  • Posts: 11,433
  • Joined: 20-September 08

Re: Hashmap array

Posted 26 April 2013 - 07:49 AM

Quote

Pardon my ignorance, but what else would you use if not an array?
A List?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2