Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
java hashtables: find a key for a value

 
Post new topic   Reply to topic Printable version
 View previous topic  MGB's Avatar Post :: Post PhpBB  View next topic  
Author Message
Helicon
Server Help Squatter


Joined: Dec 03 2002
Posts: 771
Location: GNU Doldrums
Offline

PostPosted: Sat Nov 08, 2003 11:10 pm   Post maybe stupid    Post subject: java hashtables: find a key for a value Reply to topic Reply with quote

alright.. i've done java for years but have yet to see a good solution for this one:

i have a java.util.Hashtable with a value added to it
Code: Show/Hide
Hashtable h = new Hashtable();
Vector vect = new Vector();
h.put("Main",v);

What i need to do is dynamically retrieve "Main" given vect.
here is the javadoc for Hastable (JDK 1.4.2)
http://java.sun.com/j2se/1.3/docs/api/java/util/Hashtable.html
i can obviously use:
Code: Show/Hide
Enumeration e = h.keys();
while(h.hasMoreElements()){
//... iterate, checking to see if this works:
String temp = (String)e.nextElement();
if(h.get(temp)!=null)
return temp;
}

but that is rediculous...
Am i missing something obvious????
_________________
Signatures just seem so quaint.
Back to top
View users profile Send private message Add User to Ignore List
Dr Brain
Flip-flopping like a wind surfer


Age:39
Gender:Gender:Male
Joined: Dec 01 2002
Posts: 3502
Location: Hyperspace
Offline

PostPosted: Sun Nov 09, 2003 12:10 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

Not really.

You could of course have two hashmaps/hashtables and use the keys of one as the objects of another.

Why do you need to do this?
_________________
Hyperspace Owner

Smong> so long as 99% deaths feel lame it will always be hyperspace to me
Back to top
View users profile Send private message Add User to Ignore List AIM Address Yahoo Messenger MSN Messenger
Helicon
Server Help Squatter


Joined: Dec 03 2002
Posts: 771
Location: GNU Doldrums
Offline

PostPosted: Sun Nov 09, 2003 3:51 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Dr Brain wrote:
Why do you need to do this?

i'm not a moron... i know when i need to use a hashtable.
The trouble here is that somewhere down the hierarchy there are vectors(hence arrays) containing the keys which yield the hashes and the objects themselves. It would be simple, given these, to just match up indices and return either. However, i don't feel like extending my way down the hierarchy to accomplish this. It just seems like having to iterate twice to find objects which reside at the same index is a little screwy... perhaps i'm wrong about the indices... it may be by hash, but that would be just a small drag compared to an iteration... my collections don't have defined limits in this case... that would severely bite my already lagging java performance
Back to top
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Sun Nov 09, 2003 3:54 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Asking you what for doesn't necessarily mean you're a moron. There's just more efficient ways of doing things depending on what you need them for...
_________________
This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Helicon
Server Help Squatter


Joined: Dec 03 2002
Posts: 771
Location: GNU Doldrums
Offline

PostPosted: Sun Nov 09, 2003 3:56 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Cyan~Fire wrote:
There's just more efficient ways of doing things depending on what you need them for...

like not using java, tee hee
Back to top
View users profile Send private message Add User to Ignore List
Dr Brain
Flip-flopping like a wind surfer


Age:39
Gender:Gender:Male
Joined: Dec 01 2002
Posts: 3502
Location: Hyperspace
Offline

PostPosted: Sun Nov 09, 2003 8:44 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Helicon wrote:
i'm not a moron... i know when i need to use a hashtable.
The trouble here is that somewhere down the hierarchy there are vectors(hence arrays) containing the keys which yield the hashes and the objects themselves. It would be simple, given these, to just match up indices and return either. However, i don't feel like extending my way down the hierarchy to accomplish this. It just seems like having to iterate twice to find objects which reside at the same index is a little screwy... perhaps i'm wrong about the indices... it may be by hash, but that would be just a small drag compared to an iteration... my collections don't have defined limits in this case... that would severely bite my already lagging java performance


I didn't say you were a moron, but usually there is a better way to do something when you are having trouble with a build in class.

I beleive that they arent stored in vectors, but rather in a linked list type thing, and a hash is used to position data in it.

If performance is a big deal, make your own. If its not, use two hash tables.
Back to top
View users profile Send private message Add User to Ignore List AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Trash Talk All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 34 page(s) served in previous 5 minutes.

phpBB Created this page in 0.809443 seconds : 28 queries executed (93.0%): GZIP compression disabled