|
a short thread, a big wtf
Last post 05-24-2008 5:47 AM by derula. 21 replies.
-
05-21-2008 1:02 PM
|
|
-
-
stinch


- Joined on 09-28-2005
- Oxford, Uk
- Posts 54
|
Re: a short thread, a big wtf
I have a hashtable in which some of the values are exactly the same. I want to remove the duplicates so that for one value there is only one copy in the hashtable.
How does that not make sense?
|
|
-
-
merreborn


- Joined on 12-30-2005
- Posts 611
|
Re: a short thread, a big wtf
stinch:I have a hashtable in which some of the values are exactly the same. I want to remove the duplicates so that for one value there is only one copy in the hashtable.
How does that not make sense?
Makes sense, but it sounds like a hash table is probably the wrong data structure to use here...
|
|
-
-
morbiuswilters


- Joined on 01-15-2008
- East Coast Represent!
- Posts 4,982
|
Re: a short thread, a big wtf
merreborn:Makes sense, but it sounds like a hash table is probably the wrong data structure to use here...
Why is it the wrong data structure? It just sounds like he needs a bi-directional hashtable.
|
|
-
-
Zecc


- Joined on 06-12-2007
- Location, Location, Location
- Posts 653
|
Re: a short thread, a big wtf
JosAH:
That is nonsense.
kind regards,
Jos
I love how they start acting all superior and then later have to swallow their pride.
If mixed metaphors were illegal, I'd be having an indigestion. typeof NaN == 'number'
|
|
-
-
KattMan


- Joined on 10-18-2006
- Posts 421
|
Re: a short thread, a big wtf
Zecc:
JosAH: That is nonsense.
kind regards,
Jos
I love how they start acting all superior and then later have to swallow their pride.
Lyle wouldn't have to swallow his pride because of course he would be right.
CAPTCHA? We ain't got no CAPTCHA. We don't need no CAPTCHA. We don't need no stinking CAPTCHA!
|
|
-
-
JamesKilton


- Joined on 12-07-2006
- Posts 101
|
Re: a short thread, a big wtf
Ouch, wow. None of them actually read the OP. What I read was duplicate*values*, not *keys*, of which everyone else was assuming he meant. Having duplicate values in a hash table is perfectly valid, though yeah there are probably better structures out for what he's doing. Who in their right mind reads the java forums anyway? It's so much cesspool it's depressing.
|
|
-
-
DZ-Jay


- Joined on 05-03-2005
- Posts 336
|
Re: a short thread, a big wtf
The question makes sense, and at least 2 answers are right, too. The original post asked how to remove duplicate values from a Hashtable. The Hashtable can most certainly contain duplicate values. All those who remarked that the question was wrong were confusing "values" with "keys". Keys must be unique, but values not necessarily. dZ.
Bastard Operators don't just win. Anyone can win. Bastard Operators win and totally demoralise. That's real winning.
- BOfH
|
|
-
-
derula


- Joined on 06-15-2007
- Germany
- Posts 862
|
Re: a short thread, a big wtf
DZ-Jay:The question makes sense, and at least 2 answers are right, too. The original post asked how to remove duplicate values from a Hashtable.
JosAH:It still doesn't make any sense: for a map like this: (A, X) (B, X) after removing the duplicate value what should the result be: (A, X) or (B, X)?
I agree with JosAH here.
You can now help me balance the tag cloud.
|
|
-
-
morbiuswilters


- Joined on 01-15-2008
- East Coast Represent!
- Posts 4,982
|
Re: a short thread, a big wtf
derula: DZ-Jay:The question makes sense, and at least 2 answers are right, too. The original post asked how to remove duplicate values from a Hashtable.
JosAH:It still doesn't make any sense: for a map like this: (A, X) (B, X) after removing the duplicate value what should the result be: (A, X) or (B, X)?
I agree with JosAH here.
One would presume the latest entry would overwrite the previous one, just like a hashtable does with identical keys.
|
|
-
-
MasterPlanSoftware


