예제 #1
0
 public BufferedLoader(int size, int maxItems, BigIntBuffer buffer)
 {
     _size     = size;
     _maxItems = Math.Min(maxItems, BigNestedIntArray.MAX_ITEMS);
     _info     = new BigIntArray(size << 1); // pointer and count
     _info.Fill(EOD);
     _buffer = buffer;
 }
예제 #2
0
 /// <summary>
 /// resets loader. This also resets underlying BigIntBuffer.
 /// </summary>
 /// <param name="size"></param>
 /// <param name="maxItems"></param>
 /// <param name="buffer"></param>
 public void Reset(int size, int maxItems, BigIntBuffer buffer)
 {
     if (size >= Capacity)
     {
         throw new System.ArgumentException("unable to change size");
     }
     _size     = size;
     _maxItems = maxItems;
     _info.Fill(EOD);
     _buffer = buffer;
 }
예제 #3
0
        public void TestMemoryReuse()
        {
            int maxId = 4096;

            int[]        maxNumItems = { 1, 1, 2, 2, 3, 3, 3, 3, 1, 1 };
            int[]        minNumItems = { 1, 1, 0, 1, 0, 0, 2, 3, 1, 0 };
            int[]        count       = new int[maxId];
            BigIntBuffer buffer      = new BigIntBuffer();

            BigNestedIntArray.BufferedLoader loader = null;
            BigNestedIntArray nestedArray           = new BigNestedIntArray();
            Random            rand = new Random();

            for (int i = 0; i < maxNumItems.Length; i++)
            {
                loader = new BigNestedIntArray.BufferedLoader(maxId, BigNestedIntArray.MAX_ITEMS, buffer);
                for (int id = 0; id < maxId; id++)
                {
                    count[id] = 0;
                    int cnt = Math.Max(rand.Next(maxNumItems[i] + 1), minNumItems[i]);
                    for (int val = 0; val < cnt; val++)
                    {
                        if (loader.Add(id, val))
                        {
                            count[id]++;
                        }
                    }
                }

                nestedArray.Load(maxId, loader);

                int[] buf = new int[1024];
                for (int id = 0; id < maxId; id++)
                {
                    int cnt = nestedArray.GetData(id, buf);
                    Assert.AreEqual(count[id], cnt, "count[" + i + "," + id + "]");

                    if (cnt > 0)
                    {
                        for (int val = 0; val < cnt; val++)
                        {
                            Assert.AreEqual(val, buf[val], "item[" + i + "," + id + "," + val + "]");
                        }
                    }
                }

                if (i == 0)
                {
                    maxId = maxId * 2;
                    count = new int[maxId];
                }
            }
        }
