示例#1
0
        public override void OnStreamStarts(Developer developer)
        {
            _breaks.Clear();

            _eventCache.Limit = MaxEventsBeforeBreak;
            _eventCache.Clear();

            base.OnStreamStarts(developer);
        }
示例#2
0
            /// <summary>
            /// This method implements the basic resetting mechanism for a state object and clears the buffer.
            /// </summary>
            public virtual void Reset()
            {
                Host.Assert(_isIniatilized);
                Host.Assert(WindowedBuffer != null);
                Host.Assert(InitialWindowedBuffer != null);

                RowCounter = 0;
                WindowedBuffer.Clear();
                InitialWindowedBuffer.Clear();
            }
示例#3
0
        public void FixedSizeQueue_CanClear()
        {
            FixedSizeQueue<int> queue = new FixedSizeQueue<int>(10);
            for (int i = 0; i < 10; i++)
            {
                queue.Enqueue(i);
            }
            Assert.AreEqual(10, queue.Count);

            queue.Clear();
            Assert.AreEqual(0, queue.Count);
        }
示例#4
0
 public static void CloseLog()
 {
     lock (Locker)
     {
         if (requestLog == null)
         {
             return;
         }
         if (file != null)
         {
             file.Close();
             file = null;
         }
         Queue.Clear();
         if (SplunkEnabled)
         {
             splunkClient.Close();
         }
     }
 }
示例#5
0
        private void TestWithSize(FixedSizeQueue <string> fixedSizeQueue, int size)
        {
            Assert.AreEqual(size, fixedSizeQueue.MaximumCapacity);
            Assert.AreEqual(0, fixedSizeQueue.Count);
            Assert.IsFalse(fixedSizeQueue.Contains(null));

            for (int i = 0; i < size; i++)
            {
                fixedSizeQueue.Push(i.ToString());
                Assert.AreEqual(i + 1, fixedSizeQueue.Count);
                Assert.IsFalse(fixedSizeQueue.Contains((i + 1).ToString()));

                for (int j = 0; j < i; j++)
                {
                    Assert.AreEqual((i - j).ToString(), fixedSizeQueue[j]);
                    Assert.IsTrue(fixedSizeQueue.Contains((i - j).ToString()));
                }
            }

            int index = size;

            for (int i = 0; i < size * 3 + 11; i++)
            {
                fixedSizeQueue.Push(index++.ToString());
                Assert.AreEqual(size, fixedSizeQueue.Count);

                for (int j = 0; j < size; j++)
                {
                    Assert.AreEqual((index - j - 1).ToString(), fixedSizeQueue[j]);
                }
            }

            foreach (string s in fixedSizeQueue)
            {
                Assert.AreEqual((--index).ToString(), s);
            }

            fixedSizeQueue.Clear();

            Assert.AreEqual(0, fixedSizeQueue.Count);
        }
示例#6
0
        public void Process(string chunk, ProcessorResult result)
        {
            var comments = JSON.Deserialize <Comment[]>(chunk);

            // We'll use this queue to keep track of all the phrases in our comments
            var lastWords = new FixedSizeQueue <string>(_queueSize);

            foreach (var comment in comments)
            {
                if (!CommunityWhitelist.Values.Contains(comment.subreddit.ToUpper()))
                {
                    continue;
                }

                var body   = Regex.Replace(comment.body, @"[.!?,_]", " ");
                var tokens = body.Split((string[])null, StringSplitOptions.RemoveEmptyEntries)
                             .ToList()
                             .Select(token => token.ToUpper());

                result.WordCountBySub.TryAdd(comment.subreddit, new Dictionary <string, long>());

                foreach (var token in tokens)
                {
                    lastWords.Enqueue(token);

                    for (var i = 0; i < lastWords.Count; i++)
                    {
                        var words = lastWords.ToArray().Take(i + 1);

                        // Join our phrase together
                        var phrase = string.Join(" ", words);

                        result.WordCountBySub[comment.subreddit].TryAdd(phrase, 0);
                        result.WordCountBySub[comment.subreddit][phrase] += 1;
                    }
                }

                // After we're done with a comment, clear out the queue
                lastWords.Clear();
            }
        }
