Ejemplo n.º 1
0
        public void TestQueueThenRemoveAll()
        {
            FastQueue <string> q = new FastQueue <string>();

            q.Enqueue("a");
            q.Enqueue("b");
            q.Enqueue("c");
            q.Enqueue("d");
            q.Enqueue("e");
            StringBuilder buf = new StringBuilder();

            while (q.Count > 0)
            {
                string o = q.Dequeue();
                buf.Append(o);
                if (q.Count > 0)
                {
                    buf.Append(" ");
                }
            }
            Assert.AreEqual(0, q.Count, "queue should be empty");
            string expecting = "a b c d e";
            string found     = buf.ToString();

            Assert.AreEqual(expecting, found);
        }
Ejemplo n.º 2
0
 public void TestGetFromEmptyQueueAfterClear()
 {
     FastQueue<string> q = new FastQueue<string>();
     q.Enqueue("a");
     q.Enqueue("b");
     q.Clear();
     q.Dequeue();
 }
Ejemplo n.º 3
0
        public void TestGetFromEmptyQueueAfterClear()
        {
            FastQueue <string> q = new FastQueue <string>();

            q.Enqueue("a");
            q.Enqueue("b");
            q.Clear();
            q.Dequeue();
        }
Ejemplo n.º 4
0
        public void ConstructorWithSingleArgument()
        {
            const int       givenItem = 0;
            FastQueue <int> q         = new FastQueue <int>(givenItem);

            Assert.IsTrue(q.Count == 1, "FastQueue should have one item but doesn't!");
            Assert.IsTrue(q.Any(), "FastQueue should have one item but doesn't!");
            Assert.IsTrue(q.Peek() == givenItem, "FastQueue.Peek() didn't return the expected value");
        }
Ejemplo n.º 5
0
        public void DequeuePerformanceTest()
        {
            List <int> storage = new List <int>(maxNumber);

            for (int i = 0; i <= maxNumber; i++)
            {
                storage.Add(i);
            }

            List <int>       list   = new List <int>(storage);
            Queue <int>      q      = new Queue <int>(storage);
            LinkedList <int> linked = new LinkedList <int>(storage);
            FastQueue <int>  fq     = new FastQueue <int>(storage);

            Stopwatch listTimer = Stopwatch.StartNew();

            while (list.Any())
            {
                list.RemoveAt(0);
                //list.TrimExcess();
            }
            listTimer.Stop();
            float listTime = listTimer.ElapsedTicks;

            Stopwatch qTimer = Stopwatch.StartNew();

            while (q.Any())
            {
                q.Dequeue();
                //q.TrimExcess();
            }
            qTimer.Stop();
            float qTime = qTimer.ElapsedTicks;

            Stopwatch linkedTimer = Stopwatch.StartNew();

            while (linked.Any())
            {
                linked.RemoveFirst();
            }
            linkedTimer.Stop();
            float linkedTime = linkedTimer.ElapsedTicks;

            Stopwatch fqTimer = Stopwatch.StartNew();

            while (fq.Any())
            {
                fq.Dequeue();
            }
            fqTimer.Stop();
            float fqTime = fqTimer.ElapsedTicks;

            Assert.IsTrue(listTime > fqTime, "List is faster than FastQueue! {0} to {1}, listTime, fqTime");
            Assert.IsTrue(qTime > fqTime, "Queue is faster than FastQueue! {0} to {1}", qTime, fqTime);
            Assert.IsTrue(linkedTime > fqTime, "linked list is faster than FastQueue! {0} to {1}", linkedTime, fqTime);
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            FastQueue <int> queue = new FastQueue <int>();

            for (int i = 1; i <= 5; i++)
            {
                queue.Enqueue(i);
            }
            queue.Dequeue();

            Console.WriteLine(string.Join(", ", queue));
        }
