这是我将其可视化的最佳尝试。但我确实很挣扎,感觉就像一条三头蛇在吃自己的尾巴。
If we say the values of the stream S are s0, s1, s2, ..., then
initially we only know the first value, s0.
s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 s10
S = 1 ? ? ? ? ? ? ? ? ? ?
But we do know the three scale-streams will be producing multiples of
these values, on demand:
s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 s10
S = 1 ? ? ? ? ? ? ? ? ? ?
scale-2: 2*1 2*? 2*? 2*? 2*? 2*? 2*? 2*? 2*? 2*? 2*?
scale-3: 3*1 3*? 3*? 3*? 3*? 3*? 3*? 3*? 3*? 3*? 3*?
scale-5: 5*1 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*?
________________________________________________________________
Merge will initially select the lowest of the numbers at the heads of
these three streams, forcing their calculation in the process:
s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 s10
S = 1 ? ? ? ? ? ? ? ? ? ?
scale-2: [2] 2*? 2*? 2*? 2*? 2*? 2*? 2*? 2*? 2*? 2*?
scale-3: 3 3*? 3*? 3*? 3*? 3*? 3*? 3*? 3*? 3*? 3*?
scale-5: 5 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*?
________________________________________________________________
So s1 will now have the value 2:
s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 s10
S = 1 [2] ? ? ? ? ? ? ? ? ?
scale-2: 2*2 2*? 2*? 2*? 2*? 2*? 2*? 2*? 2*? 2*?
scale-3: 3 3*? 3*? 3*? 3*? 3*? 3*? 3*? 3*? 3*? 3*?
scale-5: 5 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*?
________________________________________________________________
Merge will now select 3 as the minimum of 4, 3, and 5:
s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 s10
S = 1 2 ? ? ? ? ? ? ? ? ?
scale-2: 4 2*? 2*? 2*? 2*? 2*? 2*? 2*? 2*? 2*?
scale-3: [3] 3*? 3*? 3*? 3*? 3*? 3*? 3*? 3*? 3*? 3*?
scale-5: 5 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*?
________________________________________________________________
and will put it into the next slot in the result stream S, s2:
s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 s10
S = 1 2 [3] ? ? ? ? ? ? ? ?
scale-2: 4 2*? 2*? 2*? 2*? 2*? 2*? 2*? 2*? 2*?
scale-3: 3*2 3*? 3*? 3*? 3*? 3*? 3*? 3*? 3*? 3*?
scale-5: 5 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*?
________________________________________________________________
Scale-2's head is selected again:
s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 s10
S = 1 2 3 [4] ? ? ? ? ? ? ?
scale-2: 2*3 2*? 2*? 2*? 2*? 2*? 2*? 2*? 2*?
scale-3: 6 3*? 3*? 3*? 3*? 3*? 3*? 3*? 3*? 3*?
scale-5: 5 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*?
________________________________________________________________
And then 5 is selected from scale-5 and placed in the result:
s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 s10
S = 1 2 3 4 [5] ? ? ? ? ? ?
scale-2: 6 2*? 2*? 2*? 2*? 2*? 2*? 2*? 2*?
scale-3: 6 3*? 3*? 3*? 3*? 3*? 3*? 3*? 3*? 3*?
scale-5: 5*2 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*?
________________________________________________________________
Two streams have 6 at their head, both are consumed but only one 6
is placed in the result:
s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 s10
S = 1 2 3 4 5 [6] ? ? ? ? ?
scale-2: 2*4 2*? 2*? 2*? 2*? 2*? 2*? 2*?
scale-3: 3*3 3*? 3*? 3*? 3*? 3*? 3*? 3*? 3*?
scale-5: 10 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*?
________________________________________________________________
And a few more iterations:
s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 s10
S = 1 2 3 4 5 6 [8] ? ? ? ?
scale-2: 2*5 2*? 2*? 2*? 2*? 2*? 2*?
scale-3: 9 3*? 3*? 3*? 3*? 3*? 3*? 3*? 3*?
scale-5: 10 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*?
________________________________________________________________
s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 s10
S = 1 2 3 4 5 6 8 [9] ? ? ?
scale-2: 10 2*? 2*? 2*? 2*? 2*? 2*?
scale-3: 3*4 3*? 3*? 3*? 3*? 3*? 3*? 3*?
scale-5: 10 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*?
_________________________________________________________________
s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 s10
S = 1 2 3 4 5 6 8 9 [10] ? ?
scale-2: 2*6 2*? 2*? 2*? 2*? 2*?
scale-3: 12 3*? 3*? 3*? 3*? 3*? 3*? 3*?
scale-5: 5*3 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*?
________________________________________________________________
s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 s10
S = 1 2 3 4 5 6 8 9 10 [12] ?
scale-2: 2*8 2*? 2*? 2*? 2*?
scale-3: 3*5 3*? 3*? 3*? 3*? 3*? 3*?
scale-5: 15 5*? 5*? 5*? 5*? 5*? 5*? 5*? 5*?
_________________________________________________________________
s0 s1 s2 s3 s4 s5 s6 s7 s8 s9 s10
S = 1 2 3 4 5 6 8 9 10 12 [15]
scale-2: 16 2*? 2*? 2*? 2*?
scale-3: 3*6 3*? 3*? 3*? 3*? 3*?
scale-5: 5*4 5*? 5*? 5*? 5*? 5*? 5*? 5*?
________________________________________________________________
所以也许它更像一条蛇,一个头从它的三个尾巴上交替咬一口。