示例#7
0
 public void Reset()
 {
     _bldr.Reset(_slotLim, false);
     _queue.Clear();
 }
    public void SetNext(Vector3 nextPosition)
    {
        if (prevTime == 0)
        {
            prevTime         = PhotonNetwork.time;
            previousPosition = nextPosition;
            return;
        }
        double time = PhotonNetwork.time;

        if (previousPosition == nextPosition)
        {
            movemantLog.Clear();
        }
        else
        {
            float distance   = Vector3.Distance(previousPosition, nextPosition);
            float newTimeDif = (float)(time - prevTime);
            movemantLog.Enqueue(new MoveCheatDetectionLogItem {
                deltaTime = newTimeDif,
                speed     = (distance / newTimeDif),             // calculates real speed
                statSpeed = statController.stats.speed
            });

            float totalSpeed     = 0;
            float totalStatSpeed = 0;
            int   count          = movemantLog.list.Count;
            for (int i = 0; i < count; i++)
            {
                totalSpeed     += movemantLog.list[i].speed;
                totalStatSpeed += movemantLog.list[i].statSpeed;
            }

            float avgSpeed     = totalSpeed / count;
            float avgStatSpeed = totalStatSpeed / count;

            if (avgSpeed > (avgStatSpeed + MovemantCheatDetection.THRESHOLD))
            {
                if (cheatTimeSet == false)
                {
                    cheatTimeSet       = true;
                    cheatDetectionTime = Time.time;
                }

                if (Time.time - cheatDetectionTime > MovemantCheatDetection.CHEAT_TIME)
                {
                    if (CheatDetected != null)
                    {
                        CheatDetected();
                    }
                }
            }
            else
            {
                cheatDetectionTime = 0;
                cheatTimeSet       = false;
            }
        }

        prevTime         = time;
        previousPosition = nextPosition;
    }
示例#9
0
        /// <summary>
        /// Find an augmenting path an alternate it's matching. If an augmenting path
        /// was found then the search must be restarted. If a blossom was detected
        /// the blossom is contracted and the search continues.
        /// </summary>
        /// <returns>an augmenting path was found</returns>
        private bool Augment()
        {
            // reset data structures
            Arrays.Fill(even, nil);
            Arrays.Fill(odd, nil);
            uf.Clear();
            bridges.Clear();
            queue.Clear();

            // queue every unmatched vertex and place in the
            // even level (level = 0)
            for (int v = 0; v < graph.Order; v++)
            {
                if (subset.Contains(v) && matching.Unmatched(v))
                {
                    even[v] = v;
                    queue.Enqueue(v);
                }
            }

            // for each 'free' vertex, start a bfs search
            while (!queue.IsEmpty())
            {
                int v = queue.Poll();

                int d = graph.Degree(v);
                for (int j = 0; j < d; ++j)
                {
                    Edge e = graph.EdgeAt(v, j);
                    if (e.Bond == Bond.Single)
                    {
                        continue;
                    }
                    int w = e.Other(v);

                    if (!subset.Contains(w))
                    {
                        continue;
                    }

                    // the endpoints of the edge are both at even levels in the
                    // forest - this means it is either an augmenting path or
                    // a blossom
                    if (even[uf.Find(w)] != nil)
                    {
                        if (Check(v, w))
                        {
                            return(true);
                        }
                    }

                    // add the edge to the forest if is not already and extend
                    // the tree with this matched edge
                    else if (odd[w] == nil)
                    {
                        odd[w] = v;
                        int u = matching.Other(w);
                        // add the matched edge (potential though a blossom) if it
                        // isn't in the forest already
                        if (even[uf.Find(u)] == nil)
                        {
                            even[u] = w;
                            queue.Enqueue(u);
                        }
                    }
                }
            }

            // no augmenting paths, matching is maximum
            return(false);
        }