Пример #1
0
        public void onReceive(Message <TTime, TInput2> message)
        {
            var output       = new Buffer <TTime, TOutput>(message.time);
            int outputOffset = 0;

            if (!vals.ContainsKey(message.time))
            {
                vals.Add(message.time,
                         new Dictionary <TKey, PairNonCloneable <RegionLinkedList <TInput1>, RegionLinkedList <TInput2> > >());
            }
            Dictionary <TKey, PairNonCloneable <RegionLinkedList <TInput1>, RegionLinkedList <TInput2> > > dictKeys =
                vals[message.time];

            for (int i = 0; i < message.length; i++)
            {
                var key = keySelector2(message.payload[i]);
                PairNonCloneable <RegionLinkedList <TInput1>, RegionLinkedList <TInput2> > currentEntry;
                if (!dictKeys.TryGetValue(key, out currentEntry))
                {
                    currentEntry = new PairNonCloneable <RegionLinkedList <TInput1>, RegionLinkedList <TInput2> >(
                        new RegionLinkedList <TInput1>(), new RegionLinkedList <TInput2>());
                    dictKeys.Add(key, currentEntry);
                }
                currentEntry.Second.InsertFirst(message.payload[i]);
                for (Node <TInput1> cur = currentEntry.First.Head;
                     cur != default(Node <TInput1>); cur = cur.Next)
                {
                    output.set(outputOffset, resSelector(cur.Data, message.payload[i]));
                    outputOffset++;
                }
            }
            output.send();
        }
Пример #2
0
        public void onReceive(Message <int, TInput1> message)
        {
            var output       = new Buffer <int, TOutput>(message.time);
            int outputOffset = 0;

            if (!vals.ContainsKey(message.time))
            {
                vals.Add(message.time,
                         new Dictionary <TKey, PairNonCloneable <RegionLinkedList <TInput1>, RegionLinkedList <TInput2> > >());
            }
            Dictionary <TKey, PairNonCloneable <RegionLinkedList <TInput1>, RegionLinkedList <TInput2> > > dictKeys =
                vals[message.time];

            for (int i = 0; i < message.length; i++)
            {
                var key = keySelector1(message.payload[i]);
                PairNonCloneable <RegionLinkedList <TInput1>, RegionLinkedList <TInput2> > currentEntry;
                if (!dictKeys.TryGetValue(key, out currentEntry))
                {
                    currentEntry = new PairNonCloneable <RegionLinkedList <TInput1>, RegionLinkedList <TInput2> >(
                        new RegionLinkedList <TInput1>(), new RegionLinkedList <TInput2>());
                    dictKeys[key] = currentEntry;
                }
                currentEntry.First.InsertFirst(message.payload[i]);
                for (int curTime = message.time - windowSize + 1;
                     curTime <= message.time; curTime++)
                {
                    if (vals.ContainsKey(curTime))
                    {
                        var matchedDictKeys = vals[curTime];
                        if (matchedDictKeys.ContainsKey(key))
                        {
                            for (Node <TInput2> cur = matchedDictKeys[key].Second.Head;
                                 cur != default(Node <TInput2>); cur = cur.Next)
                            {
                                output.set(outputOffset,
                                           resSelector(message.payload[i], cur.Data));
                                outputOffset++;
                            }
                        }
                    }
                }
            }
            output.send();
        }
Пример #3
0
 public bool Equals(PairNonCloneable <TFirst, TSecond> other)
 {
     return(First.Equals(other.First) && Second.Equals(other.Second));
 }
Пример #4
0
        public void onReceive(Message <TTime, TInput2> message, Region actorRegion)
        {
            Region outputRegion =
                RegionAllocator.AllocateRegion(NaiadSimulator.OUTPUT_REGION_SIZE);
            var output       = new Buffer <TTime, TOutput>(outputRegion, message.time);
            int outputOffset = 0;

            Region dictRegion;

            if (!vals.ContainsKey(message.time))
            {
                Dictionary <TKey, PairNonCloneable <RegionLinkedList <TInput1>, RegionLinkedList <TInput2> > > dictKeyPair;
                dictRegion =
                    RegionAllocator.AllocateRegion(NaiadSimulator.TMP_REGION_SIZE);
                using (RegionContext regContext = RegionContext.Create(dictRegion))
                {
                    dictKeyPair =
                        new Dictionary <TKey, PairNonCloneable <RegionLinkedList <TInput1>, RegionLinkedList <TInput2> > >(0, new EqualityComparer <TKey>());
                }
                using (RegionContext regContext = RegionContext.Create(actorRegion))
                {
                    vals.Add(message.time, dictKeyPair);
                    dictRegions.Add(message.time, dictRegion);
                }
            }
            Dictionary <TKey, PairNonCloneable <RegionLinkedList <TInput1>, RegionLinkedList <TInput2> > > dictKeys =
                vals[message.time];

            dictRegion = dictRegions[message.time];

            PairNonCloneable <RegionLinkedList <TInput1>, RegionLinkedList <TInput2> > currentEntry;
            TInput2 curInput;

            using (RegionContext regContext = RegionContext.Create(dictRegion))
            {
                for (int i = 0; i < message.length; i++)
                {
                    // Note: Automatically annotated code may require this Clone, but
                    // in the manually written one we don't need it.
                    // curInput = (TInput2)message.payload[i].Clone();
                    curInput = (TInput2)message.payload[i];
                    var key = keySelector2(curInput);
                    if (!dictKeys.TryGetValue(key, out currentEntry))
                    {
                        currentEntry = new PairNonCloneable <RegionLinkedList <TInput1>, RegionLinkedList <TInput2> >(
                            new RegionLinkedList <TInput1>(), new RegionLinkedList <TInput2>());
                        dictKeys.Add(key, currentEntry);
                    }
                    currentEntry.Second.InsertFirst(curInput);

//          using (RegionContext context = RegionContext.Create(outputRegion))
                    {
                        for (Node <TInput1> cur = currentEntry.First.Head;
                             cur != default(Node <TInput1>); cur = cur.Next)
                        {
                            output.set(outputOffset, resSelector(cur.Data, curInput));
                            outputOffset++;
                        }
                    }
                }
            }
            // The region will be freed.
            output.send(outputRegion);
        }