设为首页收藏本站

小牛社区-大数据学习交流社区|大数据免费学习资源

 找回密码
 立即注册!

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 922|回复: 0

Scala 具体的并行集合库【翻译】

[复制链接]

3205

主题

3588

帖子

1万

积分

管理员

Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18

积分
15112
发表于 2016-6-12 12:55:11 | 显示全部楼层 |阅读模式
原文地址
  本文内容

  
       
  • 并行数组(Parallel Array)   
  • 并行向量(Parallel Vector)   
  • 并行范围(Parallel Range)   
  • 并行哈希表(Parallel Hash Tables)   
  • 并行散列 Tries(Parallel Hash Tries)   
  • 并行并发 Tries(Parallel Concurrent Tries)   
  • 参考资料
  并行数组(Parallel Array)

    一个 ParArray 序列包含线性、连续的元素数组。这意味着,通过修改底层数组,可以高效地访问和修改元素。因此,反序元素也很高效。并行数组跟数组一样也是固定大小的。
     
   
  1. scala> val pa = scala.collection.parallel.mutable.ParArray.tabulate(1000)(x =>2*
复制代码
  1. x +1)
复制代码
  1. pa: scala.collection.parallel.mutable.ParArray[Int] = ParArray(1, 3, 5, 7, 9, 11
复制代码
  1. , 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51
复制代码
  1. , 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91
复制代码
  1. , 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 12
复制代码
  1. 5, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 15
复制代码
  1. 7, 159, 161, 163, 165, 167, 169, 171, 173, 175, 177, 179, 181, 183, 185, 187, 18
复制代码
  1. 9, 191, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 22
复制代码
  1. 1, 223, 225, 227, 229, 231, 233, 235, 237, 239, 241, 243, 245, 247, 249, 251, 25
复制代码
  1. x +1)0
复制代码
  1. x +1)1
复制代码
  1. x +1)2
复制代码
  1. x +1)3
复制代码
  1. x +1)4
复制代码
  1. x +1)5
复制代码
  1. x +1)6
复制代码
  1. x +1)7
复制代码
  1. x +1)8
复制代码
  1. x +1)9
