Пример #1
0
        public virtual void TestSingleWriterReader()
        {
            Counter      bytesUsed = Util.Counter.NewCounter();
            IntBlockPool pool      = new IntBlockPool(new ByteTrackingAllocator(bytesUsed));

            for (int j = 0; j < 2; j++)
            {
                IntBlockPool.SliceWriter writer = new IntBlockPool.SliceWriter(pool);
                int start = writer.StartNewSlice();
                int num   = AtLeast(100);
                for (int i = 0; i < num; i++)
                {
                    writer.WriteInt(i);
                }

                int upto = writer.CurrentOffset;
                IntBlockPool.SliceReader reader = new IntBlockPool.SliceReader(pool);
                reader.Reset(start, upto);
                for (int i = 0; i < num; i++)
                {
                    Assert.AreEqual(i, reader.ReadInt());
                }
                Assert.IsTrue(reader.EndOfSlice());
                if (Random().NextBoolean())
                {
                    pool.Reset(true, false);
                    Assert.AreEqual(0, bytesUsed.Get());
                }
                else
                {
                    pool.Reset(true, true);
                    Assert.AreEqual(IntBlockPool.INT_BLOCK_SIZE * RamUsageEstimator.NUM_BYTES_INT, bytesUsed.Get());
                }
            }
        }
Пример #2
0
 private void AssertReader(IntBlockPool.SliceReader reader, StartEndAndValues values)
 {
     reader.Reset(values.Start, values.End);
     for (int i = 0; i < values.ValueCount; i++)
     {
         Assert.AreEqual(values.ValueOffset + i, reader.ReadInt());
     }
     Assert.IsTrue(reader.EndOfSlice());
 }
Пример #3
0
        /// <summary>
        /// Returns a String representation of the index data for debugging purposes.
        /// </summary>
        /// <returns> the string representation </returns>
        public override string ToString()
        {
            StringBuilder result = new StringBuilder(256);

            SortFields();
            int      sumPositions = 0;
            int      sumTerms     = 0;
            BytesRef spare        = new BytesRef();

            for (int i = 0; i < sortedFields.Length; i++)
            {
                KeyValuePair <string, Info> entry = sortedFields[i];
                string fieldName = entry.Key;
                Info   info      = entry.Value;
                info.SortTerms();
                result.Append(fieldName + ":\n");
                SliceByteStartArray sliceArray = info.sliceArray;
                int numPositions = 0;
                IntBlockPool.SliceReader postingsReader = new IntBlockPool.SliceReader(intBlockPool);
                for (int j = 0; j < info.terms.Size(); j++)
                {
                    int ord = info.sortedTerms[j];
                    info.terms.Get(ord, spare);
                    int freq = sliceArray.freq[ord];
                    result.Append("\t'" + spare + "':" + freq + ":");
                    postingsReader.Reset(sliceArray.start[ord], sliceArray.end[ord]);
                    result.Append(" [");
                    int iters = storeOffsets ? 3 : 1;
                    while (!postingsReader.EndOfSlice())
                    {
                        result.Append("(");

                        for (int k = 0; k < iters; k++)
                        {
                            result.Append(postingsReader.ReadInt());
                            if (k < iters - 1)
                            {
                                result.Append(", ");
                            }
                        }
                        result.Append(")");
                        if (!postingsReader.EndOfSlice())
                        {
                            result.Append(",");
                        }
                    }
                    result.Append("]");
                    result.Append("\n");
                    numPositions += freq;
                }

                result.Append("\tterms=" + info.terms.Size());
                result.Append(", positions=" + numPositions);
                result.Append(", memory=" + RamUsageEstimator.HumanReadableUnits(RamUsageEstimator.SizeOf(info)));
                result.Append("\n");
                sumPositions += numPositions;
                sumTerms     += info.terms.Size();
            }

            result.Append("\nfields=" + sortedFields.Length);
            result.Append(", terms=" + sumTerms);
            result.Append(", positions=" + sumPositions);
            result.Append(", memory=" + RamUsageEstimator.HumanReadableUnits(MemorySize));
            return(result.ToString());
        }