/** * Adds all of the elements in <tt>array</tt> to the set. * * @param array an <code>array</code> of long primitives. * @return true if the set was modified by the add all operation. */ public boolean addAll(long[] array) { boolean changed = false; for (int i = array.length; i-- > 0;) { if (add(array[i])) { changed = true; } } return changed; }
public final boolean execute(long value) { return that.contains(value); } });
/** * Creates a new <code>TLongHashSet</code> instance containing the * elements of <tt>array</tt>. * * @param array an array of <code>long</code> primitives * @param strategy used to compute hash codes and to compare keys. */ public TLongHashSet(long[] array, TLongHashingStrategy strategy) { this(array.length, strategy); addAll(array); }
/** * Inserts a value into the set. * * @param val an <code>long</code> value * @return true if the set was modified by the add operation */ public boolean add(long val) { int index = insertionIndex(val); if (index < 0) { return false; // already present in set, nothing to add } byte previousState = _states[index]; _set[index] = val; _states[index] = FULL; postInsertHook(previousState == FREE); return true; // yes, we added something }
@Override public Document getDocument() { long docno; try { docno = Long.parseLong(((FlatJSONDocument)currentDocument).getProperty("docno") ); } catch (Exception e) { logger.warn("WARN: Parsing failure... skipping document"); return null; } if(alldocnos.contains(docno)) return null; alldocnos.add(docno); return currentDocument; }
if (_set.equals(other)) { return true; // comparing two trove sets } else if (other instanceof Set) { Set that = (Set)other; if (that.size() != _set.size()) { return false; // different sizes, no need to compare } else { // now we have to do it the hard way if (val instanceof Long) { long v = unwrap(val); if (_set.contains(v)) {
/** * Compares this set with another set for equality of their stored * entries. * * @param other an <code>Object</code> value * @return a <code>boolean</code> value */ public boolean equals(Object other) { if (! (other instanceof TLongHashSet)) { return false; } final TLongHashSet that = (TLongHashSet)other; if (that.size() != this.size()) { return false; } return forEach(new TLongProcedure() { public final boolean execute(long value) { return that.contains(value); } }); }
/** * Empties the set. */ public void clear() { this._set.clear(); }
/** * Creates an iterator over the values of the set. * * @return an iterator with support for removals in the underlying set */ public Iterator iterator() { return new Iterator() { private final TLongIterator it = _set.iterator(); public Object next() { return wrap(it.next()); } public boolean hasNext() { return it.hasNext(); } public void remove() { it.remove(); } }; }
/** * Expands the set to accomodate new values. * * @param newCapacity an <code>int</code> value */ protected void rehash(int newCapacity) { int oldCapacity = _set.length; long oldSet[] = _set; byte oldStates[] = _states; _set = new long[newCapacity]; _states = new byte[newCapacity]; for (int i = oldCapacity; i-- > 0;) { if(oldStates[i] == FULL) { long o = oldSet[i]; int index = insertionIndex(o); _set[index] = o; _states[index] = FULL; } } }
private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); // number of entries stream.writeInt(_size); SerializationProcedure writeProcedure = new SerializationProcedure(stream); if (! forEach(writeProcedure)) { throw writeProcedure.exception; } }
@Override public Document getDocument() { long docno; try { docno = Long.parseLong(((FlatJSONDocument)currentDocument).getProperty("docno") ); } catch (Exception e) { logger.warn("WARN: Parsing failure... skipping document"); return null; } if(alldocnos.contains(docno)) return null; alldocnos.add(docno); return currentDocument; }
/** * Inserts a value into the set. * * @param true if the set was modified by the insertion */ public boolean add(Object value) { return _set.add(unwrap(value)); }
/** * Tests the set to determine if all of the elements in * <tt>array</tt> are present. * * @param array an <code>array</code> of long primitives. * @return true if all elements were present in the set. */ public boolean containsAll(long[] array) { for (int i = array.length; i-- > 0;) { if (! contains(array[i])) { return false; } } return true; }
/** * Creates a new <code>TLongHashSet</code> instance containing the * elements of <tt>array</tt>. * * @param array an array of <code>long</code> primitives */ public TLongHashSet(long[] array) { this(array.length); addAll(array); }