{"action":"created","comment":{"url":"https://api.github.com/repos/akka/akka/pulls/comments/46341153","id":46341153,"diff_hunk":"@@ -0,0 +1,162 @@\n+/**\n+ * Copyright (C) 2015 Typesafe Inc. <http://www.typesafe.com>\n+ */\n+package akka.stream.impl.fusing\n+\n+import akka.stream._\n+import akka.stream.stage._\n+import akka.stream.scaladsl._\n+import akka.stream.actor.ActorSubscriberMessage\n+import akka.stream.actor.ActorSubscriberMessage._\n+import akka.stream.actor.ActorPublisherMessage\n+import akka.stream.actor.ActorPublisherMessage._\n+import scala.concurrent.forkjoin.ThreadLocalRandom\n+\n+import java.{ util ⇒ ju }\n+\n+class FlattenMerge[T, M](breadth: Int) extends GraphStage[FlowShape[Source[T, M], T]] {\n+  private val in = Inlet[Source[T, M]](\"flatten.in\")\n+  private val out = Outlet[T](\"flatten.out\")\n+  override val shape = FlowShape(in, out)\n+\n+  override def createLogic(attr: Attributes) = new GraphStageLogic(shape) {\n+\n+    var sources = Set.empty[LocalSource[T]]\n+    def activeSources = sources.size\n+\n+    private trait Queue {\n+      def hasData: Boolean\n+      def enqueue(src: LocalSource[T]): Unit\n+      def dequeue(): LocalSource[T]\n+    }\n+\n+    private class FixedQueue extends Queue {\n+      final val Size = 16\n+      final val Mask = 15\n+\n+      private val queue = new Array[LocalSource[T]](Size)\n+      private var head = 0\n+      private var tail = 0\n+\n+      def hasData = tail != head\n+      def enqueue(src: LocalSource[T]): Unit =\n+        if (tail - head == Size) {\n+          val queue = new ju.LinkedList[LocalSource[T]]\n+          while (hasData) {\n+            queue.add(dequeue())\n+          }\n+          queue.add(src)\n+          q = new DynamicQueue(queue)\n+        } else {\n+          queue(tail & Mask) = src\n+          tail += 1\n+        }\n+      def dequeue(): LocalSource[T] = {\n+        val ret = queue(head & Mask)\n+        head += 1\n+        ret\n+      }\n+    }\n+\n+    private class DynamicQueue(queue: ju.Queue[LocalSource[T]]) extends Queue {","path":"akka-stream/src/main/scala/akka/stream/impl/fusing/StreamOfStreams.scala","position":61,"original_position":61,"commit_id":"f92a392749323d1a6a2625f06edc47f279e12b2b","original_commit_id":"f92a392749323d1a6a2625f06edc47f279e12b2b","user":{"login":"rkuhn","id":470469,"avatar_url":"https://avatars.githubusercontent.com/u/470469?v=3","gravatar_id":"","url":"https://api.github.com/users/rkuhn","html_url":"https://github.com/rkuhn","followers_url":"https://api.github.com/users/rkuhn/followers","following_url":"https://api.github.com/users/rkuhn/following{/other_user}","gists_url":"https://api.github.com/users/rkuhn/gists{/gist_id}","starred_url":"https://api.github.com/users/rkuhn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkuhn/subscriptions","organizations_url":"https://api.github.com/users/rkuhn/orgs","repos_url":"https://api.github.com/users/rkuhn/repos","events_url":"https://api.github.com/users/rkuhn/events{/privacy}","received_events_url":"https://api.github.com/users/rkuhn/received_events","type":"User","site_admin":false},"body":"good point","created_at":"2015-12-01T21:25:43Z","updated_at":"2015-12-01T21:25:43Z","html_url":"https://github.com/akka/akka/pull/19063#discussion_r46341153","pull_request_url":"https://api.github.com/repos/akka/akka/pulls/19063","_links":{"self":{"href":"https://api.github.com/repos/akka/akka/pulls/comments/46341153"},"html":{"href":"https://github.com/akka/akka/pull/19063#discussion_r46341153"},"pull_request":{"href":"https://api.github.com/repos/akka/akka/pulls/19063"}}},"pull_request":{"url":"https://api.github.com/repos/akka/akka/pulls/19063","id":52285669,"html_url":"https://github.com/akka/akka/pull/19063","diff_url":"https://github.com/akka/akka/pull/19063.diff","patch_url":"https://github.com/akka/akka/pull/19063.patch","issue_url":"https://api.github.com/repos/akka/akka/issues/19063","number":19063,"state":"open","locked":false,"title":"!str #15089 add flatMapMerge","user":{"login":"rkuhn","id":470469,"avatar_url":"https://avatars.githubusercontent.com/u/470469?v=3","gravatar_id":"","url":"https://api.github.com/users/rkuhn","html_url":"https://github.com/rkuhn","followers_url":"https://api.github.com/users/rkuhn/followers","following_url":"https://api.github.com/users/rkuhn/following{/other_user}","gists_url":"https://api.github.com/users/rkuhn/gists{/gist_id}","starred_url":"https://api.github.com/users/rkuhn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkuhn/subscriptions","organizations_url":"https://api.github.com/users/rkuhn/orgs","repos_url":"https://api.github.com/users/rkuhn/repos","events_url":"https://api.github.com/users/rkuhn/events{/privacy}","received_events_url":"https://api.github.com/users/rkuhn/received_events","type":"User","site_admin":false},"body":"fixes #15089","created_at":"2015-12-01T17:05:14Z","updated_at":"2015-12-01T21:25:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5c21bc2e4bf7267c46b23440f6858ec8af184a58","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/akka/akka/pulls/19063/commits","review_comments_url":"https://api.github.com/repos/akka/akka/pulls/19063/comments","review_comment_url":"https://api.github.com/repos/akka/akka/pulls/comments{/number}","comments_url":"https://api.github.com/repos/akka/akka/issues/19063/comments","statuses_url":"https://api.github.com/repos/akka/akka/statuses/f92a392749323d1a6a2625f06edc47f279e12b2b","head":{"label":"akka:wip-fusable-stream-of-streams-RK","ref":"wip-fusable-stream-of-streams-RK","sha":"f92a392749323d1a6a2625f06edc47f279e12b2b","user":{"login":"akka","id":1496237,"avatar_url":"https://avatars.githubusercontent.com/u/1496237?v=3","gravatar_id":"","url":"https://api.github.com/users/akka","html_url":"https://github.com/akka","followers_url":"https://api.github.com/users/akka/followers","following_url":"https://api.github.com/users/akka/following{/other_user}","gists_url":"https://api.github.com/users/akka/gists{/gist_id}","starred_url":"https://api.github.com/users/akka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akka/subscriptions","organizations_url":"https://api.github.com/users/akka/orgs","repos_url":"https://api.github.com/users/akka/repos","events_url":"https://api.github.com/users/akka/events{/privacy}","received_events_url":"https://api.github.com/users/akka/received_events","type":"Organization","site_admin":false},"repo":{"id":130013,"name":"akka","full_name":"akka/akka","owner":{"login":"akka","id":1496237,"avatar_url":"https://avatars.githubusercontent.com/u/1496237?v=3","gravatar_id":"","url":"https://api.github.com/users/akka","html_url":"https://github.com/akka","followers_url":"https://api.github.com/users/akka/followers","following_url":"https://api.github.com/users/akka/following{/other_user}","gists_url":"https://api.github.com/users/akka/gists{/gist_id}","starred_url":"https://api.github.com/users/akka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akka/subscriptions","organizations_url":"https://api.github.com/users/akka/orgs","repos_url":"https://api.github.com/users/akka/repos","events_url":"https://api.github.com/users/akka/events{/privacy}","received_events_url":"https://api.github.com/users/akka/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/akka/akka","description":"Akka Project","fork":false,"url":"https://api.github.com/repos/akka/akka","forks_url":"https://api.github.com/repos/akka/akka/forks","keys_url":"https://api.github.com/repos/akka/akka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akka/akka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akka/akka/teams","hooks_url":"https://api.github.com/repos/akka/akka/hooks","issue_events_url":"https://api.github.com/repos/akka/akka/issues/events{/number}","events_url":"https://api.github.com/repos/akka/akka/events","assignees_url":"https://api.github.com/repos/akka/akka/assignees{/user}","branches_url":"https://api.github.com/repos/akka/akka/branches{/branch}","tags_url":"https://api.github.com/repos/akka/akka/tags","blobs_url":"https://api.github.com/repos/akka/akka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akka/akka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akka/akka/git/refs{/sha}","trees_url":"https://api.github.com/repos/akka/akka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akka/akka/statuses/{sha}","languages_url":"https://api.github.com/repos/akka/akka/languages","stargazers_url":"https://api.github.com/repos/akka/akka/stargazers","contributors_url":"https://api.github.com/repos/akka/akka/contributors","subscribers_url":"https://api.github.com/repos/akka/akka/subscribers","subscription_url":"https://api.github.com/repos/akka/akka/subscription","commits_url":"https://api.github.com/repos/akka/akka/commits{/sha}","git_commits_url":"https://api.github.com/repos/akka/akka/git/commits{/sha}","comments_url":"https://api.github.com/repos/akka/akka/comments{/number}","issue_comment_url":"https://api.github.com/repos/akka/akka/issues/comments{/number}","contents_url":"https://api.github.com/repos/akka/akka/contents/{+path}","compare_url":"https://api.github.com/repos/akka/akka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akka/akka/merges","archive_url":"https://api.github.com/repos/akka/akka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akka/akka/downloads","issues_url":"https://api.github.com/repos/akka/akka/issues{/number}","pulls_url":"https://api.github.com/repos/akka/akka/pulls{/number}","milestones_url":"https://api.github.com/repos/akka/akka/milestones{/number}","notifications_url":"https://api.github.com/repos/akka/akka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akka/akka/labels{/name}","releases_url":"https://api.github.com/repos/akka/akka/releases{/id}","created_at":"2009-02-16T12:51:54Z","updated_at":"2015-12-01T12:09:06Z","pushed_at":"2015-12-01T20:07:49Z","git_url":"git://github.com/akka/akka.git","ssh_url":"git@github.com:akka/akka.git","clone_url":"https://github.com/akka/akka.git","svn_url":"https://github.com/akka/akka","homepage":"http://akka.io","size":177870,"stargazers_count":4768,"watchers_count":4768,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1433,"mirror_url":null,"open_issues_count":786,"forks":1433,"open_issues":786,"watchers":4768,"default_branch":"master"}},"base":{"label":"akka:release-2.3-dev","ref":"release-2.3-dev","sha":"0a6aa445b4218a1478c15e38f3acc5f00b4b3e93","user":{"login":"akka","id":1496237,"avatar_url":"https://avatars.githubusercontent.com/u/1496237?v=3","gravatar_id":"","url":"https://api.github.com/users/akka","html_url":"https://github.com/akka","followers_url":"https://api.github.com/users/akka/followers","following_url":"https://api.github.com/users/akka/following{/other_user}","gists_url":"https://api.github.com/users/akka/gists{/gist_id}","starred_url":"https://api.github.com/users/akka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akka/subscriptions","organizations_url":"https://api.github.com/users/akka/orgs","repos_url":"https://api.github.com/users/akka/repos","events_url":"https://api.github.com/users/akka/events{/privacy}","received_events_url":"https://api.github.com/users/akka/received_events","type":"Organization","site_admin":false},"repo":{"id":130013,"name":"akka","full_name":"akka/akka","owner":{"login":"akka","id":1496237,"avatar_url":"https://avatars.githubusercontent.com/u/1496237?v=3","gravatar_id":"","url":"https://api.github.com/users/akka","html_url":"https://github.com/akka","followers_url":"https://api.github.com/users/akka/followers","following_url":"https://api.github.com/users/akka/following{/other_user}","gists_url":"https://api.github.com/users/akka/gists{/gist_id}","starred_url":"https://api.github.com/users/akka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akka/subscriptions","organizations_url":"https://api.github.com/users/akka/orgs","repos_url":"https://api.github.com/users/akka/repos","events_url":"https://api.github.com/users/akka/events{/privacy}","received_events_url":"https://api.github.com/users/akka/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/akka/akka","description":"Akka Project","fork":false,"url":"https://api.github.com/repos/akka/akka","forks_url":"https://api.github.com/repos/akka/akka/forks","keys_url":"https://api.github.com/repos/akka/akka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akka/akka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akka/akka/teams","hooks_url":"https://api.github.com/repos/akka/akka/hooks","issue_events_url":"https://api.github.com/repos/akka/akka/issues/events{/number}","events_url":"https://api.github.com/repos/akka/akka/events","assignees_url":"https://api.github.com/repos/akka/akka/assignees{/user}","branches_url":"https://api.github.com/repos/akka/akka/branches{/branch}","tags_url":"https://api.github.com/repos/akka/akka/tags","blobs_url":"https://api.github.com/repos/akka/akka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akka/akka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akka/akka/git/refs{/sha}","trees_url":"https://api.github.com/repos/akka/akka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akka/akka/statuses/{sha}","languages_url":"https://api.github.com/repos/akka/akka/languages","stargazers_url":"https://api.github.com/repos/akka/akka/stargazers","contributors_url":"https://api.github.com/repos/akka/akka/contributors","subscribers_url":"https://api.github.com/repos/akka/akka/subscribers","subscription_url":"https://api.github.com/repos/akka/akka/subscription","commits_url":"https://api.github.com/repos/akka/akka/commits{/sha}","git_commits_url":"https://api.github.com/repos/akka/akka/git/commits{/sha}","comments_url":"https://api.github.com/repos/akka/akka/comments{/number}","issue_comment_url":"https://api.github.com/repos/akka/akka/issues/comments{/number}","contents_url":"https://api.github.com/repos/akka/akka/contents/{+path}","compare_url":"https://api.github.com/repos/akka/akka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akka/akka/merges","archive_url":"https://api.github.com/repos/akka/akka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akka/akka/downloads","issues_url":"https://api.github.com/repos/akka/akka/issues{/number}","pulls_url":"https://api.github.com/repos/akka/akka/pulls{/number}","milestones_url":"https://api.github.com/repos/akka/akka/milestones{/number}","notifications_url":"https://api.github.com/repos/akka/akka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akka/akka/labels{/name}","releases_url":"https://api.github.com/repos/akka/akka/releases{/id}","created_at":"2009-02-16T12:51:54Z","updated_at":"2015-12-01T12:09:06Z","pushed_at":"2015-12-01T20:07:49Z","git_url":"git://github.com/akka/akka.git","ssh_url":"git@github.com:akka/akka.git","clone_url":"https://github.com/akka/akka.git","svn_url":"https://github.com/akka/akka","homepage":"http://akka.io","size":177870,"stargazers_count":4768,"watchers_count":4768,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1433,"mirror_url":null,"open_issues_count":786,"forks":1433,"open_issues":786,"watchers":4768,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/akka/akka/pulls/19063"},"html":{"href":"https://github.com/akka/akka/pull/19063"},"issue":{"href":"https://api.github.com/repos/akka/akka/issues/19063"},"comments":{"href":"https://api.github.com/repos/akka/akka/issues/19063/comments"},"review_comments":{"href":"https://api.github.com/repos/akka/akka/pulls/19063/comments"},"review_comment":{"href":"https://api.github.com/repos/akka/akka/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/akka/akka/pulls/19063/commits"},"statuses":{"href":"https://api.github.com/repos/akka/akka/statuses/f92a392749323d1a6a2625f06edc47f279e12b2b"}}}}