/** * Creates a new <code>TIntByteHashMap</code> instance containing * all of the entries in the map passed in. * * @param map a <tt>TIntByteMap</tt> that will be duplicated. */ public TIntByteHashMap( TIntByteMap map ) { super( map.size() ); if ( map instanceof TIntByteHashMap ) { TIntByteHashMap hashmap = ( TIntByteHashMap ) map; this._loadFactor = hashmap._loadFactor; this.no_entry_key = hashmap.no_entry_key; this.no_entry_value = hashmap.no_entry_value; //noinspection RedundantCast if ( this.no_entry_key != ( int ) 0 ) { Arrays.fill( _set, this.no_entry_key ); } //noinspection RedundantCast if ( this.no_entry_value != ( byte ) 0 ) { Arrays.fill( _values, this.no_entry_value ); } setUp( (int) Math.ceil( DEFAULT_CAPACITY / _loadFactor ) ); } putAll( map ); }
/** {@inheritDoc} */ public void putAll( TIntByteMap map ) { ensureCapacity( map.size() ); TIntByteIterator iter = map.iterator(); while ( iter.hasNext() ) { iter.advance(); this.put( iter.key(), iter.value() ); } }
/** {@inheritDoc} */ @Override public boolean equals( Object other ) { if ( ! ( other instanceof TIntByteMap ) ) { return false; } TIntByteMap that = ( TIntByteMap ) other; if ( that.size() != this.size() ) { return false; } byte[] values = _values; byte[] states = _states; byte this_no_entry_value = getNoEntryValue(); byte that_no_entry_value = that.getNoEntryValue(); for ( int i = values.length; i-- > 0; ) { if ( states[i] == FULL ) { int key = _set[i]; byte that_value = that.get( key ); byte this_value = values[i]; if ( ( this_value != that_value ) && ( this_value != this_no_entry_value ) && ( that_value != that_no_entry_value ) ) { return false; } } } return true; }
public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // MAP _map = ( TIntByteMap ) in.readObject(); }
/** {@inheritDoc} */ @Override public void putAll( TIntByteMap map ) { ensureCapacity( map.size() ); TIntByteIterator iter = map.iterator(); while ( iter.hasNext() ) { iter.advance(); this.put( iter.key(), iter.value() ); } }
/** {@inheritDoc} */ @Override public boolean equals( Object other ) { if ( ! ( other instanceof TIntByteMap ) ) { return false; } TIntByteMap that = ( TIntByteMap ) other; if ( that.size() != this.size() ) { return false; } TByteOffheapArray values = _values; TByteOffheapArray states = _states; byte this_no_entry_value = getNoEntryValue(); byte that_no_entry_value = that.getNoEntryValue(); for ( int i = capacity(); i-- > 0; ) { if ( states.get( i ) == FULL ) { int key = _set.get( i ); byte that_value = that.get( key ); byte this_value = values.get( i ); if ( ( this_value != that_value ) && ( this_value != this_no_entry_value ) && ( that_value != that_no_entry_value ) ) { return false; } } } return true; }
@Override public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // MAP _map = ( TIntByteMap ) in.readObject(); }
private static mt_bool encodeBool(TIntByteMap t_bool, int timestampsSize) { LOG.log(Level.FINEST, "encoding {0}", TDecorators.wrap(t_bool)); boolean values[] = new boolean[timestampsSize]; int values_len = 0; for (int i = 0; i < values.length; ++i) { if (t_bool.containsKey(i)) values[values_len++] = t_bool.get(i) != 0; } mt_bool result = new mt_bool(); result.presence = createPresenceBitset(t_bool.keySet(), timestampsSize); result.values = bitset(Arrays.copyOf(values, values_len)); return result; }
/** * Gets the value at row i, column j; not yet set values are 0 * @param i * @param j * @return */ public Byte get(int i, int j){ TIntByteMap row = matrix.get(i); if (row != null){ byte value = row.get(j); return value; } // System.out.println("get not ex"); return 0; }
/** * Gets the value at row i, column j as boolean * @param i * @param j * @return */ public boolean getBool(int i, int j){ TIntByteMap row = matrix.get(i); if (row != null){ byte value = row.get(j); return value!=0; } // System.out.println("get not ex"); return false; }
/** * Creates a new matrix; the matrix has no capacity bounds. */ public SparseByteMatrix(int m, int n){ matrix = new TIntObjectHashMap<TIntByteMap>(); M = m; N = n; numberOfEntries = 0; }