/** * Creates a new <code>TByteHashSet</code> instance that is a copy * of the existing set. * * @param collection a <tt>TByteSet</tt> that will be duplicated. */ public TByteHashSet( TByteCollection collection ) { this( Math.max( collection.size(), DEFAULT_CAPACITY ) ); if ( collection instanceof TByteHashSet ) { TByteHashSet hashset = ( TByteHashSet ) collection; this._loadFactor = hashset._loadFactor; this.no_entry_value = hashset.no_entry_value; //noinspection RedundantCast if ( this.no_entry_value != ( byte ) 0 ) { Arrays.fill( _set, this.no_entry_value ); } setUp( (int) Math.ceil( DEFAULT_CAPACITY / _loadFactor ) ); } addAll( collection ); }
/** {@inheritDoc} */ public boolean containsAll( byte[] array ) { for ( int i = array.length; i-- > 0; ) { if ( ! contains( array[i] ) ) { return false; } } return true; }
/** {@inheritDoc} */ public boolean add( byte 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 byte[] h1, final byte[] h2) { TByteHashSet union = new TByteHashSet(h1); union.addAll(h2); TByteHashSet intersection = new TByteHashSet(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( byte[] array ) { boolean changed = false; for ( int i = array.length; i-- > 0; ) { if ( add( array[i] ) ) { changed = true; } } return changed; }
/** * Creates a new <code>TByteHashSet</code> instance containing the * elements of <tt>array</tt>. * * @param array an array of <code>byte</code> primitives */ public TByteHashSet( byte[] array ) { this( Math.max( array.length, DEFAULT_CAPACITY ) ); addAll( array ); }
/** {@inheritDoc} */ public boolean removeAll( byte[] array ) { boolean changed = false; for ( int i = array.length; i-- > 0; ) { if ( remove(array[i]) ) { changed = true; } } return changed; }
/** {@inheritDoc} */ public byte[] toArray() { byte[] result = new byte[ size() ]; byte[] set = _set; byte[] states = _states; for ( int i = states.length, j = 0; i-- > 0; ) { if ( states[i] == FULL ) { result[j++] = set[i]; } } return result; }
/** * Creates a new <code>TByteHashSet</code> instance that is a copy * of the existing set. * * @param collection a <tt>TByteSet</tt> that will be duplicated. */ public TByteHashSet( TByteCollection collection ) { this( Math.max( collection.size(), DEFAULT_CAPACITY ) ); if ( collection instanceof TByteHashSet ) { TByteHashSet hashset = ( TByteHashSet ) collection; this._loadFactor = hashset._loadFactor; this.no_entry_value = hashset.no_entry_value; //noinspection RedundantCast if ( this.no_entry_value != ( byte ) 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; TByteIterator iter = iterator(); while ( iter.hasNext() ) { if ( ! collection.contains( Byte.valueOf ( iter.next() ) ) ) { iter.remove(); modified = true; } } return modified; }
/** {@inheritDoc} */ public boolean retainAll( byte[] array ) { boolean changed = false; Arrays.sort( array ); byte[] 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( byte 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 byte[] h1, final byte[] h2) { TByteHashSet union = new TByteHashSet(h1); union.addAll(h2); TByteHashSet intersection = new TByteHashSet(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 Byte> collection ) { boolean changed = false; for ( Byte element : collection ) { byte e = element.byteValue(); if ( add( e ) ) { changed = true; } } return changed; }
/** * Creates a new <code>TByteHashSet</code> instance that is a copy * of the existing Collection. * * @param collection a <tt>Collection</tt> that will be duplicated. */ public TByteHashSet( Collection<? extends Byte> collection ) { this( Math.max( collection.size(), DEFAULT_CAPACITY ) ); addAll( collection ); }
/** {@inheritDoc} */ public boolean removeAll( Collection<?> collection ) { boolean changed = false; for ( Object element : collection ) { if ( element instanceof Byte ) { byte c = ( ( Byte ) element ).byteValue(); if ( remove( c ) ) { changed = true; } } } return changed; }
/** {@inheritDoc} */ public boolean equals( Object other ) { if ( ! ( other instanceof TByteSet ) ) { return false; } TByteSet that = ( TByteSet ) other; if ( that.size() != this.size() ) { return false; } for ( int i = _states.length; i-- > 0; ) { if ( _states[i] == FULL ) { if ( ! that.contains( _set[i] ) ) { return false; } } } return true; }