var processedBag = new WeakSet(); var nextObject = getNext(); while (nextObject !== null){ // Check if already processed this similar object? if (!processedBag.has(nextObject)){ // If not, process it and memorize process(nextObject); processedBag.add(nextObject); } nextObject = getNext(); }
/** * Return the size of the set. * * @return The size of the set. */ public int size() { maintain(); return set.size(); }
/** * Construct a <tt>WeakSet</tt>. Any elements in the given set will be * wrapped in {@link WeakObject} references. * * @param set The <tt>Set</tt> which will be used for element storage. * * @throws NullArgumentException Set is <tt>null</tt>. */ public WeakSet(final Set set) { if (set == null) throw new NullArgumentException("set"); // reset any elements to weak objects if (set.size() != 0) { Object elements[] = set.toArray(); set.clear(); for (int i=0; i<elements.length; i++) { add(elements[i]); } } this.set = set; }
/** * Returns <tt>true</tt> if this set contains no elements. * * @return <tt>true</tt> if this set contains no elements. */ public boolean isEmpty() { maintain(); return set.isEmpty(); }
let ws = new WeakSet(); let symbol = Symbol(); let wrapped = Object(symbol); ws.add(wrapped);
/** * Returns a shallow copy of this <tt>WeakSet</tt> instance: the elements * themselves are not cloned. * * @return A shallow copy of this set. */ public Object clone() { maintain(); try { return super.clone(); } catch (CloneNotSupportedException e) { throw new InternalError(); } } }
var touch = (function() { var seen = new WeakSet(); return function(value) { if(seen.has(value)) return true; seen.add(value); }; })(); function convert(object) { if(touch(object)) return; extend(object, yunoprototype); // Made up. }; function unconvert(object) { if(untouch(object)) return; // Imagine it exists. del_props(object, Object.keys(yunoprototype)); // Never do this IRL. };
/** * Add an element to the set. * * @param obj Element to add to the set. * @return True if the element was added. */ public boolean add(final Object obj) { maintain(); return set.add(WeakObject.create(obj, queue)); }
/** * Returns <tt>true</tt> if this set contains the specified element. * * @param obj Element whose presence in this set is to be tested. * @return <tt>true</tt> if this set contains the specified element. */ public boolean contains(final Object obj) { maintain(); return set.contains(WeakObject.create(obj)); }
/** * Removes the given element from this set if it is present. * * @param obj Object to be removed from this set, if present. * @return <tt>true</tt> if the set contained the specified element. */ public boolean remove(final Object obj) { maintain(); return set.remove(WeakObject.create(obj)); }