public AmortizedPQueue<E> minus() { if (size() == 0) { return this; } int fsize = front.size(); if (fsize == 0) { //If there's nothing on front, dump back onto front //(as stacks, this goes in reverse like we want) //and take one off. return new AmortizedPQueue<E>(Empty.<E>stack().plusAll(back), Empty.<E>stack()).minus(); } else if (fsize == 1) { //If there's one element on front, dump back onto front, //but now we've already removed the head. return new AmortizedPQueue<E>(Empty.<E>stack().plusAll(back), Empty.<E>stack()); } else { //If there's more than one on front, we pop one off. return new AmortizedPQueue<E>(front.minus(0), back); } }
public AmortizedPQueue<E> minus() { if (size() == 0) { return this; } int fsize = front.size(); if (fsize == 0) { //If there's nothing on front, dump back onto front //(as stacks, this goes in reverse like we want) //and take one off. return new AmortizedPQueue<E>(Empty.<E>stack().plusAll(back), Empty.<E>stack()).minus(); } else if (fsize == 1) { //If there's one element on front, dump back onto front, //but now we've already removed the head. return new AmortizedPQueue<E>(Empty.<E>stack().plusAll(back), Empty.<E>stack()); } else { //If there's more than one on front, we pop one off. return new AmortizedPQueue<E>(front.minus(0), back); } }
public PStack<T> plusAll(Collection<? extends T> list) { return boxed.plusAll(list); } public PStack<T> with(int i, T e) {
public PStack<T> plusAll(int i, Collection<? extends T> list) { return boxed.plusAll(i, list); } public PStack<T> minus(Object e) {
/** * @param i * @param list * @return * @see org.pcollections.PStack#plusAll(int, java.util.Collection) */ public PStackX<T> plusAll(int i, Collection<? extends T> list) { return this.withStack(stack.plusAll(i, list)); }
/** * @param list * @return * @see org.pcollections.MapPSet#plusAll(java.util.Collection) */ public PStackX<T> plusAll(Collection<? extends T> list) { return this.withStack(stack.plusAll(list)); }
private static <T> PStackType<T> concat(PStack<T> l1, PStack<T> l2){ return PStackType.widen(l1.plusAll(l2)); } private <T> PStackType<T> of(T value){
private static <T> LinkedListX<T> concat(PStack<T> l1, PStack<T> l2){ return LinkedListX.fromIterable(l1.plusAll(l2)); } private <T> LinkedListX<T> of(T value){
/** * Merge two cases, with supplied Cases added after current Cases * @see #append * * @param patterns Cases to merge to this set * @return New merged Cases */ public Cases<T,R,X> merge(Cases<T, R,X> patterns){ return this.withCases(cases.plusAll(size(), patterns.cases)); }
@Override public LinkedListX<T> plusAll(int i, Collection<? extends T> list) { return from(get().plusAll(i,list)); }
@Override public LinkedListX<T> plusAll(Collection<? extends T> list) { return from(get().plusAll(list)); }
stack, reverse(stack2)); PStack<String> stack3 = stack.plusAll(stack); // palindrome stack
public static <T> Monoid<PStack<T>> toPStackReversed() { return Monoid.<PStack<T>>of(ConsPStack.empty(), (PStack<T> a) -> b -> a.plusAll(b), (T x) -> ConsPStack.singleton(x)); }
public static <T> Monoid<PStack<T>> toPStack() { return Monoid.<PStack<T>>of(ConsPStack.empty(), (PStack<T> a) -> b -> a.plusAll(b), (T x) -> ConsPStack.singleton(x)); } public static <K,V> Monoid<PMap<K,V>> toPMap() {
public static <T> Monoid<PStack<T>> toPStack() { return Monoid.<PStack<T>>of(ConsPStack.empty(), (PStack<T> a) -> b -> a.plusAll(b), (T x) -> ConsPStack.singleton(x)); } public static <K,V> Monoid<PMap<K,V>> toPMap() {
/** * <pre> * {@code * PStack<Integer> q = Reducers.<Integer>toPStackReversed() .mapReduce(Stream.of(1,2,3,4)); * * } * </pre> * @return Reducer for PStack in reveresed order */ public static <T> Reducer<PStack<T>> toPStackReversed() { return Reducer.<PStack<T>> of(ConsPStack.empty(), (final PStack<T> a) -> b -> a.plusAll(b), (final T x) -> ConsPStack.singleton(x)); } /**
public static <T> Monoid<PStack<T>> toPStack() { return Monoid.<PStack<T>>of(ConsPStack.empty(), (PStack<T> a) -> b -> a.plusAll(a.size(),b), (T x) -> ConsPStack.singleton(x)); } public static <T> Monoid<PStack<T>> toPStackReversed() {
/** * <pre> * {@code * PStack<Integer> q = Reducers.<Integer>toPStack() .mapReduce(Stream.of(1,2,3,4)); * * } * </pre> * @return Reducer for PStack */ public static <T> Reducer<PStack<T>> toPStack() { return Reducer.<PStack<T>> of(ConsPStack.empty(), (final PStack<T> a) -> b -> a.plusAll(a.size(), b), (final T x) -> ConsPStack.singleton(x)); } /**
public AmortizedPQueue<E> minus() { if (size() == 0) { return this; } int fsize = front.size(); if (fsize == 0) { //If there's nothing on front, dump back onto front //(as stacks, this goes in reverse like we want) //and take one off. return new AmortizedPQueue<E>(Empty.<E>stack().plusAll(back), Empty.<E>stack()).minus(); } else if (fsize == 1) { //If there's one element on front, dump back onto front, //but now we've already removed the head. return new AmortizedPQueue<E>(Empty.<E>stack().plusAll(back), Empty.<E>stack()); } else { //If there's more than one on front, we pop one off. return new AmortizedPQueue<E>(front.minus(0), back); } }
public AmortizedPQueue<E> minus() { if (size() == 0) return this; int fsize = front.size(); if (fsize == 0) { //If there's nothing on front, dump back onto front //(as stacks, this goes in reverse like we want) //and take one off. return new AmortizedPQueue<E>(Empty.<E>stack().plusAll(back), Empty.<E>stack()).minus(); } else if (fsize == 1) { //If there's one element on front, dump back onto front, //but now we've already removed the head. return new AmortizedPQueue<E>(Empty.<E>stack().plusAll(back), Empty.<E>stack()); } else { //If there's more than one on front, we pop one off. return new AmortizedPQueue<E>(front.minus(0), back); } }