I was thinking the same, create a __setUniqueId property per each set, add it per each added element to the set, and check if this.__setUniqueId in element is true.
This is way too dirty to me in any case, I preferred to do not pollute objects at all indeed with es6-collections shim ( https://github.com/WebReflection/es6-collections) It must be said I am not using there what Brendan suggested, the Object.is equivalent ... good catch ( however, I think the NaN and -0 cases are extremely edge ) br On Fri, Mar 30, 2012 at 9:44 AM, David Bruant <[email protected]> wrote: > Le 30/03/2012 07:17, Peter Michaux a écrit : > > I've worked on a generic Set polyfill. It is quite a simple task to >> build one but determining if an object is in the set is O(n) with the >> following "has" method. >> >> Set.prototype.has = function(element) { >> for (var i = 0, ilen = this._elements.length; i< ilen; i++) { >> if (element === this._elements[i]) { >> return true; >> } >> } >> return false; >> }; >> >> It seems like a long shot but is there some trick that someone has >> discovered that allows for a more efficient generic Set polyfill? >> > The issue here is that without native Set, the representations you have of > an object set requires to traverse it entirely the representation to find > something in it. This isn't true for sets of orderable things like strings > or numbers since orderable things could be ordered and found in O(log(n)). > But opaque things like objects can't be ordered. > > One idea would be that each Set puts a unique marker on each object it > contains as a non-enumerable property. Override Object.getOwnPropertyNames, > Object.preventExtensions|seal|**freeze for consistency. Much like the > technique in http://code.google.com/p/es-**lab/source/browse/trunk/src/** > ses/WeakMap.js<http://code.google.com/p/es-lab/source/browse/trunk/src/ses/WeakMap.js> > > Certainly not the best solution ever, but it seems like a step forward > assuming the costs of such a solution (in terms of performance and > security) is acceptable in your applications. > > David > > ______________________________**_________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/**listinfo/es-discuss<https://mail.mozilla.org/listinfo/es-discuss> >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

