how to go to specific row in hashtable based on value - not key?

G

Guest

Hello,

I populate a hashtable with recordID's in a "For i=0 to n" loop. Some
recordID's are duplicate but for different rows (recordID is not a key field
in this scenario). I use the value of "i" in the For loop as the key in the
hashtable (which is actually the currencyManager counter).

Originally, I was using the recordID as the key and "i" as the value. So if
I user needed to go to recordID = 12345, I just retrieve the corresponding
value for that key and make currencyManager go to that value. But since I
now have duplicate RecordID's I can't use that as the key. So I switched it
around where the value of "i" is now the key and the RecordID is the value.

I experimented with the DictionaryEntry object to retrieve the key based on
a value, but I have to loop through the entire hashtable to locate the
desired DictionaryEntry. Is there a way to go to the desired row in the
Hashtable without having to loop?

Thanks,
Rich
 
H

housebuyer

I'm not sure what you're trying to accomplish. It sounds like you've
created a "hashtable" which behaves just like a standard table -- the
hash key is a sequential value, which could just as well be the index
of a simple table.

I don't know what you're trying to retrieve, or why, but assuming you'd
like to get all your RecordIDs, I'd suggest adding a sequential
collision resolver to each record ID, and make the combined field the
key to your hash table. The first record you add with a given RecordID
has a hash key of "RecordID" + "000". Each time you attempt to add a
new record, you check to see if RecordIDnnn exists; if it does, you
increment nnn and check again, until you get a slot. Retrieval is
similarly simple; start with RecordID000, and keep looking until you
get a not found.

Of course, this won't work if you're going to be randomly deleting
records, but it's my best (and only) attempt at trying to understand
what you want to accomplish and suggesting a solution. Good luck.
 
C

creator_bob

How about using an arraylist in your hash table. Everytime you add an
item, if there is something there already, add it to your list.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top