本文整理了Java中com.google.common.collect.MinMaxPriorityQueue.size()
方法的一些代码示例,展示了MinMaxPriorityQueue.size()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MinMaxPriorityQueue.size()
方法的具体详情如下:
包路径:com.google.common.collect.MinMaxPriorityQueue
类名称:MinMaxPriorityQueue
方法名:size
暂无
代码示例来源:origin: apache/hive
public int size() {
return indexes.size();
}
代码示例来源:origin: apache/hive
public Iterable<Integer> indexes() {
Integer[] array = indexes.toArray(new Integer[indexes.size()]);
Arrays.sort(array, 0, array.length, C);
return Arrays.asList(array);
}
}
代码示例来源: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
/** This tests a more obscure special case, but otherwise similar to above. */
public void testInvalidatingRemove2() {
MinMaxPriorityQueue<Integer> mmHeap = MinMaxPriorityQueue.create();
List<Integer> values =
Lists.newArrayList(
1, 20, 1000, 2, 3, 30, 40, 10, 11, 12, 13, 300, 400, 500, 600, 4, 5, 6, 7, 8, 9, 4, 5,
200, 250);
mmHeap.addAll(values);
assertEquals(25, mmHeap.size());
assertTrue("Heap is not intact initially", mmHeap.isIntact());
mmHeap.remove(2);
assertEquals(24, mmHeap.size());
assertTrue("Heap is not intact after remove()", mmHeap.isIntact());
values.removeAll(Lists.newArrayList(2));
assertEquals(values.size(), mmHeap.size());
assertTrue(values.containsAll(mmHeap));
assertTrue(mmHeap.containsAll(values));
}
代码示例来源:origin: google/guava
public void testRandomAddsAndRemoves_duplicateElements() {
Random random = new Random(0);
Multiset<Element> elements = HashMultiset.create();
MinMaxPriorityQueue<Element> queue = MinMaxPriorityQueue.create();
int range = Element.values().length;
for (int iter = 0; iter < reduceIterationsIfGwt(1000); iter++) {
for (int i = 0; i < 100; i++) {
Element element = Element.values()[random.nextInt(range)];
elements.add(element);
queue.add(element);
}
Iterator<Element> queueIterator = queue.iterator();
int remaining = queue.size();
while (queueIterator.hasNext()) {
Element element = queueIterator.next();
remaining--;
assertThat(elements).contains(element);
if (random.nextBoolean()) {
elements.remove(element);
queueIterator.remove();
}
}
assertThat(remaining).isEqualTo(0);
assertIntact(queue);
assertThat(queue).containsExactlyElementsIn(elements);
}
}
代码示例来源:origin: google/guava
/**
* This tests a special case of the removeAt() call. Moving an element sideways on the heap could
* break the invariants. Sometimes we need to bubble an element up instead of trickling down. See
* implementation.
*/
public void testInvalidatingRemove() {
MinMaxPriorityQueue<Integer> mmHeap = MinMaxPriorityQueue.create();
mmHeap.addAll(
Lists.newArrayList(1, 20, 1000, 2, 3, 30, 40, 10, 11, 12, 13, 300, 400, 500, 600));
assertEquals(15, mmHeap.size());
assertTrue("Heap is not intact initially", mmHeap.isIntact());
mmHeap.remove(12);
assertEquals(14, mmHeap.size());
assertTrue("Heap is not intact after remove()", mmHeap.isIntact());
}
代码示例来源:origin: google/guava
public void testRemove() {
MinMaxPriorityQueue<Integer> mmHeap = MinMaxPriorityQueue.create();
mmHeap.addAll(Lists.newArrayList(1, 2, 3, 4, 47, 1, 5, 3, 0));
assertTrue("Heap is not intact initally", mmHeap.isIntact());
assertEquals(9, mmHeap.size());
mmHeap.remove(5);
assertEquals(8, mmHeap.size());
assertTrue("Heap is not intact after remove()", mmHeap.isIntact());
assertEquals(47, (int) mmHeap.pollLast());
assertEquals(4, (int) mmHeap.pollLast());
mmHeap.removeAll(Lists.newArrayList(2, 3));
assertEquals(3, mmHeap.size());
assertTrue("Heap is not intact after removeAll()", mmHeap.isIntact());
}
代码示例来源:origin: google/guava
assertEquals(heapSize, mmHeap.size());
int currentHeapSize = heapSize;
for (int i = 0; i < numberOfModifications; i++) {
assertEquals(currentHeapSize, mmHeap.size());
assertEquals(currentHeapSize, mmHeap.size());
assertIntact(mmHeap);
代码示例来源:origin: google/guava
public void testIteratorInvalidatingIteratorRemove() {
MinMaxPriorityQueue<Integer> mmHeap = MinMaxPriorityQueue.create();
mmHeap.addAll(Lists.newArrayList(1, 20, 100, 2, 3, 30, 40));
assertEquals(7, mmHeap.size());
assertTrue("Heap is not intact initially", mmHeap.isIntact());
Iterator<Integer> it = mmHeap.iterator();
assertEquals((Integer) 40, it.next());
assertFalse(it.hasNext());
assertEquals(6, mmHeap.size());
assertTrue("Heap is not intact after remove()", mmHeap.isIntact());
assertFalse(mmHeap.contains(2));
代码示例来源:origin: google/guava
public void testCreation_withContents() {
MinMaxPriorityQueue<Integer> queue = MinMaxPriorityQueue.create(NUMBERS);
assertEquals(6, queue.size());
assertEquals(11, queue.capacity());
checkUnbounded(queue);
checkNatural(queue);
}
代码示例来源:origin: google/guava
public void testRemoveFromStringHeap() {
MinMaxPriorityQueue<String> mmHeap = MinMaxPriorityQueue.expectedSize(5).create();
Collections.addAll(mmHeap, "foo", "bar", "foobar", "barfoo", "larry", "sergey", "eric");
assertTrue("Heap is not intact initially", mmHeap.isIntact());
assertEquals("bar", mmHeap.peek());
assertEquals("sergey", mmHeap.peekLast());
assertEquals(7, mmHeap.size());
assertTrue("Could not remove larry", mmHeap.remove("larry"));
assertEquals(6, mmHeap.size());
assertFalse("heap contains larry which has been removed", mmHeap.contains("larry"));
assertTrue("heap does not contain sergey", mmHeap.contains("sergey"));
assertTrue("Could not remove larry", mmHeap.removeAll(Lists.newArrayList("sergey", "eric")));
assertFalse("Could remove nikesh which is not in the heap", mmHeap.remove("nikesh"));
assertEquals(4, mmHeap.size());
}
代码示例来源:origin: google/guava
public void testCreation_expectedSize_withContents() {
MinMaxPriorityQueue<Integer> queue = MinMaxPriorityQueue.expectedSize(8).create(NUMBERS);
assertEquals(6, queue.size());
assertEquals(8, queue.capacity());
checkUnbounded(queue);
checkNatural(queue);
}
代码示例来源:origin: google/guava
public void testCreation_maximumSize_withContents() {
MinMaxPriorityQueue<Integer> queue = MinMaxPriorityQueue.maximumSize(42).create(NUMBERS);
assertEquals(6, queue.size());
assertEquals(11, queue.capacity());
assertEquals(42, queue.maximumSize);
checkNatural(queue);
}
代码示例来源:origin: google/guava
public void testCreation_comparator_withContents() {
MinMaxPriorityQueue<Integer> queue =
MinMaxPriorityQueue.orderedBy(SOME_COMPARATOR).create(NUMBERS);
assertEquals(6, queue.size());
assertEquals(11, queue.capacity());
checkUnbounded(queue);
assertSame(SOME_COMPARATOR, queue.comparator());
}
代码示例来源:origin: forcedotcom/phoenix
public int size() {
if (flushBuffer)
return flushedCount;
return results.size();
}
代码示例来源:origin: google/guava
public void testCreation_allOptions() {
MinMaxPriorityQueue<Integer> queue =
MinMaxPriorityQueue.orderedBy(SOME_COMPARATOR)
.expectedSize(8)
.maximumSize(42)
.create(NUMBERS);
assertEquals(6, queue.size());
assertEquals(8, queue.capacity());
assertEquals(42, queue.maximumSize);
assertSame(SOME_COMPARATOR, queue.comparator());
}
代码示例来源:origin: google/guava
public void testContains() {
MinMaxPriorityQueue<Integer> mmHeap = MinMaxPriorityQueue.create();
mmHeap.addAll(Lists.newArrayList(1, 1, 2));
assertEquals(3, mmHeap.size());
assertFalse("Heap does not contain null", mmHeap.contains(null));
assertFalse("Heap does not contain 3", mmHeap.contains(3));
assertFalse("Heap does not contain 3", mmHeap.remove(3));
assertEquals(3, mmHeap.size());
assertTrue("Heap is not intact after remove()", mmHeap.isIntact());
assertTrue("Heap contains two 1's", mmHeap.contains(1));
assertTrue("Heap contains two 1's", mmHeap.remove(1));
assertTrue("Heap contains 1", mmHeap.contains(1));
assertTrue("Heap contains 1", mmHeap.remove(1));
assertFalse("Heap does not contain 1", mmHeap.contains(1));
assertTrue("Heap contains 2", mmHeap.remove(2));
assertEquals(0, mmHeap.size());
assertFalse("Heap does not contain anything", mmHeap.contains(1));
assertFalse("Heap does not contain anything", mmHeap.remove(2));
}
代码示例来源:origin: forcedotcom/phoenix
if (added) {
maxResultSize = Math.max(maxResultSize, resultSize);
totalResultSize = limit < 0 ? (totalResultSize + resultSize) : maxResultSize * results.size();
if (totalResultSize >= thresholdBytes) {
this.file = File.createTempFile(UUID.randomUUID().toString(), null);
writeBuffer = fc.map(MapMode.READ_WRITE, writeIndex, mappingSize);
int resSize = results.size();
for (int i = 0; i < resSize; i++) {
int totalLen = 0;
flushedCount = results.size();
results.clear();
flushBuffer = true;
代码示例来源:origin: uk.co.nichesolutions.presto/presto-main
private long addRow(Block[] row)
{
checkState(candidateRows.size() < maxRowCountPerPartition);
long sizeDelta = sizeOfRow(row);
candidateRows.add(row);
return sizeDelta;
}
代码示例来源:origin: com.google.guava/guava-tests
public void testCreation_comparator_withContents() {
MinMaxPriorityQueue<Integer> queue = MinMaxPriorityQueue
.orderedBy(SOME_COMPARATOR)
.create(NUMBERS);
assertEquals(6, queue.size());
assertEquals(11, queue.capacity());
checkUnbounded(queue);
assertSame(SOME_COMPARATOR, queue.comparator());
}
内容来源于网络,如有侵权,请联系作者删除!