MemoIter
A small Rust library implementing a Memoized Iterator, which pairs a normal Iterator<Item=T>
with an owned Vec<T>
to store the items it returns. Alternatively, it may be considered as a wrapped Vec<T>
that is lazily populated with items from the Iterator.
This is useful for infinite Iterators where each value depends on the last, such as the factorial function: Calculating the factorial of 1000
is quite expensive, but it also includes, as byproducts, the factorials of 999
, 998
, and so on. If these are stored, they can be retrieved later, without needing to be recalculated for their own sake.
Example
The following example shows a MemoIter
being used to cache the results of calculating the Fibonacci Sequence.
use MemoIter;
use successors;