private void gotoMinOf(IntTree<V> node) { while(node.size>0) { stack = stack.plus(node); key += node.key; node = node.left; } } }
stack = stack.plus(s); assertEquals("first element should be most recently added", s, stack.get(0)); assertTrue("stack.plus(x).contains(x) should be true!", stack.contains(s));
private void gotoMinOf(IntTree<V> node) { while(node.size>0) { stack = stack.plus(node); key += node.key; node = node.left; } } }
private AmortizedPQueue(AmortizedPQueue<E> queue, E e) { /* Guarantee that there is always at least 1 element * in front, which makes peek worst-case O(1). */ if (queue.front.size() == 0) { this.front = queue.front.plus(e); this.back = queue.back; } else { this.front = queue.front; this.back = queue.back.plus(e); } }
private AmortizedPQueue(AmortizedPQueue<E> queue, E e) { /* Guarantee that there is always at least 1 element * in front, which makes peek worst-case O(1). */ if (queue.front.size() == 0) { this.front = queue.front.plus(e); this.back = queue.back; } else { this.front = queue.front; this.back = queue.back.plus(e); } }
static <E> PStack<E> reverse(final Collection<? extends E> list) { PStack<E> rev = ConsPStack.empty(); for(E e : list) rev = rev.plus(e); return rev; } }
private void gotoMinOf(IntTree<V> node) { while (node.size > 0) { stack = stack.plus(node); key += node.key; node = node.left; } } }
private void gotoMinOf(IntTree<V> node) { while(node.size>0) { stack = stack.plus(node); key += node.key; node = node.left; } } }
/** Make sure the right element is removed */ public void testMinusInt() { // First, let's try a list with distinct elements PStack<String> pstack = ConsPStack.<String>empty().plus("C").plus("B").plus("A"); assertEquals(Arrays.asList("A", "B", "C"), pstack); assertEquals(Arrays.asList("B", "C"), pstack.minus(0)); assertEquals(Arrays.asList("A", "B"), pstack.minus(2)); //Now, let's try duplicates pstack = pstack.plus("B"); assertEquals(Arrays.asList("B", "A", "B", "C"), pstack); assertEquals(Arrays.asList("A", "B", "C"), pstack.minus(0)); assertEquals(Arrays.asList("B", "A", "C"), pstack.minus(2)); }
/** * @param i * @param e * @return * @see org.pcollections.PStack#plus(int, java.lang.Object) */ public PStackX<T> plus(int i, T e) { return this.withStack(stack.plus(i, e)); }
/** * Append an individual case with supplied Cases inserted at index * @see #merge * @param index to insert supplied cases in new Case instance * @param pattern Cases to append / insert * @return New Cases with current and supplied cases */ public Cases<T,R,X> append(int index, Case<T,R,X> pattern) { return this.withCases(cases.plus(index, pattern)); }
@Override default PStackX<T> reverse() { PStack<T> reversed = ConsPStack.empty(); Iterator<T> it = iterator(); while(it.hasNext()) reversed = reversed.plus(0, it.next()); return fromCollection(reversed); }
@Override public List<T> next() { for(int i=0;i<increment && list.get().size()>0;i++) list.mutate(var -> var.minus(0)); for (int i = 0; list.get().size() < windowSize && it.hasNext(); i++) { if(it.hasNext()){ list.mutate(var -> var.plus(Math.max(0,var.size()),it.next())); } } return list.get(); }
@Override public Streamable<T> next() { for(int i=0;i<increment && list.get().size()>0;i++) list.mutate(var -> var.minus(0)); for (int i = 0; list.get().size() < windowSize && it.hasNext(); i++) { if(it.hasNext()){ list.mutate(var -> var.plus(Math.max(0,var.size()),it.next())); } } return Streamable.fromIterable(list.get()); }