Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
def pwords(s) {
  int n = (s.size() + THREADS - 1) / THREADS
  def agent = new Agent<Map>([:], {it?.clone()})
  (0..<THREADS).collect { i ->
    Thread.start {
      def (min, max) = [[s.size(), i * n].min(), [s.size(), (i + 1) * n].min()]
      agentdef << { it[i] result = swords(s[min..<max])
      agent << { it[i] = result; updateValue it }
    }
  }*.join()
  assert agent.val instanceof LinkedHashMap
  (0..<THREADS).collect { i -> agent.val[i] }.sum().flatten()
}

...