Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Hashtable with two keys?  RSS feed

 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there somthing like a hashtable but supports two keys? I want to be able to grab the frequency of a note by either a String with the name of the note or the midi representation.

Thanks for atleast reading this,
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. But you could create a Note object which overrides equals() etc. so you can test for equality based on the notes name or its midi representation. (and you probaby want to use a HashMap). Does that make sense?
 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the help
 
Rick O'Shay
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Danger Will Robinson. You must override hashCode any time you override equals. If an object is equal the hash codes must also be equal. Ignore at your peril.

I would just create two maps because you have, in fact, two maps. You could wrap them in a lookup class.
 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good thinking... thanks!
 
Rick O'Shay
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome
[ September 15, 2005: Message edited by: Rick O'Shay ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or if the two key forms can never collide, put em in one map.

map.put( note.getName(), note );
map.put( note.getMIDINoteNumber(), note );

BTW: how's that MIDI stuff going? I ought to get back into that some day. I did a couple neat DOS programs in Pascal to manipulate MIDI messages in real time. Always thought I should do them again in Windows.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!