Ejemplo n.º 7
0
        void CastInitial(int startX, int startZ, int endX, int endZ)
        {
            //initial loop for making fullbright spots
            int oneY = width * length, maxY = height - 1;

            byte[] blocks = game.World.blocks;

            FastQueue block_queue = new FastQueue(32 * 32 * 32);
            FastQueue sun_queue   = new FastQueue(32 * 32 * 32);

            for (int i = 0; i < lightPasses.Length; i++)
            {
                // Light passes through a block if a) doesn't block light b) block isn't full block
                lightPasses[i] =
                    !game.BlockInfo.BlocksLight[i] ||
                    game.BlockInfo.MinBB[i] != OpenTK.Vector3.Zero ||
                    game.BlockInfo.MaxBB[i] != OpenTK.Vector3.One;
            }

            for (int z = startZ; z < endZ; z++)
            {
                int horOffset = startX + (z * width);
                for (int x = startX; x < endX; x++)
                {
                    int index = (maxY * oneY) + horOffset;
                    horOffset++;                     // increase horizontal position
                    if (lightPasses[blocks[index]])
                    {
                        sun_queue.Enqueue(index);
                        lightLevels[x, maxY, z] &= 0x0F;
                        lightLevels[x, maxY, z] |= 0xF0;
                    }

                    for (int y = maxY; y >= 0; y--)
                    {
                        //if the current block is fullbright assign the fullest block brightness to the higher 4 bits
                        if (info.FullBright[blocks[index]])
                        {
                            block_queue.Enqueue(index);
                            lightLevels[x, y, z] &= 0xF0;
                            lightLevels[x, y, z] |= 0x0F;
                        }
                        index -= oneY;                         // reduce y position
                    }
                }
            }

            Console.BufferHeight = short.MaxValue - 10;
            Console.WriteLine(sun_queue.count + " - " + block_queue.count);
            CastLight(sun_queue, true, 0xF0, 16);
            CastLight(block_queue, false, 0x0F, 1);
        }
Ejemplo n.º 8
0
        public void TestQueueNoRemove()
        {
            FastQueue <string> q = new FastQueue <string>();

            q.Enqueue("a");
            q.Enqueue("b");
            q.Enqueue("c");
            q.Enqueue("d");
            q.Enqueue("e");
            string expecting = "a b c d e";
            string found     = q.ToString();

            Assert.AreEqual(expecting, found);
        }
Ejemplo n.º 9
0
 public void TestGetFromEmptyQueue()
 {
     FastQueue<string> q = new FastQueue<string>();
     string msg = null;
     try
     {
         q.Dequeue();
     }
     catch (IndexOutOfRangeException nsee)
     {
         msg = nsee.Message;
     }
     string expecting = "queue index 0 > last index -1";
     string found = msg;
     Assert.AreEqual( expecting, found );
 }
