Exemplo n.º 1
0
        /// <summary>
        /// Finds the next unused cache page index. Marks it as used.
        /// Assigns the page information that comes from the memory pool.
        /// </summary>
        /// <returns>The Page Index</returns>
        public int AddNewPage(int positionIndex, IntPtr locationOfPage, int memoryPoolIndex)
        {
            if (m_disposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }
            InternalPageMetaData cachePage;

            cachePage.MemoryPoolIndex = memoryPoolIndex;
            cachePage.LocationOfPage  = (byte *)locationOfPage;
            cachePage.ReferencedCount = 0;
            int pageIndex = m_listOfPages.AddValue(cachePage);

            m_pageIndexLookupByPositionIndex.Add(positionIndex, pageIndex);
            return(pageIndex);
        }
        public void TestCount()
        {
            NullableLargeArray <int> array = new NullableLargeArray <int>();

            for (int x = 0; x < 100000; x++)
            {
                array.AddValue(x);
            }

            for (int x = 0; x < 100000; x += 2)
            {
                if (array[x] != x)
                {
                    throw new Exception();
                }
                array.SetNull(x);
            }

            if (array.Capacity != 100000 + (1024 - (100000 & 1023)))
            {
                throw new Exception();
            }
            if (array.CountUsed != 50000)
            {
                throw new Exception();
            }
            if (array.CountFree != array.Capacity - 50000)
            {
                throw new Exception();
            }


            int i;

            for (int x = 1; x < 100000; x += 2)
            {
                if (!array.TryGetValue(x, out i))
                {
                    throw new Exception();
                }
                if (i != x)
                {
                    throw new Exception();
                }
            }

            for (int x = 0; x < 100000; x += 2)
            {
                if (array.TryGetValue(x, out i))
                {
                    throw new Exception();
                }
            }

            if (array.Count() != 50000)
            {
                throw new Exception();
            }

            i = 1;
            foreach (int item in array)
            {
                if (item != i)
                {
                    throw new Exception();
                }
                i += 2;
            }

            if (array.Select(x => x).Count() != 50000)
            {
                throw new Exception();
            }


            for (int x = 1; x < 100000; x += 2)
            {
                array.OverwriteValue(x, -1);
            }

            for (int x = 1; x < 100000; x += 2)
            {
                if (array[x] != -1)
                {
                    throw new Exception();
                }
            }
        }
        public void TestCount()
        {
            NullableLargeArray<int> array = new NullableLargeArray<int>();

            for (int x = 0; x < 100000; x++)
            {
                array.AddValue(x);
            }

            for (int x = 0; x < 100000; x += 2)
            {
                if (array[x] != x)
                    throw new Exception();
                array.SetNull(x);
            }

            if (array.Capacity != 100000 + (1024 - (100000 & 1023)))
                throw new Exception();
            if (array.CountUsed != 50000)
                throw new Exception();
            if (array.CountFree != array.Capacity - 50000)
                throw new Exception();


            int i;
            for (int x = 1; x < 100000; x += 2)
            {
                if (!array.TryGetValue(x, out i))
                    throw new Exception();
                if (i != x)
                    throw new Exception();
            }

            for (int x = 0; x < 100000; x += 2)
            {
                if (array.TryGetValue(x, out i))
                    throw new Exception();
            }

            if (array.Count() != 50000)
                throw new Exception();

            i = 1;
            foreach (var item in array)
            {
                if (item != i)
                    throw new Exception();
                i += 2;
            }

            if (array.Select(x => x).Count() != 50000)
                throw new Exception();


            for (int x = 1; x < 100000; x += 2)
            {
                array.OverwriteValue(x, -1);
            }

            for (int x = 1; x < 100000; x += 2)
            {
                if (array[x] != -1)
                    throw new Exception();
            }

        }