当前位置: 首页>>代码示例>>Java>>正文


Java PriorityQueue.addAll方法代码示例

本文整理汇总了Java中java.util.PriorityQueue.addAll方法的典型用法代码示例。如果您正苦于以下问题:Java PriorityQueue.addAll方法的具体用法?Java PriorityQueue.addAll怎么用?Java PriorityQueue.addAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.PriorityQueue的用法示例。


在下文中一共展示了PriorityQueue.addAll方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: insertMoves

import java.util.PriorityQueue; //导入方法依赖的package包/类
private void insertMoves() {
  SpillMoveSet spillMoves =
      new SpillMoveSet(this, code, numberOfArgumentRegisters + NUMBER_OF_SENTINEL_REGISTERS);
  for (LiveIntervals intervals : liveIntervals) {
    if (intervals.hasSplits()) {
      LiveIntervals current = intervals;
      PriorityQueue<LiveIntervals> sortedChildren =
          new PriorityQueue<>((o1, o2) -> Integer.compare(o1.getStart(), o2.getStart()));
      sortedChildren.addAll(current.getSplitChildren());
      for (LiveIntervals split = sortedChildren.poll();
          split != null;
          split = sortedChildren.poll()) {
        int position = split.getStart();
        spillMoves.addSpillOrRestoreMove(toGapPosition(position), split, current);
        current = split;
      }
    }
  }

  resolveControlFlow(spillMoves);
  firstParallelMoveTemporary = maxRegisterNumber + 1;
  maxRegisterNumber += spillMoves.scheduleAndInsertMoves(maxRegisterNumber + 1);
}
 
开发者ID:inferjay,项目名称:r8,代码行数:24,代码来源:LinearScanRegisterAllocator.java

示例2: print

import java.util.PriorityQueue; //导入方法依赖的package包/类
public void print(CfgPrinter printer, String title) {
  printer.begin("intervals");
  printer.print("name \"").append(title).append("\"").ln();
  PriorityQueue<LiveIntervals> sortedIntervals =
      new PriorityQueue<>((o1, o2) -> Integer.compare(o1.getStart(), o2.getStart()));
  sortedIntervals.addAll(liveIntervals);
  for (LiveIntervals interval = sortedIntervals.poll();
      interval != null;
      interval = sortedIntervals.poll()) {
    Value value = interval.getValue();
    if (interval.getRanges().get(0).isInfinite()) {
      // Skip argument sentinels.
      continue;
    }
    interval.print(printer, value.getNumber(), value.getNumber());
  }
  printer.end("intervals");
}
 
开发者ID:inferjay,项目名称:r8,代码行数:19,代码来源:LinearScanRegisterAllocator.java

示例3: shortest

import java.util.PriorityQueue; //导入方法依赖的package包/类
protected void shortest()
{
    IVertex s = _startVertex;
    IVertex u;

    INITIALIZE_SINGLE_SOURCE(s);

    HashSet<IVertex> S = new HashSet<>();

    PriorityQueue<IVertex> Q = new PriorityQueue<>(_graph_input.vertices().size(), this.new keyComparator());
    Q.addAll(_graph_input.vertices());

    while (!Q.isEmpty()) {
        u = Q.poll();
        S.add(u);

        for (IVertex v : _graph_input.getNeighborsOf(u)) {
            RELAX(u, v);
        }
    }

    // create the tree

    _result_algorithm = new ShortestPathsTree(_PIE, _startVertex, _DISTANCE);
    _result_algorithm.setTag(getTag() + " result");
}
 
开发者ID:Erdos-Graph-Framework,项目名称:Erdos,代码行数:27,代码来源:DijkstraShortestPath.java

示例4: nextGeneration

import java.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * Advances the current population to the next generation. All objects are cloned during
 * the process.
 */
@SuppressWarnings("unchecked")
public void nextGeneration() {
	PriorityQueue<T> newPopulation = new PriorityQueue<T>(getPopulationSize(), new FitnessComparator());

	//Take best n and copy into new population
	newPopulation.addAll(getTopN(config.getNumElite()));

	int fitnessSum = getFitnessSum();
	
	while (newPopulation.size() < config.getPopulationSize()) {
		T mommy = getWeightedOrganism(fitnessSum);
		T daddy = getWeightedOrganism(fitnessSum);
		
		T offspring = mommy;
		if (shouldCrossover()) {
			offspring = (T) mommy.breed(daddy);
		}
		
		if (shouldMutate()) {
			offspring = (T) offspring.mutate();
		}
		newPopulation.offer(offspring);
	}
	
	generation++;
	population = newPopulation;
}
 
