Java Code Examples for it.unimi.dsi.fastutil.longs.LongArrayList#size()

The following examples show how to use it.unimi.dsi.fastutil.longs.LongArrayList#size() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RecentlyClickedPostFiltering.java    From StreamingRec with Apache License 2.0 6 votes vote down vote up
@Override
public LongArrayList recommendInternal(ClickData clickData) {
	//filter out items that have not received at last one click in the last time frame
	//first, retrieve the recommendation results of the underlying algorithm
	LongArrayList rec = mainStrategy.recommendInternal(clickData);
	
	//create lists of filtered items and retained items
	LongArrayList filteredRec = new LongArrayList();
	LongArrayList filteredRecNotMatch = new LongArrayList();
	//iterate over the recommendation list of the underlying strategy
	for (int j = 0; j < rec.size(); j++) {
		long i = rec.getLong(j);
		//filter items whose last-clicked timestamp is too old
		if ((itemClickTime.containsKey(i)) && ((clickData.click.timestamp.getTime()-itemClickTime.get(i))<filterTime)) {
			filteredRec.add(i);
		} else if (fallback) {
			//if we have a fallback, add the filtered item to the fallback list
			filteredRecNotMatch.add(i);
		}
	}
	//merge the filtered list with the fallback list (empty in case fallback==false)
	filteredRec.addAll(filteredRecNotMatch);
	//return the filtered list
	return filteredRec;
}
 
Example 2
Source File: PopularityPostFiltering.java    From StreamingRec with Apache License 2.0 6 votes vote down vote up
@Override
public LongArrayList recommendInternal(ClickData clickData) {
	//filter out items with low overall click counts
	//first, retrieve the recommendation results of the underlying algorithm
	LongArrayList rec = mainStrategy.recommendInternal(clickData);
	
	//create lists of filtered items and retained items
	LongArrayList filteredRec = new LongArrayList();
	LongArrayList filteredRecNotMatch = new LongArrayList();
	//iterate over the recommendation list of the underlying strategy
	for (int j = 0; j < rec.size(); j++) {
		long i = rec.getLong(j);
		//filter items if they do not have enough clicks
		if ((itemClickCount.containsKey(i)) && (itemClickCount.get(i) >= minClickCount)) {
			filteredRec.add(i);
		} else if (fallback) {
			//if we have a fallback, add the filtered item to the fallback list
			filteredRecNotMatch.add(i);
		}
	}
	//merge the filtered list with the fallback list (empty in case fallback==false)
	filteredRec.addAll(filteredRecNotMatch);
	//return the filtered list
	return filteredRec;
}
 
Example 3
Source File: SnapshotCodecV4.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
@Override
protected void encodeInProgress(BinaryEncoder encoder, Map<Long, TransactionManager.InProgressTx> inProgress)
    throws IOException {

  if (!inProgress.isEmpty()) {
    encoder.writeInt(inProgress.size());
    for (Map.Entry<Long, TransactionManager.InProgressTx> entry : inProgress.entrySet()) {
      encoder.writeLong(entry.getKey()); // tx id
      encoder.writeLong(entry.getValue().getExpiration());
      encoder.writeLong(entry.getValue().getVisibilityUpperBound());
      encoder.writeInt(entry.getValue().getType().ordinal());
      // write checkpoint tx IDs
      LongArrayList checkpointPointers = entry.getValue().getCheckpointWritePointers();
      if (!checkpointPointers.isEmpty()) {
        encoder.writeInt(checkpointPointers.size());
        for (int i = 0; i < checkpointPointers.size(); i++) {
          encoder.writeLong(checkpointPointers.getLong(i));
        }
      }
      encoder.writeInt(0);
    }
  }
  encoder.writeInt(0); // zero denotes end of list as per AVRO spec
}
 
Example 4
Source File: MultiThreadedPageRank.java    From GraphJet with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs this object for running PageRank over a directed graph.
 *
 * @param graph          the directed graph
 * @param nodes          nodes in the graph
 * @param maxNodeId      maximum node id
 * @param dampingFactor  damping factor
 * @param maxIterations  maximum number of iterations to run
 * @param tolerance      L1 norm threshold for convergence
 * @param threads        number of threads
 */
public MultiThreadedPageRank(OutIndexedDirectedGraph graph, LongArrayList nodes,
                             long maxNodeId, double dampingFactor, int maxIterations,
                             double tolerance, int threads) {
  if (maxNodeId > Integer.MAX_VALUE) {
    throw new UnsupportedOperationException("maxNodeId exceeds Integer.MAX_VALUE!");
  }

  this.graph = graph;
  this.nodes = nodes;
  this.maxNodeId = maxNodeId;
  this.dampingFactor = dampingFactor;
  this.nodeCount = nodes.size();
  this.maxIterations = maxIterations;
  this.tolerance = tolerance;
  this.threads = threads;
}
 
