|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.rice.cs.plt.recur.RecursionStack<T>
public class RecursionStack<T>
A stack used to store the arguments of a recursive invocation in order to prevent infinite recursion. By checking that a given argument has not been used previously before recurring, a client can prevent infinite recursion in some circumstances (such as when traversing an infinite, immutable data structure).
The client may either choose to explicity check for containment, push(T) the
argument, recur, and then pop(T), or invoke one of a variety of lambda-based
methods that perform these bookkeeping tasks automatically. In the latter case, when an
exception occurs between a push and a matching pop, the pop is
guaranteed to execute before the exception propagates upward. Thus, clients who do not
directly invoke push(T) and pop(T) may assume that the stack is always in a
consistent state.
PrecomputedRecursionStack,
RecursionStack2,
RecursionStack3,
RecursionStack4| Constructor Summary | |
|---|---|
RecursionStack()
Create an empty recursion stack with an IdentityWrapper factory |
|
RecursionStack(Lambda<? super T,? extends Wrapper<T>> wrapperFactory)
Create an empty recursion stack with the given Wrapper factory |
|
| Method Summary | ||
|---|---|---|
|
apply(Lambda<? super V,? extends R> lambda,
Lambda<? super V,? extends R> infiniteCase,
V arg)
If arg is not on the stack, evaluate lambda with argument arg;
otherwise, evaluate infiniteCase. |
|
|
apply(Lambda<? super V,? extends R> lambda,
Lambda<? super V,? extends R> infiniteCase,
V arg,
int threshold)
If less than threshold instances of arg are on the stack, evaluate
lambda with argument arg; otherwise, evaluate infiniteCase. |
|
|
apply(Lambda<? super V,? extends R> lambda,
R infiniteCase,
V arg)
Evaluate the given lambda with argument arg, unless arg is already on
the stack; push arg onto the stack during lambda evaluation |
|
|
apply(Lambda<? super V,? extends R> lambda,
R infiniteCase,
V arg,
int threshold)
Evaluate the given lambda with argument arg, unless threshold instances
of arg are already on the stack; push arg onto the stack during
lambda evaluation |
|
|
apply(Thunk<? extends R> thunk,
R infiniteCase,
T arg)
Evaluate the given thunk, unless arg is already on the stack; push arg
onto the stack during thunk evaluation |
|
|
apply(Thunk<? extends R> thunk,
R infiniteCase,
T arg,
int threshold)
Evaluate the given thunk, unless threshold instances of arg are already
on the stack; push arg onto the stack during thunk evaluation |
|
|
apply(Thunk<? extends R> thunk,
Thunk<? extends R> infiniteCase,
T arg)
If arg is not on the stack, evaluate thunk; otherwise, evaluate
infiniteCase. |
|
|
apply(Thunk<? extends R> thunk,
Thunk<? extends R> infiniteCase,
T arg,
int threshold)
If less than threshold instances of arg are on the stack, evaluate
thunk; otherwise, evaluate infiniteCase. |
|
boolean |
contains(T arg)
|
|
boolean |
contains(T arg,
int threshold)
|
|
boolean |
isEmpty()
|
|
static
|
make()
Call the constructor (allows T to be inferred) |
|
static
|
make(Lambda<? super T,? extends Wrapper<T>> wrapperFactory)
Call the constructor (allows T to be inferred) |
|
void |
pop(T arg)
Remove arg from the top of the stack |
|
void |
push(T arg)
Add arg to the top of the stack |
|
|
run(Runnable1<? super V> r,
Runnable1<? super V> infiniteCase,
V arg)
If arg is not on the stack, run r with argument arg; otherwise,
run infiniteCase. |
|
|
run(Runnable1<? super V> r,
Runnable1<? super V> infiniteCase,
V arg,
int threshold)
If less than threshold instances of arg are on the stack, run r
with argument arg; otherwise, run infiniteCase. |
|
|
run(Runnable1<? super V> r,
V arg)
Run the given runnable with argument arg, unless arg is already on the
stack; push arg onto the stack during runnable execution |
|
|
run(Runnable1<? super V> r,
V arg,
int threshold)
Run the given runnable with argument arg, unless threshold instances
of arg are already on the stack; push arg onto the stack during
runnable execution |
|
void |
run(Runnable r,
Runnable infiniteCase,
T arg)
If arg is not on the stack, run r; otherwise, run infiniteCase. |
|
void |
run(Runnable r,
Runnable infiniteCase,
T arg,
int threshold)
If less than threshold instances of arg are on the stack, run r;
otherwise, run infiniteCase. |
|
void |
run(Runnable r,
T arg)
Run the given runnable, unless arg is already on the stack; push arg
onto the stack during runnable execution |
|
void |
run(Runnable r,
T arg,
int threshold)
Run the given runnable, unless threshold instances of arg are already
on the stack; push arg onto the stack during runnable execution |
|
int |
size()
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public RecursionStack()
IdentityWrapper factory
public RecursionStack(Lambda<? super T,? extends Wrapper<T>> wrapperFactory)
Wrapper factory
wrapperFactory - A lambda used to produce a wrapper for values placed on the
stack. This provides clients with control over the method used
to determine if a value has been seen previously.| Method Detail |
|---|
public boolean contains(T arg)
true iff a value identical (according to ==) to arg
is currently on the stack
public boolean contains(T arg,
int threshold)
true iff at least threshold values identical (according to
==) to arg are currently on the stackpublic void push(T arg)
arg to the top of the stack
public void pop(T arg)
arg from the top of the stack
IllegalArgumentException - If arg is not at the top of the stackpublic int size()
public boolean isEmpty()
true iff the stack is currently empty
public void run(Runnable r,
T arg)
arg is already on the stack; push arg
onto the stack during runnable execution
public void run(Runnable r,
T arg,
int threshold)
threshold instances of arg are already
on the stack; push arg onto the stack during runnable execution
public void run(Runnable r,
Runnable infiniteCase,
T arg)
arg is not on the stack, run r; otherwise, run infiniteCase.
In either case, push arg onto the stack during runnable execution.
public void run(Runnable r,
Runnable infiniteCase,
T arg,
int threshold)
threshold instances of arg are on the stack, run r;
otherwise, run infiniteCase. In either case, push arg onto the stack
during runnable execution.
public <V extends T> void run(Runnable1<? super V> r,
V arg)
arg, unless arg is already on the
stack; push arg onto the stack during runnable execution
public <V extends T> void run(Runnable1<? super V> r,
V arg,
int threshold)
arg, unless threshold instances
of arg are already on the stack; push arg onto the stack during
runnable execution
public <V extends T> void run(Runnable1<? super V> r,
Runnable1<? super V> infiniteCase,
V arg)
arg is not on the stack, run r with argument arg; otherwise,
run infiniteCase. In either case, push arg onto the stack during
runnable execution.
public <V extends T> void run(Runnable1<? super V> r,
Runnable1<? super V> infiniteCase,
V arg,
int threshold)
threshold instances of arg are on the stack, run r
with argument arg; otherwise, run infiniteCase. In either case,
push arg onto the stack during runnable execution.
public <R> R apply(Thunk<? extends R> thunk,
R infiniteCase,
T arg)
arg is already on the stack; push arg
onto the stack during thunk evaluation
thunk, or infiniteCase
public <R> R apply(Thunk<? extends R> thunk,
R infiniteCase,
T arg,
int threshold)
threshold instances of arg are already
on the stack; push arg onto the stack during thunk evaluation
thunk, or infiniteCase
public <R> R apply(Thunk<? extends R> thunk,
Thunk<? extends R> infiniteCase,
T arg)
arg is not on the stack, evaluate thunk; otherwise, evaluate
infiniteCase. In either case, push arg onto the stack during
thunk evaluation.
thunk, or the value of infiniteCase
public <R> R apply(Thunk<? extends R> thunk,
Thunk<? extends R> infiniteCase,
T arg,
int threshold)
threshold instances of arg are on the stack, evaluate
thunk; otherwise, evaluate infiniteCase. In either case, push
arg onto the stack during thunk evaluation.
thunk, or the value of infiniteCase
public <V extends T,R> R apply(Lambda<? super V,? extends R> lambda,
R infiniteCase,
V arg)
arg, unless arg is already on
the stack; push arg onto the stack during lambda evaluation
lambda, or infiniteCase
public <V extends T,R> R apply(Lambda<? super V,? extends R> lambda,
R infiniteCase,
V arg,
int threshold)
arg, unless threshold instances
of arg are already on the stack; push arg onto the stack during
lambda evaluation
lambda, or infiniteCase
public <V extends T,R> R apply(Lambda<? super V,? extends R> lambda,
Lambda<? super V,? extends R> infiniteCase,
V arg)
arg is not on the stack, evaluate lambda with argument arg;
otherwise, evaluate infiniteCase. In either case, push arg onto the
stack during lambda evaluation.
lambda, or the value of infiniteCase
public <V extends T,R> R apply(Lambda<? super V,? extends R> lambda,
Lambda<? super V,? extends R> infiniteCase,
V arg,
int threshold)
threshold instances of arg are on the stack, evaluate
lambda with argument arg; otherwise, evaluate infiniteCase.
In either case, push arg onto the stack during lambda evaluation.
lambda, or the value of infiniteCasepublic static <T> RecursionStack<T> make()
T to be inferred)
public static <T> RecursionStack<T> make(Lambda<? super T,? extends Wrapper<T>> wrapperFactory)
T to be inferred)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||