开发者ID:ryantate314,项目名称:genetic-one-tough-puzzle-solver,代码行数:32,代码来源:Ecosystem.java

示例5: spreadLightingDijkstra

import java.util.PriorityQueue; //导入方法依赖的package包/类
void spreadLightingDijkstra(List<LightingPoint> sources) {
	if (sources.isEmpty())
		return;
	HashSet<LightingPoint> out = new HashSet<>();
	PriorityQueue<LightingPoint> in = new PriorityQueue<>(sources.size(),
               new LightingPoint.LightValueComparator());
	// consider that the input sources are done (this is not a good assumption if different
	// light sources have different values......)
	out.addAll(sources);
	
	in.addAll(sources);
	while (!in.isEmpty()) {
		LightingPoint current = in.poll();
		out.add(current);
		
		if (current.lightValue <= lightValues[current.x][current.y] || current.lightValue < 0) {
			continue;
		}
		lightValues[current.x][current.y] = current.lightValue;
		lightFlow[current.x][current.y] = current.flow;
		if (lightFlow[current.x][current.y] == Direction.SOURCE
				&& current.flow != Direction.SOURCE) {
			System.out.println("There's a bug in the source map!");
		}
		List<LightingPoint> neighbors = getNeighbors(current);
		for (LightingPoint next : neighbors) {
			if (out.contains(next)) {
				continue;
			}
			in.add(next);
		}
	}
}
 
开发者ID:DreamBlocks,项目名称:DreamBlocks,代码行数:34,代码来源:LightingEngine.java

示例6: testConstructor7

import java.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * The comparator used in constructor is used
 */