Example 5
Source File: SimpleConditionTraverser.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
public List<LongArrayList> calculateConditions(PositionListIndex partialUnique,
                                               PositionListIndex PLICondition,
                                               int frequency,
                                               List<LongArrayList> unsatisfiedClusters) {
  List<LongArrayList> result = new LinkedList<>();
  Long2LongOpenHashMap uniqueHashMap = partialUnique.asHashMap();
  LongArrayList touchedClusters = new LongArrayList();
  nextCluster:
  for (LongArrayList cluster : PLICondition.getClusters()) {
    if (cluster.size() < frequency) {
      continue;
    }
    int unsatisfactionCount = 0;
    touchedClusters.clear();
    for (long rowNumber : cluster) {
      if (uniqueHashMap.containsKey(rowNumber)) {
        if (touchedClusters.contains(uniqueHashMap.get(rowNumber))) {
          unsatisfactionCount++;
        } else {
          touchedClusters.add(uniqueHashMap.get(rowNumber));
        }
      }
    }
    if (unsatisfactionCount == 0) {
      result.add(cluster);
    } else {
      if ((cluster.size() - unsatisfactionCount) >= frequency) {
        unsatisfiedClusters.add(cluster);
      }
    }
  }
  return result;
}
 
Example 6
Source File: RecencyPostFiltering.java    From StreamingRec with Apache License 2.0 5 votes vote down vote up
@Override
public LongArrayList recommendInternal(ClickData clickData) {
	//filter out items that have been release too long ago
	//first, retrieve the recommendation results of the underlying algorithm
	LongArrayList rec = mainStrategy.recommendInternal(clickData);
	
	//create lists of filtered items and retained items
	LongArrayList filteredRec = new LongArrayList();
	LongArrayList filteredRecNotMatch = new LongArrayList();
	//iterate over the recommendation list of the underlying strategy
	for (int j = 0; j < rec.size(); j++) {
		long i = rec.getLong(j);
		// filter item based on the difference between the current (simulation) time and
		// the time of publication
		if ((clickData.click.timestamp.getTime() - timestampMap.get(i)) <= filterTime
				&& (clickData.click.timestamp.getTime() - timestampMap.get(i)) > 0) {
			filteredRec.add(i);
		} else if (fallback) {
			//if we have a fallback, add the filtered item to the fallback list
			filteredRecNotMatch.add(i);
		}
	}
	//merge the filtered list with the fallback list (empty in case fallback==false)
	filteredRec.addAll(filteredRecNotMatch);
	//return the filtered list
	return filteredRec;

}
 
Example 7
Source File: PagesSpatialIndexSupplier.java    From presto with Apache License 2.0 4 votes vote down vote up
private static STRtree buildRTree(LongArrayList addresses, List<List<Block>> channels, int geometryChannel, Optional<Integer> radiusChannel, Optional<Integer> partitionChannel)
{
    STRtree rtree = new STRtree();
    Operator relateOperator = OperatorFactoryLocal.getInstance().getOperator(Operator.Type.Relate);

    for (int position = 0; position < addresses.size(); position++) {
        long pageAddress = addresses.getLong(position);
        int blockIndex = decodeSliceIndex(pageAddress);
        int blockPosition = decodePosition(pageAddress);

        Block block = channels.get(geometryChannel).get(blockIndex);
        // TODO Consider pushing is-null and is-empty checks into a filter below the join
        if (block.isNull(blockPosition)) {
            continue;
        }

        Slice slice = block.getSlice(blockPosition, 0, block.getSliceLength(blockPosition));
        OGCGeometry ogcGeometry = deserialize(slice);
        verifyNotNull(ogcGeometry);
        if (ogcGeometry.isEmpty()) {
            continue;
        }

        double radius = radiusChannel.map(channel -> DOUBLE.getDouble(channels.get(channel).get(blockIndex), blockPosition)).orElse(0.0);
        if (radius < 0) {
            continue;
        }

        if (radiusChannel.isEmpty()) {
            // If radiusChannel is supplied, this is a distance query, for which our acceleration won't help.
            accelerateGeometry(ogcGeometry, relateOperator);
        }

        int partition = -1;
        if (partitionChannel.isPresent()) {
            Block partitionBlock = channels.get(partitionChannel.get()).get(blockIndex);
            partition = toIntExact(INTEGER.getLong(partitionBlock, blockPosition));
        }

        rtree.insert(getEnvelope(ogcGeometry, radius), new GeometryWithPosition(ogcGeometry, partition, position));
    }

    rtree.build();
    return rtree;
}
 
Example 8
Source File: CollectionUtils.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
public static int countNotN(LongArrayList numbers, int numberNotToCount) {
	return numbers.size() - countN(numbers, numberNotToCount);
}
 
Example 9
Source File: ConditionEntry.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
public ConditionEntry(ColumnCombinationBitset condition, LongArrayList cluster) {
  this.condition = new ColumnCombinationBitset(condition);
  this.cluster = cluster.clone();
  this.coverage = (float) ((cluster.size() * 100.0) / Dcucc.numberOfTuples);
}