001 /*
002 DXN, May 18. 99: don't think host is needed in the next method in general. The
003 lazy evaluator should carry all needed information to compute the next element in
004 the sequence, irrespective of what the host has.
005 */
006 package lrs.lazyLRSEvaluators;
007
008 import lrs.*;
009 public class LazyFibEval extends ALazyEval
010 {
011 // f(n) = f(n-1) + f(n-2).
012 private int _fn1; // f(n-1)
013 private int _fn2; // f(n-2)
014
015 public LazyFibEval (int fn2, int fn1)
016 {
017 _fn1 = fn1;
018 _fn2 = fn2;
019 }
020
021 public LRStruct nextLRS()
022 {
023 int fn = _fn1 + _fn2;
024 _fn2 = _fn1;
025 _fn1 = fn;
026 return makeLazyLRS (_fn2);
027 }
028
029 /**
030 * @return
031 */
032 public LRStruct makeLRS() // I want to be able to makeLazyLRS at any time.
033 {
034 LRStruct lrs = new LRStruct();
035 lrs.insertFront(_fn2);
036 lrs.setRest (nextLRS());
037 return lrs;
038 }
039 }
040