zoukankan      html  css  js  c++  java
  • Lazy Evaluation

     https://stackoverflow.com/questions/2515796/deferred-execution-and-eager-evaluation

     public
    class LazyEvaluation { public int Count { get; set; } public int Computation(int index) { this.Count++; if (index == 0) { return 0; } else if (index == 1) { return 1; } else if (index >= 2) { return Computation(index - 2) + Computation(index - 1); } else { throw new ArgumentException("index"); } } public IEnumerable<int> GetComputationEager(int maxIndex) { var result = new int[maxIndex]; for (int i = 0; i < maxIndex; i++) { result[i] = this.Computation(i); } foreach (var value in result) { yield return value; } } public IEnumerable<int> GetComputationImmediate(int maxIndex) { var result = new int[maxIndex]; for (int i = 0; i < maxIndex; i++) { result[i] = this.Computation(i); } return result; } public IEnumerable<int> GetComputationLazy(int maxIndex) { for (int i = 0; i < maxIndex; i++) { yield return this.Computation(i); } } }
  • 相关阅读:
    生成函数代替伯努利数
    关于费用流
    GDOI注意事项
    计算几何 学习笔记
    jzoj5370
    图上的游戏
    小学生语文题
    arcane
    P2305 [NOI2014] 购票
    P3512 [POI2010]PIL-Pilots
  • 原文地址:https://www.cnblogs.com/ryan-y-an/p/8513926.html
Copyright © 2011-2022 走看看