加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

什么是DList?

发布时间:2020-12-16 09:44:34 所属栏目:安全 来源:网络整理
导读:我尝试了谷歌搜索,但我得到的是关于小名人的故事。鉴于缺乏文档,什么是 DList? 解决方法 这是一个不同的列表,沿着 “Difference List as functions” scala val (l1,l2,l3) = (List(1,2,3),List(4,5,6),List(7,8,9))l1: List[Int] = List(1,3)l2: List[I
我尝试了谷歌搜索,但我得到的是关于小名人的故事。鉴于缺乏文档,什么是 DList?

解决方法

这是一个不同的列表,沿着 “Difference List as functions”

scala> val (l1,l2,l3) = (List(1,2,3),List(4,5,6),List(7,8,9))
l1: List[Int] = List(1,3)
l2: List[Int] = List(4,6)
l3: List[Int] = List(7,9)

高效预设:

scala> l1 ::: l2 ::: l3
res8: List[Int] = List(1,3,4,6,7,9)

效率低下。这创建一个中间列表(l1 l2),然后((l l l2)l3)

scala> l1 ++ l2 ++ l3  // inefficient
res9: List[Int] = List(1,9)

DList存储附件,只需要创建一个完整的列表,有效地调用:

scala> List(l1,l3) reduceRight ( _ ::: _) 
res10: List[Int] = List(1,9)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读