The Daily WTF: Curious Perversions in Information Technology
Welcome to TDWTF Forums Sign in | Join | Help
in Search

a short thread, a big wtf

Last post 05-24-2008 5:47 AM by derula. 21 replies.
Page 1 of 1 (22 items)
Sort Posts: Previous Next
  • 05-21-2008 1:02 PM

    a short thread, a big wtf

     another great thread from java forums:

     

    http://forum.java.sun.com/thread.jspa?threadID=5297974&tstart=0 

     

    someone asks a question that doesnt make sense, and 10 people give wrong answers. yey! 

  • 05-21-2008 1:27 PM In reply to

    • stinch
    • Top 500 Contributor
    • 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?
  • 05-21-2008 1:31 PM In reply to

    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...

  • 05-21-2008 1:42 PM In reply to

    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.

  • 05-21-2008 1:44 PM In reply to

    • Zecc
    • Top 50 Contributor
    • 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'
  • 05-21-2008 2:37 PM In reply to

    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!
  • 05-21-2008 3:20 PM In reply to

    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.

  • 05-21-2008 3:25 PM In reply to

    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
  • 05-21-2008 4:14 PM In reply to

    • derula
    • Top 25 Contributor
    • 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.
  • 05-21-2008 4:38 PM In reply to

    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. 

  • 05-21-2008 4:46 PM In reply to

    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...

  • 05-21-2008 6:29 PM In reply to

    • fbjon
    • Top 500 Contributor
    • 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.
  • 05-21-2008 9:00 PM In reply to

    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.

  • 05-21-2008 9:55 PM In reply to

    • fbjon
    • Top 500 Contributor
    • 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.
  • 05-21-2008 10:32 PM In reply to

    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); 
    }

     

  • 05-22-2008 6:22 AM In reply to

    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).

     

  • 05-23-2008 1:43 AM In reply to

    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)

  • 05-23-2008 11:34 AM In reply to

    • DOA
    • Top 25 Contributor
    • 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?

  • 05-23-2008 1:27 PM In reply to

    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
  • 05-23-2008 1:35 PM In reply to

    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!

  • 05-24-2008 5:23 AM In reply to

    Re: a short thread, a big wtf

    belgariontheking:

    Perhaps we could just ask Morbii though.

     

    It's actually the Norwegian metal band Immortal.  It's the cover of their album "Blizzard Beasts".

     

    http://www.youtube.com/watch?v=3GmNBeG4fiE

  • 05-24-2008 5:47 AM In reply to

    • derula
    • Top 25 Contributor
    • 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)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems