@Override public int getCurrentGroupKeyUpperBound() { return _groupKeyMap.size(); }
@Override public int getNumberOfEvents() { return counts.size(); }
@Override public int numRows() { return map.size(); }
FreqKList(long totalRows, double epsilon, Object2IntOpenHashMap<RowSnapshot> hMap) { this.totalRows = totalRows; this.epsilon = epsilon; this.hMap = hMap; this.pList = new ArrayList<Pair<RowSnapshot, Integer>>(this.hMap.size()); }
@SuppressWarnings("ConstantConditions") @Override public String toString() { List<Pair<RowSnapshot, Integer>> pList = new ArrayList<Pair<RowSnapshot, Integer>>(this.hMap.size()); this.hMap.forEach((rs, j) -> pList.add(new Pair<RowSnapshot, Integer>(rs, j))); pList.sort((p1, p2) -> Integer.compare(p2.second, p1.second)); final StringBuilder builder = new StringBuilder(); pList.forEach(p -> builder.append(p.first.toString()).append(": ").append(p.second) .append(System.getProperty("line.separator"))); return builder.toString(); } }
@Override public void putAll(Map<? extends K, ? extends Integer> m) { if (f <= .5) ensureCapacity(m.size()); // The resulting map will be sized for m.size() elements else tryCapacity(size() + m.size()); // The resulting map will be tentatively sized for size() + m.size() // elements super.putAll(m); } @SuppressWarnings("unchecked")
private int keyId(String stringKey) { int keyIndex = keyMap.getInt(stringKey); if(keyIndex == -1) { keyIndex = keyMap.size(); keyMap.put(stringKey, keyIndex); } return keyIndex; }
int encode(@Nullable String value) { final int ret = this.intEncoding.getOrDefault(value, KEY_NOT_FOUND); if (ret != KEY_NOT_FOUND) return ret; int encoding = this.intEncoding.size(); this.intEncoding.put(value, encoding); this.intDecoding.put(encoding, value); return encoding; }
@Override public void addData( String value ) { // We don't want to store a substring, which might hang on // to more characters than it needs. So make a clean copy. value = new String( value ); int index = indexByString.getInt( value ); if ( index == -1 ) { index = indexByString.size( ); indexByString.put( value, index ); } indexByRow.append( index ); }
/** * Get a descending list of counted items. * * @return List of items. */ public static <O> List<Entry<O>> descending(Object2IntOpenHashMap<O> counters) { ArrayList<Entry<O>> copy = new ArrayList<>(counters.size()); for(Iterator<Object2IntMap.Entry<O>> iter = counters.object2IntEntrySet().fastIterator(); iter.hasNext();) { // Note: fast iterator will recycle this object! Object2IntMap.Entry<O> entry = iter.next(); copy.add(new Entry<O>(entry.getKey(), entry.getIntValue())); } Collections.sort(copy); return copy; }
private void process(Object2IntOpenHashMap<String> idMap, Int2ObjectOpenHashMap<IntList> idToRows, Int2ObjectOpenHashMap<String> rowToId, Frame df, List<String> varNames) { for (int i = 0; i < df.rowCount(); i++) { StringBuilder sb = new StringBuilder(); for (int k = 0; k < varNames.size(); k++) { sb.append(k).append(SEP).append(df.getLabel(i, varNames.get(k))).append(SEP); } String key = sb.toString(); idMap.putIfAbsent(key, idMap.size()); int id = idMap.getInt(key); idToRows.putIfAbsent(id, new IntArrayList()); idToRows.get(id).add(i); rowToId.put(i, key); } }
private String[] keyList() { String[] keys = new String[keyMap.size()]; for (Object2IntMap.Entry<String> entry : keyMap.object2IntEntrySet()) { keys[entry.getIntValue()] = entry.getKey(); } return keys; }
@Override public int test() { final Object2IntOpenHashMap<Integer> m_map = new Object2IntOpenHashMap<>( m_keys.length, m_fillFactor ); for ( int i = 0; i < m_keys.length; ++i ) m_map.put( m_keys[ i ], i ); for ( int i = 0; i < m_keys2.length; ++i ) m_map.put( m_keys2[ i ], i ); return m_map.size(); } }
/** * Add a (potentially new) element to the map * @param token The element * @return The index assigned to it */ public int offer(String token) { if(super.containsKey(token)) { return super.getInt(token); } else { int w = super.size() + 1; super.put(token, w); return w; } }
/** Creates a new replicated document factory. * * @param documentFactory the factory that will be replicated. * @param numberOfCopies the number of copies. * @param fieldName the names to be given to the fields of the new factory. */ private ReplicatedDocumentFactory( final DocumentFactory documentFactory, final int numberOfCopies, final String[] fieldName ) { this.documentFactory = documentFactory; this.numberOfCopies = numberOfCopies; this.fieldName = fieldName; if ( numberOfFields() != fieldName.length ) throw new IllegalArgumentException( "The number of field names (" + fieldName.length + ") is not equal to the number of fields in the replicated factory (" + numberOfFields() + ")" ); field2Index = new Object2IntOpenHashMap<String>( fieldName.length, .5f ); field2Index.defaultReturnValue( -1 ); for( int i = 0; i < fieldName.length; i++ ) field2Index.put( fieldName[ i ], i ); if ( field2Index.size() != fieldName.length ) throw new IllegalArgumentException( "The field name array " + ObjectArrayList.wrap( fieldName ) + " contains duplicates" ); }
/** Creates a new replicated document factory. * * @param documentFactory the factory that will be replicated. * @param numberOfCopies the number of copies. * @param fieldName the names to be given to the fields of the new factory. */ private ReplicatedDocumentFactory( final DocumentFactory documentFactory, final int numberOfCopies, final String[] fieldName ) { this.documentFactory = documentFactory; this.numberOfCopies = numberOfCopies; this.fieldName = fieldName; if ( numberOfFields() != fieldName.length ) throw new IllegalArgumentException( "The number of field names (" + fieldName.length + ") is not equal to the number of fields in the replicated factory (" + numberOfFields() + ")" ); field2Index = new Object2IntOpenHashMap<String>( fieldName.length, .5f ); field2Index.defaultReturnValue( -1 ); for( int i = 0; i < fieldName.length; i++ ) field2Index.put( fieldName[ i ], i ); if ( field2Index.size() != fieldName.length ) throw new IllegalArgumentException( "The field name array " + ObjectArrayList.wrap( fieldName ) + " contains duplicates" ); }
/** Creates a new replicated document factory. * * @param documentFactory the factory that will be replicated. * @param numberOfCopies the number of copies. * @param fieldName the names to be given to the fields of the new factory. */ private ReplicatedDocumentFactory( final DocumentFactory documentFactory, final int numberOfCopies, final String[] fieldName ) { this.documentFactory = documentFactory; this.numberOfCopies = numberOfCopies; this.fieldName = fieldName; if ( numberOfFields() != fieldName.length ) throw new IllegalArgumentException( "The number of field names (" + fieldName.length + ") is not equal to the number of fields in the replicated factory (" + numberOfFields() + ")" ); field2Index = new Object2IntOpenHashMap<String>( fieldName.length, .5f ); field2Index.defaultReturnValue( -1 ); for( int i = 0; i < fieldName.length; i++ ) field2Index.put( fieldName[ i ], i ); if ( field2Index.size() != fieldName.length ) throw new IllegalArgumentException( "The field name array " + ObjectArrayList.wrap( fieldName ) + " contains duplicates" ); }
/** Creates a new replicated document factory. * * @param documentFactory the factory that will be replicated. * @param numberOfCopies the number of copies. * @param fieldName the names to be given to the fields of the new factory. */ private ReplicatedDocumentFactory( final DocumentFactory documentFactory, final int numberOfCopies, final String[] fieldName ) { this.documentFactory = documentFactory; this.numberOfCopies = numberOfCopies; this.fieldName = fieldName; if ( numberOfFields() != fieldName.length ) throw new IllegalArgumentException( "The number of field names (" + fieldName.length + ") is not equal to the number of fields in the replicated factory (" + numberOfFields() + ")" ); field2Index = new Object2IntOpenHashMap<String>( fieldName.length, .5f ); field2Index.defaultReturnValue( -1 ); for( int i = 0; i < fieldName.length; i++ ) field2Index.put( fieldName[ i ], i ); if ( field2Index.size() != fieldName.length ) throw new IllegalArgumentException( "The field name array " + ObjectArrayList.wrap( fieldName ) + " contains duplicates" ); }
@Override public int test() { final Object2IntOpenHashMap<Integer> m_map = new Object2IntOpenHashMap<>( m_keys.length / 2 + 1, m_fillFactor ); int add = 0, remove = 0; while ( add < m_keys.length ) { m_map.put( m_keys[ add ], add ); ++add; m_map.put( m_keys[ add ], add ); ++add; m_map.removeInt( m_keys[ remove++ ] ); } return m_map.size(); } }
@Override public TableColumn createTableColumn( Column column, Concept concept, DataType type ) { // This seems a little dangerous, but works because we're careful // to put each integer on [0,size) into the map exactly once String[] uniqueStrings = new String[indexByString.size( )]; for ( Object2IntMap.Entry<String> entry : indexByString.object2IntEntrySet( ) ) { int index = entry.getIntValue( ); uniqueStrings[index] = entry.getKey( ); } return new CompactInternStringTableColumn( column, concept, indexByRow.n, uniqueStrings, indexByRow.copyOf( ) ); }