예제 #4
0
        public void TestBufferedLoaderReuse()
        {
            int maxId = 5000;

            int[] maxNumItems = { 25, 50, 20, 100, 15, 500, 10, 1000, 5, 2000, 2 };
            int[,] count = new int[maxNumItems.Length, maxId];
            var buffer      = new BigIntBuffer();
            var loader      = new BigNestedIntArray.BufferedLoader(maxId, BigNestedIntArray.MAX_ITEMS, buffer);
            var nestedArray = new BigNestedIntArray[maxNumItems.Length];

            for (int i = 0; i < maxNumItems.Length; i++)
            {
                for (int id = 0; id < maxId; id++)
                {
                    int cnt = id % (maxNumItems[i] + 1);
                    for (int val = 0; val < cnt; val++)
                    {
                        if (loader.Add(id, val))
                        {
                            count[i, id]++;
                        }
                    }
                }
                nestedArray[i] = new BigNestedIntArray();
                nestedArray[i].Load(maxId, loader);

                loader.Reset(maxId, BigNestedIntArray.MAX_ITEMS, buffer);
            }

            for (int i = 0; i < maxNumItems.Length; i++)
            {
                int[] buf = new int[1024];
                for (int id = 0; id < maxId; id++)
                {
                    int cnt = nestedArray[i].GetData(id, buf);
                    Assert.AreEqual(count[i, id], cnt, "count[" + i + "," + id + "]");

                    if (cnt > 0)
                    {
                        for (int val = 0; val < cnt; val++)
                        {
                            Assert.AreEqual(val, buf[val], "item[" + i + "," + id + "," + val + "]");
                        }
                    }
                }
            }
        }
        public void TestBufferedLoaderReuse()
        {
            int maxId = 5000;
            int[] maxNumItems = { 25, 50, 20, 100, 15, 500, 10, 1000, 5, 2000, 2 };
            int[,] count = new int[maxNumItems.Length, maxId];
            var buffer = new BigIntBuffer();
            var loader = new BigNestedIntArray.BufferedLoader(maxId, BigNestedIntArray.MAX_ITEMS, buffer);
            var nestedArray = new BigNestedIntArray[maxNumItems.Length];

            for (int i = 0; i < maxNumItems.Length; i++)
            {
                for(int id = 0; id < maxId; id++)
                {
                    int cnt = id % (maxNumItems[i] + 1);
                    for(int val = 0; val < cnt; val++)
                    {
                        if(loader.Add(id, val)) count[i, id]++;
                    }
                }
                nestedArray[i] = new BigNestedIntArray();
                nestedArray[i].load(maxId, loader);
      
                loader.reset(maxId, BigNestedIntArray.MAX_ITEMS, buffer);
            }

            for (int i = 0; i < maxNumItems.Length; i++)
            {
                int[] buf = new int[1024];
                for(int id = 0; id < maxId; id++)
                {
                    int cnt = nestedArray[i].getData(id, buf);
                    Assert.AreEqual(count[i, id], cnt, "count[" + i + "," + id + "]");
      
                    if(cnt > 0)
                    {
                        for(int val = 0; val < cnt; val++)
                        {
                            Assert.AreEqual(val, buf[val], "item[" + i + "," + id + "," + val + "]");
                        }
                    }
                }
            }
        }
        public void TestMemoryReuse()
        {
            int maxId = 4096;
            int[] maxNumItems = { 1, 1, 2, 2, 3, 3, 3, 3, 1, 1 };
            int[] minNumItems = { 1, 1, 0, 1, 0, 0, 2, 3, 1, 0 };
            int[] count = new int[maxId];
            BigIntBuffer buffer = new BigIntBuffer();
            BigNestedIntArray.BufferedLoader loader = null;
            BigNestedIntArray nestedArray = new BigNestedIntArray();
            Random rand = new Random();

            for (int i = 0; i < maxNumItems.Length; i++)
            {
                loader = new BigNestedIntArray.BufferedLoader(maxId, BigNestedIntArray.MAX_ITEMS, buffer);
                for (int id = 0; id < maxId; id++)
                {
                    count[id] = 0;
                    int cnt = Math.Max(rand.Next(maxNumItems[i] + 1), minNumItems[i]);
                    for (int val = 0; val < cnt; val++)
                    {
                        if (loader.Add(id, val)) count[id]++;
                    }
                }

                nestedArray.Load(maxId, loader);

                int[] buf = new int[1024];
                for (int id = 0; id < maxId; id++)
                {
                    int cnt = nestedArray.GetData(id, buf);
                    Assert.AreEqual(count[id], cnt, "count[" + i + "," + id + "]");

                    if (cnt > 0)
                    {
                        for (int val = 0; val < cnt; val++)
                        {
                            Assert.AreEqual(val, buf[val], "item[" + i + "," + id + "," + val + "]");
                        }
                    }
                }

                if (i == 0)
                {
                    maxId = maxId * 2;
                    count = new int[maxId];
                }
            }
        }
예제 #7
0
 /// <summary>
 /// resets loader. This also resets underlying BigIntBuffer.
 /// </summary>
 /// <param name="size"></param>
 /// <param name="maxItems"></param>
 /// <param name="buffer"></param>
 public void Reset(int size, int maxItems, BigIntBuffer buffer)
 {
     if (size >= Capacity)
         throw new System.ArgumentException("unable to change size");
     _size = size;
     _maxItems = maxItems;
     _info.Fill(EOD);
     _buffer = buffer;
 }
예제 #8
0
 public BufferedLoader(int size, int maxItems, BigIntBuffer buffer)
 {
     _size = size;
     _maxItems = Math.Min(maxItems, BigNestedIntArray.MAX_ITEMS);
     _info = new BigIntArray(size << 1); // pointer and count
     _info.Fill(EOD);
     _buffer = buffer;
 }
        protected virtual BigNestedIntArray.BufferedLoader GetBufferedLoader(int maxdoc, BoboIndexReader.WorkArea workArea)
        {
            if (workArea == null)
            {
                return new BigNestedIntArray.BufferedLoader(maxdoc, _maxItems, new BigIntBuffer());
            }
            else
            {
                BigIntBuffer buffer = workArea.Get<BigIntBuffer>();
                if (buffer == null)
                {
                    buffer = new BigIntBuffer();
                    workArea.Put(buffer);
                }
                else
                {
                    buffer.Reset();
                }

                BigNestedIntArray.BufferedLoader loader = workArea.Get<BigNestedIntArray.BufferedLoader>();
                if (loader == null || loader.Capacity < maxdoc)
                {
                    loader = new BigNestedIntArray.BufferedLoader(maxdoc, _maxItems, buffer);
                    workArea.Put(loader);
                }
                else
                {
                    loader.Reset(maxdoc, _maxItems, buffer);
                }
                return loader;
            }
        }