Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我有这个:
val a = Array(...)
我写
a.par.map(e => someFunc(e))
生成的集合是否与非并行集合的顺序相同?
是的,但是函数本身的执行没有任何特定的顺序。
List(1,2,3).par foreach print // could print out 213
并行集合维护其非并行等价物的所有合同。
在map操作保留顺序的集合上,例如List,顺序也将由并行保留map。在map不保留顺序的集合上,例如Set,并行版本中不会保留顺序。
map
List
Set
对于无序集合,无法保证并行操作的结果甚至具有与其非并行等效项相同的遍历顺序。