com.google.common.collect.MinMaxPriorityQueue.removeAt()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(5.7k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中com.google.common.collect.MinMaxPriorityQueue.removeAt()方法的一些代码示例,展示了MinMaxPriorityQueue.removeAt()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MinMaxPriorityQueue.removeAt()方法的具体详情如下:
包路径:com.google.common.collect.MinMaxPriorityQueue
类名称:MinMaxPriorityQueue
方法名:removeAt

MinMaxPriorityQueue.removeAt介绍

[英]Removes the element at position index.

Normally this method leaves the elements at up to index - 1, inclusive, untouched. Under these circumstances, it returns null.

Occasionally, in order to maintain the heap invariant, it must swap a later element of the list with one before index. Under these circumstances it returns a pair of elements as a MoveDesc. The first one is the element that was previously at the end of the heap and is now at some position before index. The second element is the one that was swapped down to replace the element at index. This fact is used by iterator.remove so as to visit elements during a traversal once and only once.
[中]删除位置索引处的元素。
通常情况下,此方法会保留索引为-1(含索引)的元素不变。在这种情况下,它返回null。
有时,为了保持堆不变,它必须将列表中的后一个元素与索引之前的元素交换。在这些情况下,它将返回一对元素作为MoveDesc。第一个元素以前位于堆的末尾,现在位于索引之前的某个位置。第二个元素是为了替换索引处的元素而向下交换的元素。迭代器使用这个事实。移除以便在遍历过程中访问元素一次且仅一次。

代码示例

代码示例来源:origin: google/guava

/** Removes and returns the value at {@code index}. */
private E removeAndGet(int index) {
 E value = elementData(index);
 removeAt(index);
 return value;
}

代码示例来源:origin: google/j2objc

/** Removes and returns the value at {@code index}. */
private E removeAndGet(int index) {
 E value = elementData(index);
 removeAt(index);
 return value;
}

代码示例来源:origin: wildfly/wildfly

/** Removes and returns the value at {@code index}. */
private E removeAndGet(int index) {
 E value = elementData(index);
 removeAt(index);
 return value;
}

代码示例来源:origin: google/guava

public void testRemoveAt() {
 long seed = new Random().nextLong();
 Random random = new Random(seed);
 int heapSize = 999;
 int numberOfModifications = reduceIterationsIfGwt(500);
 MinMaxPriorityQueue<Integer> mmHeap = MinMaxPriorityQueue.expectedSize(heapSize).create();
 for (int i = 0; i < heapSize; i++) {
  mmHeap.add(random.nextInt());
 }
 for (int i = 0; i < numberOfModifications; i++) {
  mmHeap.removeAt(random.nextInt(mmHeap.size()));
  assertIntactUsingSeed(seed, mmHeap);
  mmHeap.add(random.nextInt());
  assertIntactUsingSeed(seed, mmHeap);
 }
}

代码示例来源:origin: google/guava

public void testRemoveAt_exhaustive() {
 int size = reduceExponentIfGwt(8);
 List<Integer> expected = createOrderedList(size);
 for (Collection<Integer> perm : Collections2.permutations(expected)) {
  for (int i = 0; i < perm.size(); i++) {
   MinMaxPriorityQueue<Integer> q = MinMaxPriorityQueue.create(perm);
   q.removeAt(i);
   assertIntactUsingStartedWith(perm, q);
  }
 }
}

代码示例来源:origin: Nextdoor/bender

/**
 * Removes and returns the value at {@code index}.
 */
private E removeAndGet(int index) {
 E value = elementData(index);
 removeAt(index);
 return value;
}

代码示例来源:origin: com.google.guava/guava-jdk5

/**
 * Removes and returns the value at {@code index}.
 */
private E removeAndGet(int index) {
 E value = elementData(index);
 removeAt(index);
 return value;
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/com.google.guava

/**
 * Removes and returns the value at {@code index}.
 */
private E removeAndGet(int index) {
 E value = elementData(index);
 removeAt(index);
 return value;
}

代码示例来源:origin: org.sonatype.sisu/sisu-guava

/**
 * Removes and returns the value at {@code index}.
 */
private E removeAndGet(int index) {
 E value = elementData(index);
 removeAt(index);
 return value;
}

代码示例来源:origin: org.kill-bill.billing/killbill-platform-osgi-bundles-logger

/** Removes and returns the value at {@code index}. */
private E removeAndGet(int index) {
 E value = elementData(index);
 removeAt(index);
 return value;
}

代码示例来源:origin: com.diffplug.guava/guava-collect

/**
 * Removes and returns the value at {@code index}.
 */
private E removeAndGet(int index) {
  E value = elementData(index);
  removeAt(index);
  return value;
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

/**
 * Removes and returns the value at {@code index}.
 */
private E removeAndGet(int index) {
 E value = elementData(index);
 removeAt(index);
 return value;
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-analytics

/**
 * Removes and returns the value at {@code index}.
 */
private E removeAndGet(int index) {
 E value = elementData(index);
 removeAt(index);
 return value;
}

代码示例来源:origin: com.atlassian.bundles/guava

/**
 * Removes and returns the value at {@code index}.
 */
private E removeAndGet(int index) {
 E value = elementData(index);
 removeAt(index);
 return value;
}

代码示例来源:origin: org.hudsonci.lib.guava/guava

/**
 * Removes and returns the value at {@code index}.
 */
private E removeAndGet(int index) {
 E value = elementData(index);
 removeAt(index);
 return value;
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

/** Removes and returns the value at {@code index}. */
private E removeAndGet(int index) {
 E value = elementData(index);
 removeAt(index);
 return value;
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

/**
 * Removes and returns the value at {@code index}.
 */
private E removeAndGet(int index) {
 E value = elementData(index);
 removeAt(index);
 return value;
}

代码示例来源:origin: com.google.guava/guava-tests

public void testRemoveAt() {
 long seed = new Random().nextLong();
 Random random = new Random(seed);
 int heapSize = 999;
 int numberOfModifications = 500;
 MinMaxPriorityQueue<Integer> mmHeap =
   MinMaxPriorityQueue.expectedSize(heapSize).create();
 for (int i = 0; i < heapSize; i++) {
  mmHeap.add(random.nextInt());
 }
 for (int i = 0; i < numberOfModifications; i++) {
  mmHeap.removeAt(random.nextInt(mmHeap.size()));
  assertTrue("Modification " + i + " of seed " + seed, mmHeap.isIntact());
  mmHeap.add(random.nextInt());
  assertTrue("Modification " + i + " of seed " + seed, mmHeap.isIntact());
 }
}

代码示例来源:origin: com.google.guava/guava-tests

public void testRemoveAt_exhaustive() {
 int size = 8;
 List<Integer> expected = createOrderedList(size);
 for (Collection<Integer> perm : Collections2.permutations(expected)) {
  for (int i = 0; i < perm.size(); i++) {
   MinMaxPriorityQueue<Integer> q = MinMaxPriorityQueue.create(perm);
   q.removeAt(i);
   assertTrue("Remove at " + i + " perm " + perm, q.isIntact());
  }
 }
}

相关文章