Filtering Scala's Parallel Collections with early abort when desired number of results found

前端 未结 3 1757
终归单人心
终归单人心 2021-02-08 13:02

Given a very large instance of collection.parallel.mutable.ParHashMap (or any other parallel collection), how can one abort a filtering parallel scan once a giv

3条回答
  •  半阙折子戏
    2021-02-08 13:45

    I would first do parallel scan in which variable maxResults would be threadlocal. This would find up to (maxResults * numberOfThreads) results.

    Then I would do single threaded scan to reduce it to maxResults.

提交回复
热议问题