/// <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; }
/// <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; }
/// <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); }
/// <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); }
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 } } }
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 } } }
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))); }
public override void SetUp() { base.SetUp(); Pool = NewPool(); Hash = NewHash(Pool); }
public override void SetUp() { base.SetUp(); pool = NewPool(); hash = NewHash(pool); }
/// <summary> /// Creates a new <seealso cref="BytesRefHash"/> /// </summary> public BytesRefHash(ByteBlockPool pool) : this(pool, DEFAULT_CAPACITY, new DirectBytesStartArray(DEFAULT_CAPACITY)) { }
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)); }