- Joined on 11-10-2006
- Posts 108
|
Re: a short thread, a big wtf
morbiuswilters:One would presume the latest entry would overwrite the previous one, just like a hashtable does with identical keys. That would appear to be the obvious solution, unless you are the type of person to sit around all day and not do anything because the specs/boss didn't hold your hand...
|
|
-
-
fbjon


- Joined on 07-04-2007
- Posts 66
|
Re: a short thread, a big wtf
AFAIunderstand, the structure he wants is two sets with bijection. Not completely trivial, actually.
|
|
-
-
Morbii


- Joined on 10-21-2006
- Posts 121
|
Re: a short thread, a big wtf
fbjon:AFAIunderstand, the structure he wants is two sets with bijection. Not completely trivial, actually.
Simply using two hashtables sounds pretty trivial to me.
|
|
-
-
fbjon


- Joined on 07-04-2007
- Posts 66
|
Re: a short thread, a big wtf
Morbii: fbjon:AFAIunderstand, the structure he wants is two sets with bijection. Not completely trivial, actually.
Simply using two hashtables sounds pretty trivial to me.
You still need to map between them.
|
|
-
-
Morbii


- Joined on 10-21-2006
- Posts 121
|
Re: a short thread, a big wtf
fbjon:You still need to map between them.
And why is that difficult? Obviously you should make your own parent class, but I don't see where the problem lies. If your bi-directional hash table is meant to be 1:1 on keys and 1:1 on values, it's trivial.
For example, C# (that may or may not be broken) for your Set method might look something like this:
assuming member hashtables ktov (key to value) and vtok (value to key) void Set(object key, object value) { object currentValue, currentKey; if(ktov.Lookup(key, out currentValue)) vtok.Remove(currentValue); if(vtok.Lookup(value, out currentKey)) ktov.Remove(currentKey); ktov.Set(key, value); vtok.Set(value, key); }
|
|
-
-
Morbii


- Joined on 10-21-2006
- Posts 121
|
Re: a short thread, a big wtf
^^^
You'd also have to recurse and remove all key/value pairs that got removed due to the first removal as well (until there were no more collisions).
|
|
-
-
Morbii


- Joined on 10-21-2006
- Posts 121
|
Re: a short thread, a big wtf
Not sure if anyone noticed, but I believe this data structure would actually have to remove every element if a duplicate key came along that had a different value or vice versa :) (if you were to make sure that every key had a value that was in the value table and vice versa)
|
|
-
-
DOA


- Joined on 06-26-2007
- Posts 703
|
Re: a short thread, a big wtf
Ok, I've got to ask... can anyone make out wth it is that Morbii has as an avatar?
|
|
-
-
belgariontheking


- Joined on 08-20-2007
- Cincinnati, OH, USA
- Posts 2,276
|
Re: a short thread, a big wtf
DOA: Ok, I've got to ask... can anyone make out wth it is that Morbii has as an avatar?
I always figured it was either KISS or the Finnish metal band Lordi. Perhaps we could just ask Morbii though.
SpectateSwamp exposing aliens. Obviously the World needs SSDS
[10:07] <fatdog> so from now on.. be sure to wear nice clean underwear [10:07] <mps> fatdog: That is simply not going to happen
|
|
-
-
bstorer


- Joined on 02-01-2007
- Alexandria, VA
- Posts 3,402
|
Re: a short thread, a big wtf
belgariontheking: DOA: Ok, I've got to ask... can anyone make out wth it is that Morbii has as an avatar?
I always figured it was either KISS or the Finnish metal band Lordi.
Oh, a schooner!
|
|
-
-
-
derula


- Joined on 06-15-2007
- Germany
- Posts 862
|
Re: a short thread, a big wtf
Morbii: belgariontheking:Perhaps we could just ask Morbii though.
It's actually the Norwegian metal band Immortal.
That's close enough. belgariontheking had 4 correct letters, and three of them in the right order.
You can now help me balance the tag cloud.
|
|
Page 1 of 1 (22 items)
|
|
|