List of usage examples for com.google.common.collect Table size
int size();
From source file:net.librec.math.structure.SparseStringMatrix.java
/** * Construct a sparse matrix/* w w w . j a v a 2s . com*/ * * @param dataTable data table * @param columnStructure column structure */ private void construct(Table<Integer, Integer, ? extends String> dataTable, Multimap<Integer, Integer> columnStructure) { int nnz = dataTable.size(); // CRS rowPtr = new int[numRows + 1]; colInd = new int[nnz]; rowData = new String[nnz]; int j = 0; for (int i = 1; i <= numRows; ++i) { Set<Integer> cols = dataTable.row(i - 1).keySet(); rowPtr[i] = rowPtr[i - 1] + cols.size(); for (int col : cols) { colInd[j++] = col; if (col < 0 || col >= numColumns) throw new IllegalArgumentException( "colInd[" + j + "]=" + col + ", which is not a valid column index"); } Arrays.sort(colInd, rowPtr[i - 1], rowPtr[i]); } // CCS colPtr = new int[numColumns + 1]; rowInd = new int[nnz]; colData = new String[nnz]; j = 0; for (int i = 1; i <= numColumns; ++i) { // dataTable.col(i-1) is more time-consuming than columnStructure.get(i-1) Collection<Integer> rows = columnStructure != null ? columnStructure.get(i - 1) : dataTable.column(i - 1).keySet(); colPtr[i] = colPtr[i - 1] + rows.size(); for (int row : rows) { rowInd[j++] = row; if (row < 0 || row >= numRows) throw new IllegalArgumentException( "rowInd[" + j + "]=" + row + ", which is not a valid row index"); } Arrays.sort(rowInd, colPtr[i - 1], colPtr[i]); } // set data for (Cell<Integer, Integer, ? extends String> en : dataTable.cellSet()) { int row = en.getRowKey(); int col = en.getColumnKey(); String val = en.getValue().toString(); set(row, col, val); } }
From source file:co.cask.cdap.data2.dataset2.lib.cube.DefaultCube.java
@Override public Collection<TimeSeries> query(CubeQuery query) { /*//from ww w . j a v a2 s .c om CubeQuery example: "dataset read ops for app per dataset". Or: SELECT count('read.ops') << measure name and type FROM aggregation1.1min_resolution << aggregation and resolution GROUP BY dataset, << groupByDimensions WHERE namespace='ns1' AND app='myApp' AND program='myFlow' AND << dimensionValues ts>=1423370200 AND ts{@literal<}1423398198 << startTs and endTs LIMIT 100 << limit Execution: 1) (optional, if aggregation to query in is not provided) find aggregation to supply results Here, we need aggregation that has following dimensions: 'namespace', 'app', 'program', 'dataset'. Ideally (to reduce the scan range), 'dataset' should be in the end, other dimensions as close to the beginning as possible, and minimal number of other "unspecified" dimensions. Let's say we found aggregation: 'namespace', 'app', 'program', 'instance', 'dataset' 2) build a scan in the aggregation For scan we set "any" into the dimension values that aggregation has but query doesn't define value for: 'namespace'='ns1', 'app'='myApp', 'program'='myFlow', 'instance'=*, 'dataset'=* Plus specified measure & aggregation?: 'measureName'='read.ops' 'measureType'='COUNTER' 3) While scanning build a table: dimension values -> time -> value. Use measureType as values aggregate function if needed. */ incrementMetric("cube.query.request.count", 1); if (!resolutionToFactTable.containsKey(query.getResolution())) { incrementMetric("cube.query.request.failure.count", 1); throw new IllegalArgumentException( "There's no data aggregated for specified resolution to satisfy the query: " + query.toString()); } // 1) find aggregation to query Aggregation agg; String aggName; if (query.getAggregation() != null) { aggName = query.getAggregation(); agg = aggregations.get(query.getAggregation()); if (agg == null) { incrementMetric("cube.query.request.failure.count", 1); throw new IllegalArgumentException( String.format("Specified aggregation %s is not found in cube aggregations: %s", query.getAggregation(), aggregations.keySet().toString())); } } else { ImmutablePair<String, Aggregation> aggregation = findAggregation(query); if (aggregation == null) { incrementMetric("cube.query.request.failure.count", 1); throw new IllegalArgumentException("There's no data aggregated for specified dimensions " + "to satisfy the query: " + query.toString()); } agg = aggregation.getSecond(); aggName = aggregation.getFirst(); } // tell how many queries end up querying specific pre-aggregated views and resolutions incrementMetric("cube.query.agg." + aggName + ".count", 1); incrementMetric("cube.query.res." + query.getResolution() + ".count", 1); // 2) build a scan for a query List<DimensionValue> dimensionValues = Lists.newArrayList(); for (String dimensionName : agg.getDimensionNames()) { // if not defined in query, will be set as null, which means "any" dimensionValues.add(new DimensionValue(dimensionName, query.getDimensionValues().get(dimensionName))); } FactScan scan = new FactScan(query.getStartTs(), query.getEndTs(), query.getMeasurements().keySet(), dimensionValues); // 3) execute scan query FactTable table = resolutionToFactTable.get(query.getResolution()); FactScanner scanner = table.scan(scan); Table<Map<String, String>, String, Map<Long, Long>> resultMap = getTimeSeries(query, scanner); incrementMetric("cube.query.request.success.count", 1); incrementMetric("cube.query.result.size", resultMap.size()); Collection<TimeSeries> timeSeries = convertToQueryResult(query, resultMap); incrementMetric("cube.query.result.timeseries.count", timeSeries.size()); return timeSeries; }
From source file:com.numb3r3.common.data.SparseMatrix.java
/** * Construct a sparse matrix/*from w w w . j a v a2s. com*/ * * @param dataTable data table * @param columnStructure column structure */ private void construct(Table<Integer, Integer, Double> dataTable, Multimap<Integer, Integer> columnStructure) { int nnz = dataTable.size(); // CRS rowPtr = new int[numRows + 1]; colInd = new int[nnz]; rowData = new double[nnz]; int j = 0; for (int i = 1; i <= numRows; ++i) { Set<Integer> cols = dataTable.row(i - 1).keySet(); rowPtr[i] = rowPtr[i - 1] + cols.size(); for (int col : cols) { colInd[j++] = col; if (col < 0 || col >= numColumns) throw new IllegalArgumentException( "colInd[" + j + "]=" + col + ", which is not a valid column index"); } Arrays.sort(colInd, rowPtr[i - 1], rowPtr[i]); } // CCS if (columnStructure != null) { colPtr = new int[numColumns + 1]; rowInd = new int[nnz]; colData = new double[nnz]; j = 0; for (int i = 1; i <= numColumns; ++i) { // dataTable.col(i-1) is very time-consuming Collection<Integer> rows = columnStructure.get(i - 1); colPtr[i] = colPtr[i - 1] + rows.size(); for (int row : rows) { rowInd[j++] = row; if (row < 0 || row >= numRows) throw new IllegalArgumentException( "rowInd[" + j + "]=" + row + ", which is not a valid row index"); } Arrays.sort(rowInd, colPtr[i - 1], colPtr[i]); } } // set data for (Cell<Integer, Integer, Double> en : dataTable.cellSet()) { int row = en.getRowKey(); int col = en.getColumnKey(); double val = en.getValue(); set(row, col, val); } }
From source file:org.caffinitas.ohc.chunked.OffHeapChunkedMap.java
private void rehash() { Table tab = table; int tableSize = tab.size(); if (tableSize > TWO_POWER_30) { // already at max hash table size return;//from w ww. java 2s.c o m } Table newTable = createTable(tableSize * 2, throwOOME); if (newTable == null) return; int next; for (int part = 0; part < tableSize; part++) for (int hashEntryOffset = tab.getFirst(part); hashEntryOffset != 0L; hashEntryOffset = next) { next = getNext(hashEntryOffset); setNext(hashEntryOffset, 0); newTable.addAsHead(getHash(hashEntryOffset), hashEntryOffset); } threshold = (long) ((float) newTable.size() * loadFactor); table.release(); table = newTable; rehashes++; }
From source file:com.griddynamics.jagger.engine.e1.scenario.DefaultWorkloadSuggestionMaker.java
@Override public WorkloadConfiguration suggest(BigDecimal desiredTps, NodeTpsStatistics statistics, int maxThreads) { log.debug("Going to suggest workload configuration. desired tps {}. statistics {}", desiredTps, statistics); Table<Integer, Integer, Pair<Long, BigDecimal>> threadDelayStats = statistics.getThreadDelayStats(); if (areEqual(desiredTps, BigDecimal.ZERO)) { return WorkloadConfiguration.with(0, 0); }/*from w w w.ja va 2s . c o m*/ if (threadDelayStats.isEmpty()) { throw new IllegalArgumentException("Cannot suggest workload configuration"); } if (!threadDelayStats.contains(CALIBRATION_CONFIGURATION.getThreads(), CALIBRATION_CONFIGURATION.getDelay())) { log.debug("Statistics is empty. Going to return calibration info."); return CALIBRATION_CONFIGURATION; } if (threadDelayStats.size() == 2 && areEqual(threadDelayStats.get(1, 0).getSecond(), BigDecimal.ZERO)) { log.warn("No calibration info. Going to retry."); return CALIBRATION_CONFIGURATION; } Map<Integer, Pair<Long, BigDecimal>> noDelays = threadDelayStats.column(0); Integer threadCount = findClosestPoint(desiredTps, noDelays); if (threadCount == 0) { threadCount = 1; } if (threadCount > maxThreads) { log.warn("{} calculated max {} allowed", threadCount, maxThreads); threadCount = maxThreads; } int currentThreads = statistics.getCurrentWorkloadConfiguration().getThreads(); int diff = threadCount - currentThreads; if (diff > maxDiff) { log.debug("Increasing to {} is required current thread count is {} max allowed diff is {}", new Object[] { threadCount, currentThreads, maxDiff }); return WorkloadConfiguration.with(currentThreads + maxDiff, 0); } if (noDelays.containsKey(threadCount) && noDelays.get(threadCount).getSecond().compareTo(desiredTps) < 0) { if (log.isDebugEnabled()) { log.debug("Statistics for current point has been already calculated and it is less then desired one" + "\nLook like we have achieved maximum for this node." + "\nGoing to help max tps detector."); } int threads = currentThreads; if (threads < maxThreads) { threads++; } return WorkloadConfiguration.with(threads, 0); } if (!threadDelayStats.contains(threadCount, 0)) { return WorkloadConfiguration.with(threadCount, 0); } Map<Integer, Pair<Long, BigDecimal>> delays = threadDelayStats.row(threadCount); if (delays.size() == 1) { int delay = suggestDelay(delays.get(0).getSecond(), threadCount, desiredTps); return WorkloadConfiguration.with(threadCount, delay); } Integer delay = findClosestPoint(desiredTps, threadDelayStats.row(threadCount)); return WorkloadConfiguration.with(threadCount, delay); }
From source file:com.android.tools.idea.uibuilder.property.inspector.InspectorPanel.java
public void setComponent(@NotNull List<NlComponent> components, @NotNull Table<String, String, ? extends NlProperty> properties, @NotNull NlPropertiesManager propertiesManager) { myInspector.setLayout(null);/*ww w .j a v a 2 s . c om*/ myInspector.removeAll(); mySource2GroupMap.clear(); myLabel2GroupMap.clear(); myLabel2ComponentMap.clear(); myRow = 0; if (!components.isEmpty()) { Map<String, NlProperty> propertiesByName = Maps.newHashMapWithExpectedSize(properties.size()); for (NlProperty property : properties.row(ANDROID_URI).values()) { propertiesByName.put(property.getName(), property); } for (NlProperty property : properties.row(AUTO_URI).values()) { propertiesByName.put(property.getName(), property); } for (NlProperty property : properties.row("").values()) { propertiesByName.put(property.getName(), property); } // Add access to known design properties for (NlProperty property : myDesignProperties.getKnownProperties(components)) { propertiesByName.putIfAbsent(property.getName(), property); } myInspectors = myProviders.createInspectorComponents(components, propertiesByName, propertiesManager); int rows = 0; for (InspectorComponent inspector : myInspectors) { rows += inspector.getMaxNumberOfRows(); } rows += myInspectors.size(); // 1 row for each divider (including 1 after the last property) rows += 2; // 1 Line with a link to all properties + 1 row with a spacer on the bottom myInspector.setLayout(createLayoutManager(rows, 2)); for (InspectorComponent inspector : myInspectors) { addSeparator(); inspector.attachToInspector(this); } endGroup(); addSeparator(); // Add a vertical spacer myInspector.add(new Spacer(), new GridConstraints(myRow++, 0, 1, 2, ANCHOR_CENTER, FILL_HORIZONTAL, SIZEPOLICY_CAN_GROW, SIZEPOLICY_CAN_GROW | SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); // Add link to all properties table addLineComponent(myAllPropertiesLink, myRow++); } // These are both important to render the controls correctly the first time: ApplicationManager.getApplication().invokeLater(() -> { updateAfterFilterChange(); if (myActivateEditorAfterLoad) { activatePreferredEditor(myPropertyNameForActivation); } }); }
From source file:matrix.SparseMatrix.java
/** * Construct a sparse matrix/* w w w . j a va 2s. co m*/ * * @param dataTable * data table * @param columnStructure * column structure */ private void construct(Table<Integer, Integer, Float> dataTable, Multimap<Integer, Integer> columnStructure) { int nnz = dataTable.size(); // CRS rowPtr = new int[numRows + 1]; colInd = new int[nnz]; rowData = new float[nnz]; int j = 0; for (int i = 1; i <= numRows; ++i) { Set<Integer> cols = dataTable.row(i - 1).keySet(); rowPtr[i] = rowPtr[i - 1] + cols.size(); for (int col : cols) { colInd[j++] = col; if (col < 0 || col >= numColumns) throw new IllegalArgumentException( "colInd[" + j + "]=" + col + ", which is not a valid column index"); } Arrays.sort(colInd, rowPtr[i - 1], rowPtr[i]); } // CCS if (columnStructure != null) { colPtr = new int[numColumns + 1]; rowInd = new int[nnz]; colData = new float[nnz]; j = 0; for (int i = 1; i <= numColumns; ++i) { // dataTable.col(i-1) is very time-consuming Collection<Integer> rows = columnStructure.get(i - 1); colPtr[i] = colPtr[i - 1] + rows.size(); for (int row : rows) { rowInd[j++] = row; if (row < 0 || row >= numRows) throw new IllegalArgumentException( "rowInd[" + j + "]=" + row + ", which is not a valid row index"); } Arrays.sort(rowInd, colPtr[i - 1], colPtr[i]); } } // set data for (Cell<Integer, Integer, Float> en : dataTable.cellSet()) { int row = en.getRowKey(); int col = en.getColumnKey(); float val = en.getValue(); set(row, col, val); } }
From source file:librec.data.SparseMatrix.java
/** * Construct a sparse matrix//w w w . j a v a 2s .co m * * @param dataTable * data table * @param columnStructure * column structure */ private void construct(Table<Integer, Integer, ? extends Number> dataTable, Multimap<Integer, Integer> columnStructure) { int nnz = dataTable.size(); // CRS rowPtr = new int[numRows + 1]; colInd = new int[nnz]; rowData = new double[nnz]; int j = 0; for (int i = 1; i <= numRows; ++i) { Set<Integer> cols = dataTable.row(i - 1).keySet(); rowPtr[i] = rowPtr[i - 1] + cols.size(); for (int col : cols) { colInd[j++] = col; if (col < 0 || col >= numColumns) throw new IllegalArgumentException( "colInd[" + j + "]=" + col + ", which is not a valid column index"); } Arrays.sort(colInd, rowPtr[i - 1], rowPtr[i]); } // CCS colPtr = new int[numColumns + 1]; rowInd = new int[nnz]; colData = new double[nnz]; j = 0; for (int i = 1; i <= numColumns; ++i) { // dataTable.col(i-1) is more time-consuming than columnStructure.get(i-1) Collection<Integer> rows = columnStructure != null ? columnStructure.get(i - 1) : dataTable.column(i - 1).keySet(); colPtr[i] = colPtr[i - 1] + rows.size(); for (int row : rows) { rowInd[j++] = row; if (row < 0 || row >= numRows) throw new IllegalArgumentException( "rowInd[" + j + "]=" + row + ", which is not a valid row index"); } Arrays.sort(rowInd, colPtr[i - 1], colPtr[i]); } // set data for (Cell<Integer, Integer, ? extends Number> en : dataTable.cellSet()) { int row = en.getRowKey(); int col = en.getColumnKey(); double val = en.getValue().doubleValue(); set(row, col, val); } }
From source file:structure.matrix.SparseMatrix.java
/** * Construct a sparse matrix/*from w w w .ja v a 2 s.c o m*/ * * @param dataTable * data table * @param columnStructure * column structure */ private void construct(Table<Integer, Integer, ? extends Number> dataTable, Multimap<Integer, Integer> columnStructure) { int nnz = dataTable.size(); // CRS rowPtr = new int[numRows + 1]; colInd = new int[nnz]; rowData = new double[nnz]; int j = 0; for (int i = 1; i <= numRows; ++i) { Set<Integer> cols = dataTable.row(i - 1).keySet(); rowPtr[i] = rowPtr[i - 1] + cols.size(); for (int col : cols) { colInd[j++] = col; if (col < 0 || col >= numColumns) throw new IllegalArgumentException( "colInd[" + j + "]=" + col + ", which is not a valid column index"); } Arrays.sort(colInd, rowPtr[i - 1], rowPtr[i]); } // CCS colPtr = new int[numColumns + 1]; rowInd = new int[nnz]; colData = new double[nnz]; j = 0; for (int i = 1; i <= numColumns; ++i) { // dataTable.col(i-1) is more time-consuming than // columnStructure.get(i-1) Collection<Integer> rows = columnStructure != null ? columnStructure.get(i - 1) : dataTable.column(i - 1).keySet(); colPtr[i] = colPtr[i - 1] + rows.size(); for (int row : rows) { rowInd[j++] = row; if (row < 0 || row >= numRows) throw new IllegalArgumentException( "rowInd[" + j + "]=" + row + ", which is not a valid row index"); } Arrays.sort(rowInd, colPtr[i - 1], colPtr[i]); } // set data for (Cell<Integer, Integer, ? extends Number> en : dataTable.cellSet()) { int row = en.getRowKey(); int col = en.getColumnKey(); double val = en.getValue().doubleValue(); set(row, col, val); } }
From source file:accumulo.balancer.GroupBalancer.java
private void balanceExtraExtra(Map<TServerInstance, TserverGroupInfo> tservers, int maxExtraGroups, Moves moves) {//from www .j a va2 s . c om Table<String, TServerInstance, TserverGroupInfo> surplusExtra = HashBasedTable.create(); for (TserverGroupInfo tgi : tservers.values()) { Map<String, Integer> extras = tgi.getExtras(); if (extras.size() > maxExtraGroups) { for (String group : extras.keySet()) { surplusExtra.put(group, tgi.getTserverInstance(), tgi); } } } ArrayList<Pair<String, TServerInstance>> serversGroupsToRemove = new ArrayList<>(); ArrayList<TServerInstance> serversToRemove = new ArrayList<>(); for (TserverGroupInfo destTgi : tservers.values()) { if (surplusExtra.size() == 0) { break; } Map<String, Integer> extras = destTgi.getExtras(); if (extras.size() < maxExtraGroups) { serversToRemove.clear(); serversGroupsToRemove.clear(); for (String group : surplusExtra.rowKeySet()) { if (!extras.containsKey(group)) { TserverGroupInfo srcTgi = surplusExtra.row(group).values().iterator().next(); moves.move(group, 1, srcTgi, destTgi); if (srcTgi.getExtras().size() <= maxExtraGroups) { serversToRemove.add(srcTgi.getTserverInstance()); } else { serversGroupsToRemove .add(new Pair<String, TServerInstance>(group, srcTgi.getTserverInstance())); } if (destTgi.getExtras().size() >= maxExtraGroups || moves.size() >= getMaxMigrations()) { break; } } } if (serversToRemove.size() > 0) { surplusExtra.columnKeySet().removeAll(serversToRemove); } for (Pair<String, TServerInstance> pair : serversGroupsToRemove) { surplusExtra.remove(pair.getFirst(), pair.getSecond()); } if (moves.size() >= getMaxMigrations()) { break; } } } }