Example #1
0
        private static void DivideNode(BoundingRectangle space, INode <T> input, Node <T> output, ArrayPool <float> pool, Treemap <T> map)
        {
            //Recursion base case
            if (input.Count == 0)
            {
                return;
            }

            var h = pool.Allocate(input.Count);
            var v = pool.Allocate(input.Count);

            //Take the split with the least bad aspect ratio
            if (MeasureSizes(false, space, input, h) < MeasureSizes(true, space, input, v))
            {
                //Free the unused array
                pool.Free(v);

                SplitHorizontal(space, input, output, h, pool, map);
            }
            else
            {
                //Free the unused array
                pool.Free(h);

                SplitVertical(space, input, output, v, pool, map);
            }
        }
Example #2
0
        private ArrayPool <double> Pool;//= new ArrayPool<double>();


        /// <summary>
        /// extracts a matrix from pool or creates a new one and associate with current pool and return it.
        /// </summary>
        /// <param name="rows"></param>
        /// <param name="columns"></param>
        /// <returns></returns>
        public Matrix Allocate(int rows, int columns)
        {
            var arr = Pool.Allocate(rows * columns);

            for (var i = 0; i < arr.Length; i++)
            {
                arr[i] = 0.0;
            }

            var buf = new Matrix(rows, columns, ref arr);

            buf.UsePool = true;
            buf.Pool    = this;

            TotalRents++;

            return(buf);
        }
Example #3
0
 public void AssertThat_AllocatedArray_IsLargeEnough_WhenAllocatingNew()
 {
     Assert.IsTrue(_pool.Allocate(10).Length >= 10);
 }