/** * Creates a new <code>TFloatHashSet</code> instance that is a copy * of the existing set. * * @param collection a <tt>TFloatSet</tt> that will be duplicated. */ public TFloatHashSet( TFloatCollection collection ) { this( Math.max( collection.size(), DEFAULT_CAPACITY ) ); if ( collection instanceof TFloatHashSet ) { TFloatHashSet hashset = ( TFloatHashSet ) collection; this._loadFactor = hashset._loadFactor; this.no_entry_value = hashset.no_entry_value; //noinspection RedundantCast if ( this.no_entry_value != ( float ) 0 ) { Arrays.fill( _set, this.no_entry_value ); } setUp( (int) Math.ceil( DEFAULT_CAPACITY / _loadFactor ) ); } addAll( collection ); }
/** {@inheritDoc} */ public float[] toArray() { float[] result = new float[ size() ]; float[] set = _set; byte[] states = _states; for ( int i = states.length, j = 0; i-- > 0; ) { if ( states[i] == FULL ) { result[j++] = set[i]; } } return result; }
/** {@inheritDoc} */ public boolean add( float val ) { int index = insertKey(val); if ( index < 0 ) { return false; // already present in set, nothing to add } postInsertHook( consumeFreeSlot ); return true; // yes, we added something }
@Override public double compare(final float[] h1, final float[] h2) { TFloatHashSet union = new TFloatHashSet(h1); union.addAll(h2); TFloatHashSet intersection = new TFloatHashSet(h1); intersection.retainAll(h2.clone()); //retainAll sorts the input, so we need to make a copy return 1.0 - (((double)intersection.size()) / (double)union.size()); } },
/** {@inheritDoc} */ public boolean addAll( float[] array ) { boolean changed = false; for ( int i = array.length; i-- > 0; ) { if ( add( array[i] ) ) { changed = true; } } return changed; }
/** * Creates a new <code>TFloatHashSet</code> instance containing the * elements of <tt>array</tt>. * * @param array an array of <code>float</code> primitives */ public TFloatHashSet( float[] array ) { this( Math.max( array.length, DEFAULT_CAPACITY ) ); addAll( array ); }
/** {@inheritDoc} */ public boolean containsAll( float[] array ) { for ( int i = array.length; i-- > 0; ) { if ( ! contains( array[i] ) ) { return false; } } return true; }
/** {@inheritDoc} */ public boolean removeAll( float[] array ) { boolean changed = false; for ( int i = array.length; i-- > 0; ) { if ( remove(array[i]) ) { changed = true; } } return changed; }
/** * Creates a new <code>TFloatHashSet</code> instance that is a copy * of the existing set. * * @param collection a <tt>TFloatSet</tt> that will be duplicated. */ public TFloatHashSet( TFloatCollection collection ) { this( Math.max( collection.size(), DEFAULT_CAPACITY ) ); if ( collection instanceof TFloatHashSet ) { TFloatHashSet hashset = ( TFloatHashSet ) collection; this._loadFactor = hashset._loadFactor; this.no_entry_value = hashset.no_entry_value; //noinspection RedundantCast if ( this.no_entry_value != ( float ) 0 ) { Arrays.fill( _set, this.no_entry_value ); } setUp( saturatedCast( fastCeil( DEFAULT_CAPACITY / (double) _loadFactor ) ) ); } addAll( collection ); }
/** {@inheritDoc} */ @SuppressWarnings({"SuspiciousMethodCalls"}) public boolean retainAll( Collection<?> collection ) { boolean modified = false; TFloatIterator iter = iterator(); while ( iter.hasNext() ) { if ( ! collection.contains( Float.valueOf ( iter.next() ) ) ) { iter.remove(); modified = true; } } return modified; }
/** {@inheritDoc} */ public boolean retainAll( float[] array ) { boolean changed = false; Arrays.sort( array ); float[] set = _set; byte[] states = _states; _autoCompactTemporaryDisable = true; for ( int i = set.length; i-- > 0; ) { if ( states[i] == FULL && ( Arrays.binarySearch( array, set[i] ) < 0) ) { removeAt( i ); changed = true; } } _autoCompactTemporaryDisable = false; return changed; }
/** {@inheritDoc} */ public boolean add( float 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 double compare(final float[] h1, final float[] h2) { TFloatHashSet union = new TFloatHashSet(h1); union.addAll(h2); TFloatHashSet intersection = new TFloatHashSet(h1); intersection.retainAll(h2.clone()); //retainAll sorts the input, so we need to make a copy return 1.0 - (((double)intersection.size()) / (double)union.size()); } },
/** {@inheritDoc} */ public boolean addAll( Collection<? extends Float> collection ) { boolean changed = false; for ( Float element : collection ) { float e = element.floatValue(); if ( add( e ) ) { changed = true; } } return changed; }
/** * Creates a new <code>TFloatHashSet</code> instance that is a copy * of the existing Collection. * * @param collection a <tt>Collection</tt> that will be duplicated. */ public TFloatHashSet( Collection<? extends Float> collection ) { this( Math.max( collection.size(), DEFAULT_CAPACITY ) ); addAll( collection ); }
/** {@inheritDoc} */ public boolean containsAll( Collection<?> collection ) { for ( Object element : collection ) { if ( element instanceof Float ) { float c = ( ( Float ) element ).floatValue(); if ( ! contains( c ) ) { return false; } } else { return false; } } return true; }
/** {@inheritDoc} */ public boolean removeAll( Collection<?> collection ) { boolean changed = false; for ( Object element : collection ) { if ( element instanceof Float ) { float c = ( ( Float ) element ).floatValue(); if ( remove( c ) ) { changed = true; } } } return changed; }