示例#1
0
 /// <summary>
 /// Creates a new <see cref="BytesRefArray"/> with a counter to track allocated bytes
 /// </summary>
 public BytesRefArray(Counter bytesUsed)
 {
     this.pool = new ByteBlockPool(new ByteBlockPool.DirectTrackingAllocator(bytesUsed));
     pool.NextBuffer();
     bytesUsed.AddAndGet(RamUsageEstimator.NUM_BYTES_ARRAY_HEADER + RamUsageEstimator.NUM_BYTES_INT32);
     this.bytesUsed = bytesUsed;
 }
示例#2
0
 /// <summary>
 /// Creates a new <seealso cref="BytesRefArray"/> with a counter to track allocated bytes
 /// </summary>
 public BytesRefArray(Counter bytesUsed)
 {
     this.Pool = new ByteBlockPool(new ByteBlockPool.DirectTrackingAllocator(bytesUsed));
     Pool.NextBuffer();
     bytesUsed.AddAndGet(RamUsageEstimator.NUM_BYTES_ARRAY_HEADER + RamUsageEstimator.NUM_BYTES_INT);
     this.BytesUsed = bytesUsed;
 }
示例#3
0
 /// <summary>
 /// Creates a new <seealso cref="BytesRefHash"/>
 /// </summary>
 public BytesRefHash(ByteBlockPool pool, int capacity, BytesStartArray bytesStartArray)
 {
     HashSize = capacity;
     HashHalfSize = HashSize >> 1;
     HashMask = HashSize - 1;
     this.Pool = pool;
     Ids = new int[HashSize];
     Arrays.Fill(Ids, -1);
     this.bytesStartArray = bytesStartArray;
     BytesStart = bytesStartArray.Init();
     BytesUsed = bytesStartArray.BytesUsed() == null ? Counter.NewCounter() : bytesStartArray.BytesUsed();
     BytesUsed.AddAndGet(HashSize * RamUsageEstimator.NUM_BYTES_INT);
 }
示例#4
0
 /// <summary>
 /// Creates a new <see cref="BytesRefHash"/>
 /// </summary>
 public BytesRefHash(ByteBlockPool pool, int capacity, BytesStartArray bytesStartArray)
 {
     hashSize     = capacity;
     hashHalfSize = hashSize >> 1;
     hashMask     = hashSize - 1;
     this.pool    = pool;
     ids          = new int[hashSize];
     Arrays.Fill(ids, -1);
     this.bytesStartArray = bytesStartArray;
     bytesStart           = bytesStartArray.Init();
     bytesUsed            = bytesStartArray.BytesUsed() ?? Counter.NewCounter();
     bytesUsed.AddAndGet(hashSize * RamUsageEstimator.NUM_BYTES_INT32);
 }
示例#5
0
        public virtual void TestReadAndWrite()
        {
            Counter       bytesUsed = Util.Counter.NewCounter();
            ByteBlockPool pool      = new ByteBlockPool(new ByteBlockPool.DirectTrackingAllocator(bytesUsed));

            pool.NextBuffer();
            bool reuseFirst = Random.NextBoolean();

            for (int j = 0; j < 2; j++)
            {
                IList <BytesRef> list = new List <BytesRef>();
                int      maxLength    = AtLeast(500);
                int      numValues    = AtLeast(100);
                BytesRef @ref         = new BytesRef();
                for (int i = 0; i < numValues; i++)
                {
                    string value = TestUtil.RandomRealisticUnicodeString(Random, maxLength);
                    list.Add(new BytesRef(value));
                    @ref.CopyChars(value);
                    pool.Append(@ref);
                }
                // verify
                long position = 0;
                foreach (BytesRef expected in list)
                {
                    @ref.Grow(expected.Length);
                    @ref.Length = expected.Length;
                    pool.ReadBytes(position, @ref.Bytes, @ref.Offset, @ref.Length);
                    Assert.AreEqual(expected, @ref);
                    position += @ref.Length;
                }
                pool.Reset(Random.NextBoolean(), reuseFirst);
                if (reuseFirst)
                {
                    Assert.AreEqual(ByteBlockPool.BYTE_BLOCK_SIZE, bytesUsed.Get());
                }
                else
                {
                    Assert.AreEqual(0, bytesUsed.Get());
                    pool.NextBuffer(); // prepare for next iter
                }
            }
        }
示例#6
0
 public virtual void TestReadAndWrite()
 {
     Counter bytesUsed = Util.Counter.NewCounter();
     ByteBlockPool pool = new ByteBlockPool(new ByteBlockPool.DirectTrackingAllocator(bytesUsed));
     pool.NextBuffer();
     bool reuseFirst = Random().NextBoolean();
     for (int j = 0; j < 2; j++)
     {
         IList<BytesRef> list = new List<BytesRef>();
         int maxLength = AtLeast(500);
         int numValues = AtLeast(100);
         BytesRef @ref = new BytesRef();
         for (int i = 0; i < numValues; i++)
         {
             string value = TestUtil.RandomRealisticUnicodeString(Random(), maxLength);
             list.Add(new BytesRef(value));
             @ref.CopyChars(value);
             pool.Append(@ref);
         }
         // verify
         long position = 0;
         foreach (BytesRef expected in list)
         {
             @ref.Grow(expected.Length);
             @ref.Length = expected.Length;
             pool.ReadBytes(position, @ref.Bytes, @ref.Offset, @ref.Length);
             Assert.AreEqual(expected, @ref);
             position += @ref.Length;
         }
         pool.Reset(Random().NextBoolean(), reuseFirst);
         if (reuseFirst)
         {
             Assert.AreEqual(ByteBlockPool.BYTE_BLOCK_SIZE, bytesUsed.Get());
         }
         else
         {
             Assert.AreEqual(0, bytesUsed.Get());
             pool.NextBuffer(); // prepare for next iter
         }
     }
 }
示例#7
0
        private BytesRefHash NewHash(ByteBlockPool blockPool)
        {
            int initSize = 2 << 1 + Random.Next(5);

            return(Random.NextBoolean() ? new BytesRefHash(blockPool) : new BytesRefHash(blockPool, initSize, new BytesRefHash.DirectBytesStartArray(initSize)));
        }
示例#8
0
 public override void SetUp()
 {
     base.SetUp();
     Pool = NewPool();
     Hash = NewHash(Pool);
 }
示例#9
0
 public override void SetUp()
 {
     base.SetUp();
     pool = NewPool();
     hash = NewHash(pool);
 }
示例#10
0
 /// <summary>
 /// Creates a new <seealso cref="BytesRefHash"/>
 /// </summary>
 public BytesRefHash(ByteBlockPool pool)
     : this(pool, DEFAULT_CAPACITY, new DirectBytesStartArray(DEFAULT_CAPACITY))
 {
 }
示例#11
0
 private BytesRefHash NewHash(ByteBlockPool blockPool)
 {
     int initSize = 2 << 1 + Random().Next(5);
     return Random().NextBoolean() ? new BytesRefHash(blockPool) : new BytesRefHash(blockPool, initSize, new BytesRefHash.DirectBytesStartArray(initSize));
 }
示例#12
0
 public override void SetUp()
 {
     base.SetUp();
     Pool = NewPool();
     Hash = NewHash(Pool);
 }