예제 #1
0
파일: Join.cs 프로젝트: xyuan/Naiad
        public override void OnInput1(Weighted <S1> entry, T time)
        {
            //Console.WriteLine("Join Recv1");

            var k = key1(entry.record);
            var v = value1(entry.record);

            var state = new JoinKeyIndices();

            if (!JoinKeys.TryGetValue(k, out state))
            {
                state = new JoinKeyIndices();
            }

            if (!inputShutdown2)//!this.inputImmutable2)
            {
                inputTrace1.EnsureStateIsCurrentWRTAdvancedTimes(ref state.processed1);
                inputTrace1.Introduce(ref state.processed1, v, entry.weight, internTable.Intern(time));
            }

            if (inputShutdown1)
            {
                Console.Error.WriteLine("Error in Join input shutdown1");
            }

            if (state.processed2 != 0)
            {
                inputTrace2.EnsureStateIsCurrentWRTAdvancedTimes(ref state.processed2);

                times.Clear();
                inputTrace2.EnumerateTimes(state.processed2, times);

                for (int i = 0; i < times.Count; i++)
                {
                    differences2.Clear();
                    inputTrace2.EnumerateDifferenceAt(state.processed2, times.Array[i], differences2);
                    var newTime = time.Join(internTable.times[times.Array[i]]);

                    var output = this.Output.GetBufferForTime(newTime);

                    for (int j = 0; j < differences2.Count; j++)
                    {
                        if (differences2.Array[j].weight != 0)
                        {
                            output.Send(resultSelector(k, v, differences2.Array[j].record).ToWeighted(entry.weight * differences2.Array[j].weight));
                        }
                    }
                }
            }

            if (state.IsEmpty)
            {
                JoinKeys.Remove(k);
            }
            else
            {
                JoinKeys[k] = state;
            }
        }
예제 #2
0
파일: Join.cs 프로젝트: sherryshare/Naiad
        public override void OnInput2(Weighted <S2> entry, T time)
        {
            var k = key2(entry.record);
            var v = value2(entry.record);

            var state = new JoinKeyIndices();

            if (!JoinKeys.TryGetValue(k, out state))
            {
                state = new JoinKeyIndices();
            }

            if (!inputShutdown1)//!this.inputImmutable1)
            {
                inputTrace2.EnsureStateIsCurrentWRTAdvancedTimes(ref state.processed2);
                inputTrace2.Introduce(ref state.processed2, v, entry.weight, internTable.Intern(time));
            }

            if (inputShutdown2)
            {
                Console.Error.WriteLine("Error in Join input shutdown2");
            }

            if (state.processed1 != 0)
            {
                inputTrace1.EnsureStateIsCurrentWRTAdvancedTimes(ref state.processed1);

                times.Clear();
                inputTrace1.EnumerateTimes(state.processed1, times);

                for (int i = 0; i < times.Count; i++)
                {
                    differences1.Clear();
                    inputTrace1.EnumerateDifferenceAt(state.processed1, times.Array[i], differences1);
                    var newTime = time.Join(internTable.times[times.Array[i]]);

                    for (int j = 0; j < differences1.Count; j++)
                    {
                        if (differences1.Array[j].weight != 0)
                        {
                            //Send(resultSelector(k, differences1.Array[j].record, v).ToNaiadRecord(entry.weight * differences1.Array[j].weight, newTime));
                            var result = resultSelector(k, differences1.Array[j].record, v);
                            var weight = entry.weight * differences1.Array[j].weight;
                            this.Output.Buffer.payload[this.Output.Buffer.length++] = new Pair <Weighted <R>, T>(new Weighted <R>(result, weight), newTime);

                            if (this.Output.Buffer.length == this.Output.Buffer.payload.Length)
                            {
                                this.Output.Send(this.Output.Buffer);
                                this.Output.Buffer.length = 0;
                            }
                        }
                    }
                }
            }

            if (state.IsEmpty)
            {
                JoinKeys.Remove(k);
            }
            else
            {
                JoinKeys[k] = state;
            }
        }