Ejemplo n.º 1
0
 public void build(Vector3[] points, int[] ids)
 {
     this.points = points;
     this.ids    = ids;
     _root       = build(0, points.Length, 0);
     _priQueue   = new FixedSizePriorityQueue <PriorityPoint>(0);
 }
Ejemplo n.º 2
0
        public void ClasShouldOnlyStoreNLArgestValuesTest()
        {
            foreach (int size in new List <int>()
            {
                10, 100, 150
            })
            {
                FixedSizePriorityQueue <int, bool> testQ = new FixedSizePriorityQueue <int, bool>(size);
                int        n    = 4 * size;
                List <int> keys = new List <int>(n);
                for (int i = 0; i < n; i++)
                {
                    int key;
                    lock (syncLock)
                    {
                        key = Rnd.Next();
                    }

                    keys.Add(key);
                    testQ.Enqueue(key, true);
                }
                keys.Sort();
                List <int> largestKeys = keys.Skip(n - size).ToList();
                Assert.AreEqual(size, largestKeys.Count);

                var result = testQ.ToList()
                             .Select(kvp => kvp.Key)
                             .ToList();
                result.Sort();
                Assert.IsTrue(largestKeys.SequenceEqual(result));
            }
        }
Ejemplo n.º 3
0
        public void ClasEnqueueTest()
        {
            int maxSize = 3;

            FixedSizePriorityQueue <float, int> testQ = new FixedSizePriorityQueue <float, int>(maxSize);

            Assert.IsNull(testQ.Peek());
            Assert.AreEqual(0, testQ.Count);

            float key   = -5;
            int   value = 1;

            testQ.Enqueue(key, value);

            Assert.AreEqual(1, testQ.Count);
            Assert.AreEqual(key, testQ.Peek().Value.Key);
            Assert.AreEqual(value, testQ.Peek().Value.Value);

            key   = 10;
            value = 2;

            testQ.Enqueue(key, value);

            Assert.AreEqual(2, testQ.Count);
            Assert.AreEqual(-5, testQ.Peek().Value.Key);
            Assert.AreEqual(1, testQ.Peek().Value.Value);

            //Updates the top of the queue when higher prio elements are added
            key   = -10;
            value = 3;

            testQ.Enqueue(key, value);

            Assert.AreEqual(3, testQ.Count);
            Assert.AreEqual(key, testQ.Peek().Value.Key);
            Assert.AreEqual(value, testQ.Peek().Value.Value);

            //When the queue is full, doesn't change its size
            //and doesn't insert a new element with lower prio than top's
            key   = -11;
            value = 4;

            testQ.Enqueue(key, value);

            Assert.AreEqual(3, testQ.Count);
            Assert.AreEqual(-10, testQ.Peek().Value.Key);
            Assert.AreEqual(3, testQ.Peek().Value.Value);

            //When the queue is full, doesn't change its size
            //and does insert a new element with hiher prio than top's
            key   = -9;
            value = 5;

            testQ.Enqueue(key, value);

            Assert.AreEqual(3, testQ.Count);
            Assert.AreEqual(key, testQ.Peek().Value.Key);
            Assert.AreEqual(value, testQ.Peek().Value.Value);
        }
Ejemplo n.º 4
0
        static public List <BeamSearchStatus> GetTopNBSS(List <BeamSearchStatus> bssList, int topN)
        {
            FixedSizePriorityQueue <ComparableItem <BeamSearchStatus> > q = new FixedSizePriorityQueue <ComparableItem <BeamSearchStatus> >(topN, new ComparableItemComparer <BeamSearchStatus>(false));

            for (int i = 0; i < bssList.Count; i++)
            {
                q.Enqueue(new ComparableItem <BeamSearchStatus>(bssList[i].Score, bssList[i]));
            }

            return(q.Select(x => x.Value).ToList());
        }
Ejemplo n.º 5
0
        public static List <BeamSearchStatus> GetTopNBSS(List <BeamSearchStatus> bssList, int topN)
        {
            var q = new FixedSizePriorityQueue <ComparableItem <BeamSearchStatus> >(topN, new ComparableItemComparer <BeamSearchStatus>(false));

            foreach (var status in bssList)
            {
                q.Enqueue(new ComparableItem <BeamSearchStatus>(status.Score, status));
            }

            return(q.Select(x => x.Value).ToList());
        }
Ejemplo n.º 6
0
        public List <int> GetTopNMaxWeightIdx(int topN)
        {
            float[] weights = ToWeightArray();
            FixedSizePriorityQueue <ComparableItem <int> > q = new FixedSizePriorityQueue <ComparableItem <int> >(topN, new ComparableItemComparer <int>(true));

            for (int i = 0; i < weights.Length; i++)
            {
                q.Enqueue(new ComparableItem <int>(weights[i], i));
            }

            return(q.Select(x => x.Value).ToList());
        }
Ejemplo n.º 7
0
        public void ClasPeekTest()
        {
            FixedSizePriorityQueue <float, int> testQ = new FixedSizePriorityQueue <float, int>(10);

            Assert.IsNull(testQ.Peek());

            testQ = new FixedSizePriorityQueue <float, int>(
                new List <KeyValuePair <float, int> >()
            {
                new KeyValuePair <float, int>(-10, 22)
            },
                10);
            Assert.AreEqual(1, testQ.Count);
            Assert.IsNotNull(testQ.Peek());
            Assert.AreEqual(1, testQ.Count);
            Assert.AreEqual(-10, testQ.Peek().Value.Key);
            Assert.AreEqual(22, testQ.Peek().Value.Value);
        }
Ejemplo n.º 8
0
        public void ClasFixedSizePriorityQueueConstructorTest()
        {
            FixedSizePriorityQueue <float, int> q = new FixedSizePriorityQueue <float, int>(1);

            Assert.IsNotNull(q);
            Assert.IsTrue(q.IsEmpty);
            Assert.IsFalse(q.IsFull);

            q = new FixedSizePriorityQueue <float, int>(Elements.Take(1), 2);
            Assert.IsNotNull(q);
            Assert.IsFalse(q.IsEmpty);
            Assert.IsFalse(q.IsFull);

            q = new FixedSizePriorityQueue <float, int>(Elements.Take(2), 2);
            Assert.IsNotNull(q);
            Assert.IsFalse(q.IsEmpty);
            Assert.IsTrue(q.IsFull);

            q = new FixedSizePriorityQueue <float, int>(Elements.Take(3), 3);
            Assert.IsNotNull(q);
            Assert.IsFalse(q.IsEmpty);
            Assert.IsTrue(q.IsFull);
        }
Ejemplo n.º 9
0
 public void build(Entity[] points)
 {
     this.points = points;
     _root       = build(0, points.Length, 0);
     _priQueue   = new FixedSizePriorityQueue <PriorityPoint>(0);
 }