public NoDictionaryMultiColumnGroupKeyGenerator(TransformOperator transformOperator, TransformExpressionTree[] groupByExpressions, int numGroupsLimit) { _groupByExpressions = groupByExpressions; _numGroupByExpressions = groupByExpressions.length; _dataTypes = new FieldSpec.DataType[_numGroupByExpressions]; _dictionaries = new Dictionary[_numGroupByExpressions]; _onTheFlyDictionaries = new ValueToIdMap[_numGroupByExpressions]; for (int i = 0; i < _numGroupByExpressions; i++) { TransformExpressionTree groupByExpression = groupByExpressions[i]; TransformResultMetadata transformResultMetadata = transformOperator.getResultMetadata(groupByExpression); _dataTypes[i] = transformResultMetadata.getDataType(); if (transformResultMetadata.hasDictionary()) { _dictionaries[i] = transformOperator.getDictionary(groupByExpression); } else { _onTheFlyDictionaries[i] = ValueToIdMapFactory.get(_dataTypes[i]); } } _groupKeyMap = new Object2IntOpenHashMap<>(); _groupKeyMap.defaultReturnValue(INVALID_ID); _globalGroupIdUpperBound = numGroupsLimit; }
numValues = sortedStrings.length; Preconditions.checkState(numValues > 0); _stringValueToIndexMap = new Object2IntOpenHashMap<>(numValues); for (int i = 0; i < numValues; i++) { String value = sortedStrings[i]; _stringValueToIndexMap.put(value, i); byte[] valueBytes = StringUtil.encodeUtf8(value); sortedStringBytes[i] = valueBytes; _bytesValueToIndexMap = new Object2IntOpenHashMap<>(numValues); _bytesValueToIndexMap.put(value, i); _numBytesPerEntry = Math.max(_numBytesPerEntry, value.getBytes().length);
Object2IntOpenHashMap ids = new Object2IntOpenHashMap(this.size()); int idCount = 0; for (VersionTag tag : this) { InternalDataSerializer.invokeToData(tag, out); } else { int idNumber = ids.getInt(id); if (idNumber == 0) { out.writeByte(FLAG_TAG_WITH_NEW_ID); idNumber = ++idCount; ids.put(id, idNumber); InternalDataSerializer.invokeToData(tag, out); } else {
/** * Create an id of the given object. * * @return the id generated for this object. */ public int createId(Object object) { assert !objectToID.containsKey(object); int id = ++highestID; objectToID.put(object, id); idToObject.put(id, object); return id; }
/** 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" ); }
public StringToIdMap() { _valueToIdMap = new Object2IntOpenHashMap<>(); _valueToIdMap.defaultReturnValue(INVALID_KEY); _idToValueMap = new ObjectArrayList<>(); }
@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 ClassLabel classify(O instance) { Object2IntOpenHashMap<ClassLabel> count = new Object2IntOpenHashMap<>(); KNNList query = knnq.getKNNForObject(instance, k); for(DoubleDBIDListIter neighbor = query.iter(); neighbor.valid(); neighbor.advance()) { count.addTo(labelrep.get(neighbor), 1); } int bestoccur = Integer.MIN_VALUE; ClassLabel bestl = null; for(ObjectIterator<Entry<ClassLabel>> iter = count.object2IntEntrySet().fastIterator(); iter.hasNext();) { Entry<ClassLabel> entry = iter.next(); if(entry.getIntValue() > bestoccur) { bestoccur = entry.getIntValue(); bestl = entry.getKey(); } } return bestl; }
@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(); } }
public FastPrimaryKeyMap(ColumnView id) { map = new Object2IntOpenHashMap<>(id.numRows()); map.defaultReturnValue(-1); for (int i = 0; i < id.numRows(); i++) { map.put(id.getString(i), i); } }
/** * Get the id for a given object */ public int getId(Object object) { return objectToID.getInt(object); }
/** * Learns the prior probability for all classes. */ @Override public void buildClassifier(Database database, Relation<? extends ClassLabel> labelrep) { Object2IntOpenHashMap<ClassLabel> count = new Object2IntOpenHashMap<>(); for(DBIDIter iter = labelrep.iterDBIDs(); iter.valid(); iter.advance()) { count.addTo(labelrep.get(iter), 1); } int max = Integer.MIN_VALUE; double size = labelrep.size(); distribution = new double[count.size()]; labels = new ArrayList<>(count.size()); ObjectIterator<Entry<ClassLabel>> iter = count.object2IntEntrySet().fastIterator(); for(int i = 0; iter.hasNext(); ++i) { Entry<ClassLabel> entry = iter.next(); distribution[i] = entry.getIntValue() / size; labels.add(entry.getKey()); if(entry.getIntValue() > max) { max = entry.getIntValue(); prediction = entry.getKey(); } } }
/** * 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; } }
/** * Add a mapping that we have recovered from disk */ public void addMapping(int id, Object object) { // Store the mapping idToObject.put(id, object); objectToID.put(object, id); // increase the next canonical id the recovered id is higher than it. highestID = highestID < id ? id : highestID; }
private String[] keyList() { String[] keys = new String[keyMap.size()]; for (Object2IntMap.Entry<String> entry : keyMap.object2IntEntrySet()) { keys[entry.getIntValue()] = entry.getKey(); } return keys; }
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; }
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); } }
public void rescale() { for (ObjectIterator<Object2IntMap.Entry<RowSnapshot>> it = this.hMap.object2IntEntrySet(). fastIterator(); it.hasNext(); ) { final Object2IntMap.Entry<RowSnapshot> entry = it.next(); this.hMap.put(entry.getKey(), (int) (entry.getIntValue() * ((double) this.totalRows)/this.sampleSize)); } } }