复制代码
  1. pa: scala.collection.parallel.mutable.ParArray[Int] = ParArray(1, 3, 5, 7, 9, 110
复制代码
  1. pa: scala.collection.parallel.mutable.ParArray[Int] = ParArray(1, 3, 5, 7, 9, 111
复制代码
  1. pa: scala.collection.parallel.mutable.ParArray[Int] = ParArray(1, 3, 5, 7, 9, 112
复制代码
  1. pa: scala.collection.parallel.mutable.ParArray[Int] = ParArray(1, 3, 5, 7, 9, 113
复制代码
  1. pa: scala.collection.parallel.mutable.ParArray[Int] = ParArray(1, 3, 5, 7, 9, 114
复制代码
  1. pa: scala.collection.parallel.mutable.ParArray[Int] = ParArray(1, 3, 5, 7, 9, 115
复制代码
  1. pa: scala.collection.parallel.mutable.ParArray[Int] = ParArray(1, 3, 5, 7, 9, 116
复制代码
  1. x +1)5
复制代码
  1. pa: scala.collection.parallel.mutable.ParArray[Int] = ParArray(1, 3, 5, 7, 9, 118
复制代码


并行向量(Parallel Vector)

一个 ParVector 是一个不可变序列,具有低常量因子对数的访问(low-constant factor logarithmic access )和更新时间。
  1. pa: scala.collection.parallel.mutable.ParArray[Int] = ParArray(1, 3, 5, 7, 9, 119
复制代码
  1. , 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 510
复制代码
  1. , 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 511
复制代码
  1. , 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 512
复制代码
  1. , 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 513
复制代码
  1. , 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 514
复制代码
  1. , 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 515
复制代码
  1. , 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 516
复制代码
  1. , 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 517
复制代码
  1. , 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 518
复制代码
  1. , 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 519
复制代码
  1. , 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 910
复制代码
  1. x +1)2
复制代码
  1. , 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 912
复制代码
  1. , 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 913
复制代码
  1. , 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 914
复制代码
  1. , 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 915
复制代码
  1. , 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 916
复制代码
  1. , 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 917
复制代码
  1. , 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 918
复制代码
  1. , 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 919
复制代码
  1. , 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 120
复制代码
  1. , 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 121
复制代码
  1. , 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 122
复制代码
  1. x +1)2
复制代码
  1. , 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 124
复制代码


并行范围(Parallel Range)

一个 ParRange 是一个有序的等差整数数列(an ordered sequence of elements equally spaced apart)。并行范围(parallel range)的创建与顺序范围类似(sequential Range)。
  1. , 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125
复制代码
  1. , 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 126
复制代码
  1. , 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 127
复制代码
  1. x +1)5
复制代码
  1. , 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 129
复制代码
  1. 5, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 150
复制代码
  1. 5, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 151
复制代码
  1. 5, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 152
复制代码
  1. x +1)5
复制代码
  1. pa: scala.collection.parallel.mutable.ParArray[Int] = ParArray(1, 3, 5, 7, 9, 118
复制代码


并行哈希表(Parallel Hash Tables)

并行哈希表(Parallel hash tables)存储底层数组的元素,并将它们放置在由各自元素哈希码的位置。并行可变哈希集(mutable.ParHashSet)和并行可变哈希映射(mutable.ParHashMap)都是基于哈希表。
  1. 5, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 155
复制代码
  1. 5, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 156
复制代码
  1. 5, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 157
复制代码
  1. 5, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 158
复制代码
  1. 5, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 159
复制代码
  1. 7, 159, 161, 163, 165, 167, 169, 171, 173, 175, 177, 179, 181, 183, 185, 187, 180
复制代码
  1. 7, 159, 161, 163, 165, 167, 169, 171, 173, 175, 177, 179, 181, 183, 185, 187, 181
复制代码
  1. 7, 159, 161, 163, 165, 167, 169, 171, 173, 175, 177, 179, 181, 183, 185, 187, 182
复制代码
  1. 7, 159, 161, 163, 165, 167, 169, 171, 173, 175, 177, 179, 181, 183, 185, 187, 183
复制代码
  1. 7, 159, 161, 163, 165, 167, 169, 171, 173, 175, 177, 179, 181, 183, 185, 187, 184
复制代码
  1. 7, 159, 161, 163, 165, 167, 169, 171, 173, 175, 177, 179, 181, 183, 185, 187, 185
复制代码
  1. x +1)5
复制代码
  1. 7, 159, 161, 163, 165, 167, 169, 171, 173, 175, 177, 179, 181, 183, 185, 187, 187
复制代码
  1. 7, 159, 161, 163, 165, 167, 169, 171, 173, 175, 177, 179, 181, 183, 185, 187, 188
复制代码
  1. 7, 159, 161, 163, 165, 167, 169, 171, 173, 175, 177, 179, 181, 183, 185, 187, 189
复制代码
  1. 9, 191, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 220
复制代码
  1. 9, 191, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 221
复制代码
  1. 9, 191, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 222
复制代码
  1. 9, 191, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 223
复制代码
  1. 9, 191, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 224
复制代码
  1. 9, 191, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 225
复制代码
  1. 9, 191, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 226
复制代码
  1. 9, 191, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 227
复制代码
  1. x +1)5
复制代码
  1. pa: scala.collection.parallel.mutable.ParArray[Int] = ParArray(1, 3, 5, 7, 9, 118
复制代码


并行散列 Tries(Parallel Hash Tries)

并行哈希 tries(Parallel hash tries )是不可变哈希 tries(immutable hash tries)的并行版本,它用来高效地表示不可变集(immutable sets)和映射(immutable maps)。他们由 immutable.ParHashSetimmutable.ParHashMap 支持。
  1. 1, 223, 225, 227, 229, 231, 233, 235, 237, 239, 241, 243, 245, 247, 249, 251, 250
复制代码
  1. 1, 223, 225, 227, 229, 231, 233, 235, 237, 239, 241, 243, 245, 247, 249, 251, 251
复制代码
  1. 1, 223, 225, 227, 229, 231, 233, 235, 237, 239, 241, 243, 245, 247, 249, 251, 252
复制代码
  1. 1, 223, 225, 227, 229, 231, 233, 235, 237, 239, 241, 243, 245, 247, 249, 251, 253
复制代码
  1. 1, 223, 225, 227, 229, 231, 233, 235, 237, 239, 241, 243, 245, 247, 249, 251, 254
复制代码
  1. 1, 223, 225, 227, 229, 231, 233, 235, 237, 239, 241, 243, 245, 247, 249, 251, 255
复制代码
  1. 1, 223, 225, 227, 229, 231, 233, 235, 237, 239, 241, 243, 245, 247, 249, 251, 256
复制代码
  1. 1, 223, 225, 227, 229, 231, 233, 235, 237, 239, 241, 243, 245, 247, 249, 251, 257
复制代码
  1. 1, 223, 225, 227, 229, 231, 233, 235, 237, 239, 241, 243, 245, 247, 249, 251, 258
复制代码
  1. 1, 223, 225, 227, 229, 231, 233, 235, 237, 239, 241, 243, 245, 247, 249, 251, 259
复制代码
  1. x +1)00
复制代码
  1. x +1)01
复制代码
  1. x +1)2
复制代码
  1. x +1)03
复制代码
  1. 5, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 150
复制代码
  1. x +1)05
复制代码
  1. x +1)2
复制代码
  1. , 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 124
复制代码


并行并发 tries(Parallel Concurrent Tries)

concurrent.TrieMap 是一个并发线程安全的映射(map),而mutable.ParTrieMap 是它的并行版本。若果数据结构在遍历期间被修改,那么大多数并发数据结构不能保证一致性,Ctries 保证在下一次迭代中更新是可见的。这意味着,当你遍历是,可以改变并发 trie,如下例子所示,输出1到99的平方根。
<div id="codeSnippetWrapper"><div id="codeSnippet"style="border-top-style: none; overflow: visible; font-size: 8pt; font-family: &#39;Courier New&#39;, courier, monospace; width: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; border-left-style: none; line-height: 12pt; padding-right: 0px; background-color: #f4f4f4">
  1. x +1)08
复制代码
  1. x +1)09
复制代码
  1. x +1)10
复制代码
  1. x +1)11
复制代码
  1. x +1)12
复制代码
  1. x +1)13
复制代码
  1. x +1)14
复制代码
  1. x +1)15
复制代码
  1. x +1)16
复制代码
  1. x +1)17
复制代码
  1. x +1)18
复制代码
  1. x +1)19
复制代码
  1. x +1)2
复制代码
  1. x +1)21
复制代码
  1. x +1)22
复制代码
  1. x +1)23
复制代码
  1. x +1)24
复制代码
[code]     | <span style="color: #0000ff">i
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册!

本版积分规则

快速回复 返回顶部 返回列表