public void testConstructor7() {
    MyReverseComparator cmp = new MyReverseComparator();
    PriorityQueue q = new PriorityQueue(SIZE, cmp);
    assertEquals(cmp, q.comparator());
    Integer[] ints = new Integer[SIZE];
    for (int i = 0; i < SIZE; ++i)
        ints[i] = new Integer(i);
    q.addAll(Arrays.asList(ints));
    for (int i = SIZE - 1; i >= 0; --i)
        assertEquals(ints[i], q.poll());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:PriorityQueueTest.java

示例7: testAddAll1

import java.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * addAll(null) throws NPE
 */
public void testAddAll1() {
    PriorityQueue q = new PriorityQueue(1);
    try {
        q.addAll(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:PriorityQueueTest.java

示例8: testAddAll2

import java.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * addAll of a collection with null elements throws NPE
 */
public void testAddAll2() {
    PriorityQueue q = new PriorityQueue(SIZE);
    try {
        q.addAll(Arrays.asList(new Integer[SIZE]));
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:PriorityQueueTest.java

示例9: testAddAll3

import java.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * addAll of a collection with any null elements throws NPE after
 * possibly adding some elements
 */
public void testAddAll3() {
    PriorityQueue q = new PriorityQueue(SIZE);
    Integer[] ints = new Integer[SIZE];
    for (int i = 0; i < SIZE - 1; ++i)
        ints[i] = new Integer(i);
    try {
        q.addAll(Arrays.asList(ints));
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:PriorityQueueTest.java

示例10: assignLeftOvers

import java.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * assign the remaining work units to hosts/fragments based on least load
 * @param leftOvers
 */
private void assignLeftOvers(List<WorkWrapper> leftOvers) {
  PriorityQueue<FragmentWork> queue = new PriorityQueue<>();
  List<FragmentWork> fragments = getFragments();
  queue.addAll(fragments);

  for (WorkWrapper work : leftOvers) {
    FragmentWork fragment = queue.poll();
    fragment.addWork(work);
    queue.add(fragment);
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:16,代码来源:AssignmentCreator2.java

示例11: flatten

import java.util.PriorityQueue; //导入方法依赖的package包/类
public ClusterModel flatten(HierarchicalClusterModel model, ExampleSet exampleSet) throws OperatorException {
	HierarchicalClusterNode root = model.getRootNode();
	int numberOfClusters = getParameterAsInt(PARAMETER_NUMBER_OF_CLUSTER);

	// creating priorityQueue using reversing comparator
	PriorityQueue<HierarchicalClusterNode> queue = new PriorityQueue<HierarchicalClusterNode>(numberOfClusters,
			new Comparator<HierarchicalClusterNode>() {

		@Override
		public int compare(HierarchicalClusterNode o1, HierarchicalClusterNode o2) {
			int value = -1 * Double.compare(o1.getDistance(), o2.getDistance());
			if (value != 0) {
				return value;
			} else {
				return -1 * Double.compare(o1.getNumberOfExamplesInSubtree(), o2.getNumberOfExamplesInSubtree());
			}
		}
	});

	// Iteratively descend within graph by splitting at greatest node until queue is full or
	// enough leafs are collected
	LinkedList<HierarchicalClusterNode> leafs = new LinkedList<HierarchicalClusterNode>();
	queue.add(root);
	while (queue.size() < numberOfClusters - leafs.size()) {
		HierarchicalClusterNode topNode = queue.poll();
		if (topNode.getSubNodes().size() > 0) {
			queue.addAll(topNode.getSubNodes());
		} else {
			leafs.add(topNode);
		}
	}
	queue.addAll(leafs);

	// construct flat cluster model from nodes
	ClusterModel flatModel = new ClusterModel(exampleSet, numberOfClusters,
			getParameterAsBoolean(PARAMETER_ADD_AS_LABEL), getParameterAsBoolean(PARAMETER_REMOVE_UNLABELED));
	int i = 0;
	for (HierarchicalClusterNode node : queue) {
		Cluster flatCluster = flatModel.getCluster(i);
		for (Object exampleId : node.getExampleIdsInSubtree()) {
			flatCluster.assignExample(exampleId);
		}
		i++;
	}

	// delivering adapted example set
	if (exampleSetOutput.isConnected()) {
		exampleSetOutput.deliver(flatModel.apply((ExampleSet) exampleSet.clone()));
	}
	return flatModel;
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:52,代码来源:FlattenClusterModel.java

示例12: realMain

import java.util.PriorityQueue; //导入方法依赖的package包/类
private static void realMain(String[] args) throws Throwable {
    final PriorityQueue<Integer> q = new PriorityQueue<>();
    Iterator<Integer> it;

    //----------------------------------------------------------------
    // Empty
    //----------------------------------------------------------------
    checkQ(q);
    check(q.isEmpty());
    check(! q.contains(1));
    it = q.iterator();
    removeIsCurrentlyIllegal(it);
    noMoreElements(it);
    q.clear();
    check(q.isEmpty());

    //----------------------------------------------------------------
    // Singleton
    //----------------------------------------------------------------
    q.add(1);
    checkQ(q, 1);
    check(! q.isEmpty());
    check(q.contains(1));
    it = q.iterator();
    removeIsCurrentlyIllegal(it);
    check(it.hasNext());
    equal(it.next(), 1);
    noMoreElements(it);
    remove(it, q);
    check(q.isEmpty());
    noMoreElements(it);
    checkQ(q);
    q.clear();

    //----------------------------------------------------------------
    // @see PriorityQueue.forgetMeNot
    //----------------------------------------------------------------
    final Integer[] a = {0, 4, 1, 6, 7, 2, 3}; // Carefully chosen!
    q.addAll(Arrays.asList(a));
    checkQ(q, a);
    it = q.iterator();
    checkQ(q, a);
    removeIsCurrentlyIllegal(it);
    checkQ(q, a);
    check(it.hasNext());
    removeIsCurrentlyIllegal(it);
    checkQ(q, a);
    check(it.hasNext());
    equal(it.next(), 0);
    equal(it.next(), 4);
    equal(it.next(), 1);
    equal(it.next(), 6);
    check(it.hasNext());
    checkQ(q, a);
    remove(it, q);
    checkQ(q, 0, 3, 1, 4, 7, 2);
    check(it.hasNext());
    removeIsCurrentlyIllegal(it);
    equal(it.next(), 7);
    remove(it, q);
    checkQ(q, 0, 2, 1, 4, 3);
    check(it.hasNext());
    removeIsCurrentlyIllegal(it);
    check(it.hasNext());
    equal(it.next(), 3);
    equal(it.next(), 2);
    check(! it.hasNext());
    remove(it, q);
    checkQ(q, 0, 3, 1, 4);
    check(! it.hasNext());
    noMoreElements(it);
    removeIsCurrentlyIllegal(it);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:74,代码来源:ForgetMeNot.java


注:本文中的java.util.PriorityQueue.addAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。