Ejemplo n.º 10
0
        public void TestGetFromEmptyQueue()
        {
            FastQueue <string> q   = new FastQueue <string>();
            string             msg = null;

            try
            {
                q.Dequeue();
            }
            catch (InvalidOperationException nsee)
            {
                msg = nsee.Message;
            }
            string expecting = "queue index 0 > last index -1";
            string found     = msg;

            Assert.AreEqual(expecting, found);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Test metoda. Potrebne su dvije ulazne datoteke datoteke, InputFile i OutputFile. U jednoj su
        /// ulazni podatci za značajku, a u drugoj referentni podatci (izlaz iz Matlaba).
        /// Ulazni podatci i izlaz i matlaba se spremaju koristeći sljedeću sintaksu:
        /// save('ime_datoteke.txt','varijabla','-ascii','-double','-tabs');
        /// </summary>
        /// <param name="InputFile">Datoteka s ulaznim podatcima</param>
        /// <param name="OutputFile">Datoteka s izlaznim podatcima</param>
        /// <param name="DataProvider">DataProvider za IFeature</param>
        /// <param name="Feature">Značajka</param>
        /// <param name="SubWindowLength">Dužina prozora u uzorcima</param>
        /// <param name="SubWindowShift">Dužina pomaka u uzorcima</param>
        /// <returns></returns>
        public static TestResult ExecuteTest(string InputFile, string OutputFile, IDataProvider DataProvider, IFeature Feature, int SubWindowLength, int SubWindowShift)
        {
            List <double> InputData  = ReadFromFile(InputFile);
            List <double> OutputData = ReadFromFile(OutputFile);

            FastQueue <double> Data   = new FastQueue <double>(100000);
            List <double>      Result = new List <double>();

            Data.Enqueue(InputData.ToArray());

            while (Data.Count > SubWindowLength)
            {
                List <double> CurrentData;

                CurrentData = Data.Peek(SubWindowLength);
                Data.Delete(SubWindowShift);
                DataProvider.Data = CurrentData;

                Feature.Compute();
                Result.Add(Feature.Feature);
            }

            double absdiff = 0;

            for (int i = 0; i < Result.Count || i < OutputData.Count; i++)
            {
                absdiff += Math.Abs(Result[i] - OutputData[i]);
            }

            TestResult tr = new TestResult();

            tr.AbsoluteDifference = absdiff;
            if (absdiff < 100)
            {
                tr.Success = true;
            }
            else
            {
                tr.Success = false;
            }


            return(tr);
        }
Ejemplo n.º 12
0
        public void TestQueueThenRemoveOneByOne()
        {
            StringBuilder      buf = new StringBuilder();
            FastQueue <string> q   = new FastQueue <string>();

            q.Enqueue("a");
            buf.Append(q.Dequeue());
            q.Enqueue("b");
            buf.Append(q.Dequeue());
            q.Enqueue("c");
            buf.Append(q.Dequeue());
            q.Enqueue("d");
            buf.Append(q.Dequeue());
            q.Enqueue("e");
            buf.Append(q.Dequeue());
            Assert.AreEqual(0, q.Count, "queue should be empty");
            string expecting = "abcde";
            string found     = buf.ToString();

            Assert.AreEqual(expecting, found);
        }
Ejemplo n.º 13
0
        public void EnqueueDequeueTest()
        {
            FastQueue <int> q = new FastQueue <int>();

            for (int i = 0; i < maxNumber; i++)
            {
                q.Enqueue(i);
            }

            Assert.IsTrue(q.Count == maxNumber);

            int expected = 0;

            for (int i = maxNumber - 1; i >= 0; i--)
            {
                Assert.IsTrue(q.Peek() == expected, "Peek() does not equal i");
                Assert.IsTrue(q.Dequeue() == expected++, "Dequeue() does not equal i");
            }

            Assert.IsTrue(q.Count == 0, "Count is not 0");
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Test metoda. Potrebne su dvije ulazne datoteke datoteke, InputFile i OutputFile. U jednoj su
        /// ulazni podatci za značajku, a u drugoj referentni podatci (izlaz iz Matlaba).
        /// Ulazni podatci i izlaz i matlaba se spremaju koristeći sljedeću sintaksu:
        /// save('ime_datoteke.txt','varijabla','-ascii','-double','-tabs');
        /// </summary>
        /// <param name="InputFile">Datoteka s ulaznim podatcima</param>
        /// <param name="OutputFile">Datoteka s izlaznim podatcima</param>
        /// <param name="DataProvider">DataProvider za IFeature</param>
        /// <param name="Feature">Značajka</param>
        /// <param name="SubWindowLength">Dužina prozora u uzorcima</param>
        /// <param name="SubWindowShift">Dužina pomaka u uzorcima</param>
        /// <returns></returns>
        public static TestResult ExecuteTest(string InputFile, string OutputFile, IDataProvider DataProvider, IFeature Feature, int SubWindowLength, int SubWindowShift)
        {
            List<double> InputData = ReadFromFile(InputFile);
            List<double> OutputData = ReadFromFile(OutputFile);

            FastQueue<double> Data = new FastQueue<double>(100000);
            List<double> Result = new List<double>();

            Data.Enqueue(InputData.ToArray());

            while (Data.Count > SubWindowLength)
            {
                List<double> CurrentData;

                CurrentData = Data.Peek(SubWindowLength);
                Data.Delete(SubWindowShift);
                DataProvider.Data = CurrentData;

                Feature.Compute();
                Result.Add(Feature.Feature);

            }

            double absdiff = 0;
            for (int i = 0; i < Result.Count || i < OutputData.Count; i++)
            {
                absdiff += Math.Abs(Result[i] - OutputData[i]);
            }

            TestResult tr = new TestResult();
            tr.AbsoluteDifference = absdiff;
            if (absdiff < 100)
                tr.Success = true;
            else
                tr.Success = false;

            return tr;
        }
Ejemplo n.º 15
0
        public AbstractClassifier()
        {
            Results = new List<EmoClassifierResult>();
            SubData = new FastQueue<double>(500000);
            SubFeatures = new List<IFeature>();
            SubResults = new Dictionary<IFeature,FastQueue<double>>();
            FinalFeatures = new List<double>();
            SuperFeatures = new Dictionary<IFeature,List<IFeature>>();

            this.SubWindowLength = 1102; // 44100 [samples per second] * 0.025 [25 milisecond interval]
            this.SubWindowShift = 661; // 44100 [samples per second] * 0.015 [15 milisecond interval]

            this.SuperWindowLength = 80; // 44100 [samples per second] / 1102 [SubFeatures per second] * 2 [seconds]
            this.SuperWindowShift = 40; // 44100 [samples per second] / 1102 [SubFeatures per second] * 1 [seconds]

            //Napravi feature
            MakeFeatures();

            foreach (IFeature f in SubFeatures)
            {
                SubResults.Add(f,new FastQueue<double>(10000));
            }
        }
Ejemplo n.º 16
0
        public void EmptyConstructorAndEmptyQueueTest()
        {
            FastQueue <int> q = new FastQueue <int>();

            Assert.IsTrue(q.Count == 0, "Count is non-zero!");
            Assert.IsTrue(!q.Any(), "FastQueue has a member when empty!");

            q.Clear();

            Assert.IsTrue(q.Count() == 0, "Count is non-zero!");
            Assert.IsTrue(!q.Any(), "FastQueue has a member when empty!");

            bool looped = false;

            foreach (int i in q)
            {
                looped = true;
            }
            Assert.IsTrue(!looped, "FastQueue looped even though empty!");

            Assert.ThrowsException <InvalidOperationException>(() => q.Dequeue(), "FastQueue didn't throw InvalidOperationException on empty Dequeue()");

            Assert.ThrowsException <InvalidOperationException>(() => q.Peek(), "FastQueue didn't throw InvalidOperationException on empty Peek()");
        }
Ejemplo n.º 17
0
        public void ConstructorWithCollectionAndInterationTest()
        {
            List <string> food = new List <string>();

            food.Add("Pizza");

            FastQueue <string> q = new FastQueue <string>(food);

            Assert.IsTrue(q.Count == 1, "FastQueue should have one item but doesn't!");
            Assert.IsTrue(q.Peek() == food[0], "FastQueue is missing the expected value!");

            food.Add("Eggs");
            q = new FastQueue <string>(food);
            Assert.IsTrue(q.Count == 2, "FastQueue should have two items but doesn't!");
            Assert.IsTrue(q.Peek() == food[0]);
            Assert.IsTrue(q.Dequeue() == food[0]);
            Assert.IsTrue(q.Peek() == food[1]);
            Assert.IsTrue(q.Dequeue() == food[1]);
            Assert.IsTrue(q.Count == 0);
            Assert.IsFalse(q.Any());

            food.Add("Chicken");
            food.Add("Bratz");
            food.Add("Cheese");

            q = new FastQueue <string>(food);
            Assert.IsTrue(q.Count == 5);

            for (int i = 0; i < food.Count; i++)
            {
                string f = food[i];
                Assert.IsTrue(f == q.Peek());
                Assert.IsTrue(f == q.Dequeue());
            }
            Assert.ThrowsException <InvalidOperationException>(() => q.Peek());
        }
Ejemplo n.º 18
0
 public LuaObjectMap()
 {
     list = new List <object>();
     pool = new FastQueue();
 }
Ejemplo n.º 19
0
 public void TestGetFromEmptyQueue()
 {
     FastQueue<string> q = new FastQueue<string>();
     q.Dequeue();
 }
Ejemplo n.º 20
0
        public void TestGetFromEmptyQueue()
        {
            FastQueue <string> q = new FastQueue <string>();

            q.Dequeue();
        }
Ejemplo n.º 21
0
 public LuaObjectMap()
 {
     list = new List<object>();
     pool = new FastQueue();
 }
Ejemplo n.º 22
0
        public void EnqueuePerformanceTest()
        {
            Stopwatch  listWatch = Stopwatch.StartNew();
            List <int> list      = new List <int>();

            for (int i = 0; i <= maxNumber; i++)
            {
                list.Add(i);
                //list.TrimExcess();
            }
            listWatch.Stop();
            float listElapsedTime = listWatch.ElapsedTicks;

            list.Clear();

            GC.Collect();
            GC.WaitForPendingFinalizers();

            Stopwatch   qWatch = Stopwatch.StartNew();
            Queue <int> q      = new Queue <int>();

            for (int i = 0; i <= maxNumber; i++)
            {
                q.Enqueue(i);
                //q.TrimExcess();
            }
            qWatch.Stop();
            float qElapsedTime = qWatch.ElapsedTicks;

            q.Clear();

            GC.Collect();
            GC.WaitForPendingFinalizers();

            Stopwatch        linkedWatch = Stopwatch.StartNew();
            LinkedList <int> linked      = new LinkedList <int>();

            for (int i = 0; i <= maxNumber; i++)
            {
                linked.AddLast(i);
            }
            linkedWatch.Stop();
            float linkedElapedTime = linkedWatch.ElapsedTicks;

            linked.Clear();

            GC.Collect();
            GC.WaitForPendingFinalizers();

            Stopwatch       fqWatch = Stopwatch.StartNew();
            FastQueue <int> fq      = new FastQueue <int>();

            for (int i = 0; i <= maxNumber; i++)
            {
                fq.Enqueue(i);
            }
            fqWatch.Stop();
            float fqElapsedTime = fqWatch.ElapsedTicks;

            fq.Clear();

            GC.Collect();
            GC.WaitForPendingFinalizers();

            Assert.IsTrue(listElapsedTime > fqElapsedTime, "list is faster than FastQueue! {0} to {1}", listElapsedTime, fqElapsedTime);
            Assert.IsTrue(qElapsedTime > fqElapsedTime, "q is faster than FastQueue! {0} to {1}", qElapsedTime, fqElapsedTime);
            Assert.IsTrue(linkedElapedTime > fqElapsedTime, "linked list is faster than FastQueue! {0} to {1}", linkedElapedTime, fqElapsedTime);
        }
Ejemplo n.º 23
0
 public void Setup()
 {
     this._fastQueue = new FastQueue <int>();
     this._slowQueue = new SlowQueue <int>();
 }
Ejemplo n.º 24
0
 public void TestQueueThenRemoveOneByOne()
 {
     StringBuilder buf = new StringBuilder();
     FastQueue<string> q = new FastQueue<string>();
     q.Enqueue( "a" );
     buf.Append( q.Dequeue() );
     q.Enqueue( "b" );
     buf.Append( q.Dequeue() );
     q.Enqueue( "c" );
     buf.Append( q.Dequeue() );
     q.Enqueue( "d" );
     buf.Append( q.Dequeue() );
     q.Enqueue( "e" );
     buf.Append( q.Dequeue() );
     Assert.AreEqual( 0, q.Count, "queue should be empty" );
     string expecting = "abcde";
     string found = buf.ToString();
     Assert.AreEqual( expecting, found );
 }
Ejemplo n.º 25
0
        public static async Task MeasureEnqueueDequeueAllAsync(int nbItems)
        {
            var emptyQueue     = new Queue(nbItems);
            var emptyFastQueue = new FastQueue <long>(nbItems);

            (string, TimeSpan)[] result = new (string, TimeSpan)[0];
Ejemplo n.º 26
0
 public void TestQueueNoRemove()
 {
     FastQueue<string> q = new FastQueue<string>();
     q.Enqueue( "a" );
     q.Enqueue( "b" );
     q.Enqueue( "c" );
     q.Enqueue( "d" );
     q.Enqueue( "e" );
     string expecting = "a b c d e";
     string found = q.ToString();
     Assert.AreEqual( expecting, found );
 }
Ejemplo n.º 27
0
        void CastLight(FastQueue queue, bool sunlight, byte mask, byte step)
        {
            BlockInfo info = game.BlockInfo;

            byte[] blocks = game.World.blocks;
            int    maxX = width - 1, maxY = height - 1, maxZ = length - 1;
            int    oneY    = width * length;
            byte   invMask = (byte)~mask;

            while (queue.count > 0)
            {
                int idx; queue.Dequeue(out idx);

                int  x     = idx % width;
                int  y     = idx / oneY;
                int  z     = (idx / width) % length;
                byte light = lightLevels[x, y, z];

                if (light == step)
                {
                    break;                                // doesn't cast further
                }
                light -= step;

                if (x > 0 && lightPasses[blocks[idx - 1]] && light > (lightLevels[x - 1, y, z] & mask))
                {
                    lightLevels[x - 1, y, z] &= invMask;
                    lightLevels[x - 1, y, z] |= light;
                    queue.Enqueue(idx - 1);
                }
                if (x < maxX && lightPasses[blocks[idx + 1]] && light > (lightLevels[x + 1, y, z] & mask))
                {
                    lightLevels[x + 1, y, z] &= invMask;
                    lightLevels[x + 1, y, z] |= light;
                    queue.Enqueue(idx + 1);
                }
                if (z > 0 && lightPasses[blocks[idx - width]] && light > (lightLevels[x, y, z - 1] & mask))
                {
                    lightLevels[x, y, z - 1] &= invMask;
                    lightLevels[x, y, z - 1] |= light;
                    queue.Enqueue(idx - width);
                }
                if (z < maxZ && lightPasses[blocks[idx + width]] && light > (lightLevels[x, y, z + 1] & mask))
                {
                    lightLevels[x, y, z + 1] &= invMask;
                    lightLevels[x, y, z + 1] |= light;
                    queue.Enqueue(idx + width);
                }

                if (y < maxY && lightPasses[blocks[idx + oneY]] && light > (lightLevels[x, y + 1, z] & mask))
                {
                    lightLevels[x, y + 1, z] &= invMask;
                    lightLevels[x, y + 1, z] |= light;
                }

                // sunlight should propagate downwards without losing light
                if (sunlight && light == 0xE0)
                {
                    light += step;
                }

                if (y > 0 && lightPasses[blocks[idx - oneY]] && light > (lightLevels[x, y - 1, z] & mask))
                {
                    lightLevels[x, y - 1, z] &= invMask;
                    lightLevels[x, y - 1, z] |= light;
                    queue.Enqueue(idx - oneY);
                }
            }
        }
Ejemplo n.º 28
0
 public void TestQueueThenRemoveAll()
 {
     FastQueue<string> q = new FastQueue<string>();
     q.Enqueue( "a" );
     q.Enqueue( "b" );
     q.Enqueue( "c" );
     q.Enqueue( "d" );
     q.Enqueue( "e" );
     StringBuilder buf = new StringBuilder();
     while ( q.Count > 0 )
     {
         string o = q.Dequeue();
         buf.Append( o );
         if ( q.Count > 0 )
             buf.Append( " " );
     }
     Assert.AreEqual( 0, q.Count, "queue should be empty" );
     string expecting = "a b c d e";
     string found = buf.ToString();
     Assert.AreEqual( expecting, found );
 }