/** * Creates a new <code>TLongLongHashMap</code> instance containing * all of the entries in the map passed in. * * @param map a <tt>TLongLongMap</tt> that will be duplicated. */ public TLongLongHashMap( TLongLongMap map ) { super( map.size() ); if ( map instanceof TLongLongHashMap ) { TLongLongHashMap hashmap = ( TLongLongHashMap ) 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 != ( long ) 0 ) { Arrays.fill( _set, this.no_entry_key ); } //noinspection RedundantCast if ( this.no_entry_value != ( long ) 0 ) { Arrays.fill( _values, this.no_entry_value ); } setUp( (int) Math.ceil( DEFAULT_CAPACITY / _loadFactor ) ); } putAll( map ); }
/** * Creates a new <code>UnsafeTLongLongHashMap</code> instance containing * all of the entries in the map passed in. * * @param map a <tt>TLongLongMap</tt> that will be duplicated. */ public UnsafeTLongLongHashMap( TLongLongMap map ) { super( map.size() ); if ( map instanceof UnsafeTLongLongHashMap ) { UnsafeTLongLongHashMap hashmap = ( UnsafeTLongLongHashMap ) 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 != ( long ) 0 ) { // Arrays.fill( _set, this.no_entry_key ); Arraysfill( keyAddresses[0][0], this.no_entry_key ); } //noinspection RedundantCast if ( this.no_entry_value != ( long ) 0 ) { // Arrays.fill( _values, this.no_entry_value ); Arraysfill( addresses[0][0], this.no_entry_key ); } setUp( (int) Math.ceil( DEFAULT_CAPACITY / _loadFactor ) ); } putAll( map ); }
/** {@inheritDoc} */ public void putAll( TLongLongMap map ) { ensureCapacity( map.size() ); TLongLongIterator iter = map.iterator(); while ( iter.hasNext() ) { iter.advance(); this.put( iter.key(), iter.value() ); } }
/** {@inheritDoc} */ @Override public boolean equals( Object other ) { if ( ! ( other instanceof TLongLongMap ) ) { return false; } TLongLongMap that = ( TLongLongMap ) other; if ( that.size() != this.size() ) { return false; } long[] values = _values; byte[] states = _states; long this_no_entry_value = getNoEntryValue(); long that_no_entry_value = that.getNoEntryValue(); for ( int i = values.length; i-- > 0; ) { if ( states[i] == FULL ) { long key = _set[i]; long that_value = that.get( key ); long 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 = ( TLongLongMap ) in.readObject(); }
/** {@inheritDoc} */ @Override public void putAll( TLongLongMap map ) { ensureCapacity( map.size() ); TLongLongIterator iter = map.iterator(); while ( iter.hasNext() ) { iter.advance(); this.put( iter.key(), iter.value() ); } }
/** {@inheritDoc} */ @Override public boolean equals( Object other ) { if ( ! ( other instanceof TLongLongMap ) ) { return false; } TLongLongMap that = ( TLongLongMap ) other; if ( that.size() != this.size() ) { return false; } TLongOffheapArray values = _values; TByteOffheapArray states = _states; long this_no_entry_value = getNoEntryValue(); long that_no_entry_value = that.getNoEntryValue(); for ( int i = capacity(); i-- > 0; ) { if ( states.get( i ) == FULL ) { long key = _set.get( i ); long that_value = that.get( key ); long 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 = ( TLongLongMap ) in.readObject(); }
/** {@inheritDoc} */ @Override public boolean equals( Object other ) { if ( ! ( other instanceof TLongLongMap ) ) { return false; } TLongLongMap that = ( TLongLongMap ) other; if ( that.size() != this.size() ) { return false; } // long[] values = _values; // byte[] states = _states; long this_no_entry_value = getNoEntryValue(); long that_no_entry_value = that.getNoEntryValue(); final int len = unsafe.getInt(addresses[0][0]); for ( int i = len; i-- > 0; ) { if ( stateAt(i) == FULL ) { long key = keyAt(i); long that_value = that.get( key ); long this_value = valueAt(i); if ( ( this_value != that_value ) && ( this_value != this_no_entry_value ) && ( that_value != that_no_entry_value ) ) { return false; } } } return true; }
@Test public void testHeavyHitters() { double epsOfTotalCount = 0.0001; double confidence = 0.99; int seed = 7364181; CountMinSketch sketch = new CountMinSketch(epsOfTotalCount, confidence, seed); int maxItems = 1000; Random random = new Random(); TLongLongMap actualItemCount = new TLongLongHashMap(maxItems); random.setSeed(12102); for (int i = 0; i < maxItems; i++) { int itemCount = random.nextInt(20000); sketch.add(i, itemCount); actualItemCount.put(i, itemCount); } List<Item> itemsBagFromSketch = new ArrayList<Item>(); List<Item> itemsBagActual = new ArrayList<Item>(); for (int i = 0; i < maxItems; i++) { itemsBagFromSketch.add(new Item(i, sketch.estimateCount(i))); itemsBagActual.add(new Item(i, actualItemCount.get(i))); } Ordering<Item> ordering = new Ordering<Item>() { @Override public int compare(Item me, Item other) { return Long.compare(me.count, other.count); } }; List<Item> topKItemsEstimated = ordering.greatestOf(itemsBagFromSketch, 5); List<Item> topKItemsActual = ordering.greatestOf(itemsBagActual, 5); /* System.out.println("Top 5 estimated items"); for (Item item : topKItemsEstimated) { System.out.println(item); } */ /* System.out.println("Top 5 actual");*/ for (int i = 0; i < topKItemsActual.size(); i++) { assertEquals(true, topKItemsActual.get(i).checkForEquality(topKItemsEstimated.get(i))); } }
public TLongLongMap getMap() { return container; }
/** * Creates a wrapper that decorates the specified primitive map. * * @param map the <tt>TLongLongMap</tt> to wrap. */ public TLongLongMapDecorator( TLongLongMap map ) { super(); this._map = map; }