@Override public Int2ObjectMap<Aggregator[]> makeDimExtractionAggregateStore() { return new Int2ObjectOpenHashMap<>(); }
public SparseMatrix(int rows, int columns, Map<Integer, Vector> rowVectors, boolean shallow) { // Why this is passing in a map? iterating it is pretty inefficient as opposed to simple lists... super(rows, columns); this.rowVectors = new Int2ObjectOpenHashMap<>(); if (shallow) { for (Map.Entry<Integer, Vector> entry : rowVectors.entrySet()) { this.rowVectors.put(entry.getKey().intValue(), entry.getValue()); } } else { for (Map.Entry<Integer, Vector> entry : rowVectors.entrySet()) { this.rowVectors.put(entry.getKey().intValue(), entry.getValue().clone()); } } }
Int2ObjectOpenHashMap<Message> messages = new Int2ObjectOpenHashMap<>(); long startSer = theStats.startMsgSerialization(); boolean firstMessage = true; for (GMSMember mbr : calculatedMembers) { short version = mbr.getVersionOrdinal(); if (!messages.containsKey(version)) { Message jmsg = createJGMessage(msg, local, version); messages.put(version, jmsg); if (firstMessage) { theStats.incSentBytes(jmsg.getLength()); JGAddress to = new JGAddress(mbr); short version = mbr.getVersionOrdinal(); Message jmsg = messages.get(version); Exception problem = null; try {
Int2ObjectOpenHashMap<Int2IntOpenHashMap> rowPositionMap = new Int2ObjectOpenHashMap<>(); for (int rowIndex = 0; rowIndex < rowSize(); rowIndex++) { SequentialSparseVector tempRowVector = row(rowIndex); tempPositionMap.put(vectorEntry.index(), vectorEntry.position()); rowPositionMap.put(rowIndex, tempPositionMap); for (Vector.VectorEntry vectorEntry : tempRowVector) { columnToRowPositionMap[columnIndex][vectorEntry.position()] = rowPositionMap.get(vectorEntry.index()).get(columnIndex); Int2ObjectOpenHashMap<Int2IntOpenHashMap> columnPositionMap = new Int2ObjectOpenHashMap<>(); for (int columnIndex = 0; columnIndex < columnSize(); columnIndex++) { SequentialSparseVector tempColumnVector = column(columnIndex); tempPositionMap.put(vectorEntry.index(), vectorEntry.position()); columnPositionMap.put(columnIndex, tempPositionMap); for (Vector.VectorEntry vectorEntry : tempRowVector) { rowToColumnPositionMap[rowIndex][vectorEntry.position()] = columnPositionMap.get(vectorEntry.index()).get(rowIndex);
@Override public int test() { final Int2ObjectOpenHashMap<Integer> m_map = new Int2ObjectOpenHashMap<>( m_keys.length / 2 + 1, m_fillFactor ); final Integer value = 1; int add = 0, remove = 0; while ( add < m_keys.length ) { m_map.put( m_keys[ add ], value ); ++add; m_map.put( m_keys[ add ], value ); ++add; m_map.remove( m_keys[ remove++ ] ); } return m_map.size(); } }
/** * 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; }
/** * Get the object for a given id. */ public Object getObject(int id) { return idToObject.get(id); }
@Override public int test() { final Int2ObjectOpenHashMap<Integer> m_map = new Int2ObjectOpenHashMap<>( m_keys.length, m_fillFactor ); for ( int i = 0; i < m_keys.length; ++i ) m_map.put( m_keys[ i ], null ); for ( int i = 0; i < m_keys.length; ++i ) m_map.put( m_keys[ i ], null ); return m_map.size(); } }
/** * Create a new matrix with the given number of rows. * * @param numRows the number of rows. */ public IntSparseMatrix(int numRows) { this.numRows = numRows; rows = new Int2ObjectOpenHashMap<IntSparseVector>(numRows); rows.defaultReturnValue(null); }
public void generateDataFrameIndex() { for (int i = 0; i < df.getData().get(index).size(); i++) { if (!dataTable.containsKey((int) df.get(i, index))) { dataTable.put((int) df.get(i, index), new IntArrayList()); } dataTable.get((int) df.get(i, index)).add(index); } }
@Override public Matrix assign(Matrix other, DoubleDoubleFunction function) { //TODO generalize to other kinds of functions if (Functions.PLUS.equals(function) && other instanceof SparseMatrix) { int rows = rowSize(); if (rows != other.rowSize()) { throw new CardinalityException(rows, other.rowSize()); } int columns = columnSize(); if (columns != other.columnSize()) { throw new CardinalityException(columns, other.columnSize()); } SparseMatrix otherSparse = (SparseMatrix) other; for(ObjectIterator<Entry<Vector>> fastIterator = otherSparse.rowVectors.int2ObjectEntrySet().fastIterator(); fastIterator.hasNext();) { final Entry<Vector> entry = fastIterator.next(); final int rowIndex = entry.getIntKey(); Vector row = rowVectors.get(rowIndex); if (row == null) { rowVectors.put(rowIndex, entry.getValue().clone()); } else { row.assign(entry.getValue(), Functions.PLUS); } } return this; } else { return super.assign(other, function); } }
@Override public void writePartition(DataOutput out, int partitionId) throws IOException { Int2ObjectOpenHashMap<DataInputOutput> partitionMap = map.get(partitionId); out.writeInt(partitionMap.size()); ObjectIterator<Int2ObjectMap.Entry<DataInputOutput>> iterator = partitionMap.int2ObjectEntrySet().fastIterator(); while (iterator.hasNext()) { Int2ObjectMap.Entry<DataInputOutput> entry = iterator.next(); out.writeInt(entry.getIntKey()); entry.getValue().write(out); } }
@Override public Iterable<IntWritable> getPartitionDestinationVertices( int partitionId) { Int2ObjectOpenHashMap<DataInputOutput> partitionMap = map.get(partitionId); List<IntWritable> vertices = Lists.newArrayListWithCapacity(partitionMap.size()); IntIterator iterator = partitionMap.keySet().iterator(); while (iterator.hasNext()) { vertices.add(new IntWritable(iterator.nextInt())); } return vertices; }
@Override public V remove(IntWritable key) { return map.remove(key.get()); }
@Override public int numSlices() { return rowVectors.size(); }
@Test public void testDataSerializableFixedIDInt() throws IOException, ClassNotFoundException { assertFalse( DSFIDFactory.getDsfidmap2().containsKey(DummyIntDataSerializableFixedID.INT_SIZE_id)); registerDSFID(DummyIntDataSerializableFixedID.INT_SIZE_id, DummyIntDataSerializableFixedID.class); assertTrue( DSFIDFactory.getDsfidmap2().containsKey(DummyIntDataSerializableFixedID.INT_SIZE_id)); try { DummyIntDataSerializableFixedID dummyObj = new DummyIntDataSerializableFixedID(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(baos); DataSerializer.writeObject(dummyObj, out); byte[] bytes = baos.toByteArray(); String type = DataType.getDataType(bytes); assertEquals("org.apache.geode.internal.DataSerializableFixedID:" + DummyIntDataSerializableFixedID.class.getName(), type); } finally { DSFIDFactory.getDsfidmap2().remove(DummyIntDataSerializableFixedID.INT_SIZE_id); assertFalse( DSFIDFactory.getDsfidmap2().containsKey(DummyIntDataSerializableFixedID.INT_SIZE_id)); } }
@Override public void write(DataOutput out) throws IOException { out.writeInt(map.size()); ObjectIterator<Int2ObjectMap.Entry<V>> iterator = map.int2ObjectEntrySet().fastIterator(); while (iterator.hasNext()) { Int2ObjectMap.Entry<V> entry = iterator.next(); out.writeInt(entry.getIntKey()); valueWriter.write(out, entry.getValue()); } }