Giter Site home page Giter Site logo

Comments (12)

GoogleCodeExporter avatar GoogleCodeExporter commented on August 27, 2024
Interesting. I'm not sure which I'd expect, and I'm not sure what would happen 
in the equivalent situation in Java or C#. Do you happen to know? (I will try 
it later when I have a little more time).

Original comment by [email protected] on 17 Oct 2010 at 4:38

from jshashtable.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 27, 2024
No, don't know how other implementations deal with this. From the perspective 
of HashTable I wouldn't know what to expect either. But from the perspective of 
a HashSet I'd expect keys to be updated/overwritten, as they are not keys in 
that scenario, but values.

Original comment by [email protected] on 17 Oct 2010 at 4:42

from jshashtable.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 27, 2024
I've thought about this and decided that I prefer the current behaviour. Your 
example fundamentally defines o1 and o2 as being equal in terms of the set so 
are essentially interchangeable. If you do actually need to distinguish between 
o1 and o2 then you need to rewrite your equality function to do that.

For what it's worth, C#'s HashSet implementation does the same thing.

Original comment by [email protected] on 18 Oct 2010 at 8:03

  • Changed state: WontFix

from jshashtable.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 27, 2024
Ok, understand your reasons.

But the implication is that there is no way of obtaining a particular value 
from the set, apart from cluelessly iterating over them all. Wouldn't it be an 
idea to offer a means of doing just that?

Original comment by [email protected] on 18 Oct 2010 at 8:29

from jshashtable.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 27, 2024
What's happening in your example is that o2 is never being added to the set 
because it thinks it's already in there (since it's equal to o1). There's only 
one element in the set.

Original comment by [email protected] on 18 Oct 2010 at 9:12

from jshashtable.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 27, 2024
Yes I understand that. My point is that o1 is out of reach as soon as it is in 
the set. Your only option is to remove it, but the object will be lost (and 
garbage collected) because no reference to it is returned.

Original comment by [email protected] on 18 Oct 2010 at 9:25

from jshashtable.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 27, 2024
OK, sorry. So your problem is that you can't tell without iterating over the 
set whether o1 or o2 is in it. So if the actual object identity is important, 
why have you defined the equality function not to distinguish between different 
object with the same id property?

Original comment by [email protected] on 18 Oct 2010 at 9:46

from jshashtable.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 27, 2024
My use case:

STORE = new Hashset();
var p1 = new Person();
p1.setData({id: 1, name: "Tim"});  // this data might come from server
STORE.add(p1);

// and then in another part of the application:
var p2 = new Person();
p2.setData({id: 1, name: "Tim Molendijk"});  // this data might come from a web 
form
if (STORE.contains(p2)) {
  var p = STORE.get(p2);  // this is currently not possible
  p.setData(p2.getData());
} else {
  STORE.add(p2);
}

Original comment by [email protected] on 18 Oct 2010 at 10:09

from jshashtable.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 27, 2024
OK, I see what you're getting at. Thanks for the example. Couldn't you instead 
use a Hashtable keyed by id?

Original comment by [email protected] on 19 Oct 2010 at 11:50

from jshashtable.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 27, 2024
Yeah I'm using Hashtable instead. No problem. Just thought I'd share it because 
I'm basically using it as a set data structure. Which is what the HashSet 
wrapper was created for I suppose.

Anyway, thanks a lot.

Original comment by [email protected] on 19 Oct 2010 at 11:58

from jshashtable.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 27, 2024
I've had a change of heart on this. Issue 5 is a duplicate and I've decided to 
add an option to enable duplicate key replacement in the next version.

Original comment by [email protected] on 15 Jul 2013 at 11:19

  • Changed state: Accepted

from jshashtable.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 27, 2024

Original comment by [email protected] on 15 Jul 2013 at 11:19

  • Changed state: Duplicate

from jshashtable.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.