• Rocket


     
    介绍TransferSizes的实现。
     
     
    1. 基本定义
     
    从min到max的闭合区间:[min, max]
     
    判断条件:
    a. min和max为2的幂;
    b. min <= max;
    c. min和max为非负整数;
    d. min和max必须同时为0;
     
     
    2. none
     
    因为min和max必须同时为0,所以只需要判断min是否为0即可:
     
    3. contains
     
    判断this是否包含x,即x落在this的范围内:
     
    4. containsLg
     
    判断this是否包含2^x。
     
    5. intersect
     
    计算this和x的交集。
     
    6. 伴生对象
     
    a. 构造方法:min = max = x;
    b. none对象:min = max = 0;
    c. asBool:x是否为空;
     
    7. 附录
     
    TransferSizes:
    // An potentially empty inclusive range of 2-powers [min, max] (in bytes)
    case class TransferSizes(min: Int, max: Int)
    {
    def this(x: Int) = this(x, x)
     
    require (min <= max, s"Min transfer $min > max transfer $max")
    require (min >= 0 && max >= 0, s"TransferSizes must be positive, got: ($min, $max)")
    require (max == 0 || isPow2(max), s"TransferSizes must be a power of 2, got: $max")
    require (min == 0 || isPow2(min), s"TransferSizes must be a power of 2, got: $min")
    require (max == 0 || min != 0, s"TransferSize 0 is forbidden unless (0,0), got: ($min, $max)")
     
    def none = min == 0
    def contains(x: Int) = isPow2(x) && min <= x && x <= max
    def containsLg(x: Int) = contains(1 << x)
    def containsLg(x: UInt) =
    if (none) Bool(false)
    else if (min == max) { UInt(log2Ceil(min)) === x }
    else { UInt(log2Ceil(min)) <= x && x <= UInt(log2Ceil(max)) }
     
    def contains(x: TransferSizes) = x.none || (min <= x.min && x.max <= max)
     
    def intersect(x: TransferSizes) =
    if (x.max < min || max < x.min) TransferSizes.none
    else TransferSizes(scala.math.max(min, x.min), scala.math.min(max, x.max))
     
    override def toString() = "TransferSizes[%d, %d]".format(min, max)
     
    }
     
    object TransferSizes {
    def apply(x: Int) = new TransferSizes(x)
    val none = new TransferSizes(0)
     
    implicit def asBool(x: TransferSizes) = !x.none
    }
     
  • 相关阅读:
    bat常用指令记录
    物料主数据MM01扩充时默认值的设置 BADI_MATERIAL_REF
    CK11,CK11N 成本估算数据读取
    VUE中具名插槽和匿名插槽的使用
    VUE+element页面按钮调用dialog
    线程进程随笔
    "反直觉" 的Unity粒子系统API
    一个RingBuffer(C语言)
    一个极其简单(陋)的内存分配器
    nginx 转发接口出现 403 forbidden
  • 原文地址:https://www.cnblogs.com/wjcdx/p/10669788.html
Copyright © 2020-2023  润新知