public virtual void TestAppend() { Random random = Random(); BytesRefArray list = new BytesRefArray(Util.Counter.NewCounter()); IList <string> stringList = new List <string>(); for (int j = 0; j < 2; j++) { if (j > 0 && random.NextBoolean()) { list.Clear(); stringList.Clear(); } int entries = AtLeast(500); BytesRef spare = new BytesRef(); int initSize = list.Size(); for (int i = 0; i < entries; i++) { string randomRealisticUnicodeString = TestUtil.RandomRealisticUnicodeString(random); spare.CopyChars(randomRealisticUnicodeString); Assert.AreEqual(i + initSize, list.Append(spare)); stringList.Add(randomRealisticUnicodeString); } for (int i = 0; i < entries; i++) { Assert.IsNotNull(list.Get(spare, i)); Assert.AreEqual(stringList[i], spare.Utf8ToString(), "entry " + i + " doesn't match"); } // check random for (int i = 0; i < entries; i++) { int e = random.Next(entries); Assert.IsNotNull(list.Get(spare, e)); Assert.AreEqual(stringList[e], spare.Utf8ToString(), "entry " + i + " doesn't match"); } for (int i = 0; i < 2; i++) { BytesRefIterator iterator = list.Iterator(); foreach (string @string in stringList) { Assert.AreEqual(@string, iterator.Next().Utf8ToString()); } } } }
public virtual void TestAppend() { Random random = Random(); BytesRefArray list = new BytesRefArray(Util.Counter.NewCounter()); IList<string> stringList = new List<string>(); for (int j = 0; j < 2; j++) { if (j > 0 && random.NextBoolean()) { list.Clear(); stringList.Clear(); } int entries = AtLeast(500); BytesRef spare = new BytesRef(); int initSize = list.Size(); for (int i = 0; i < entries; i++) { string randomRealisticUnicodeString = TestUtil.RandomRealisticUnicodeString(random); spare.CopyChars(randomRealisticUnicodeString); Assert.AreEqual(i + initSize, list.Append(spare)); stringList.Add(randomRealisticUnicodeString); } for (int i = 0; i < entries; i++) { Assert.IsNotNull(list.Get(spare, i)); Assert.AreEqual(stringList[i], spare.Utf8ToString(), "entry " + i + " doesn't match"); } // check random for (int i = 0; i < entries; i++) { int e = random.Next(entries); Assert.IsNotNull(list.Get(spare, e)); Assert.AreEqual(stringList[e], spare.Utf8ToString(), "entry " + i + " doesn't match"); } for (int i = 0; i < 2; i++) { BytesRefIterator iterator = list.Iterator(); foreach (string @string in stringList) { Assert.AreEqual(@string, iterator.Next().Utf8ToString()); } } } }
/// <summary> /// Read in a single partition of data </summary> internal int ReadPartition(ByteSequencesReader reader) { long start = Environment.TickCount; var scratch = new BytesRef(); while ((scratch.Bytes = reader.Read()) != null) { scratch.Length = scratch.Bytes.Length; Buffer.Append(scratch); // Account for the created objects. // (buffer slots do not account to buffer size.) if (RamBufferSize.Bytes < BufferBytesUsed.Get()) { break; } } sortInfo.ReadTime += (Environment.TickCount - start); return(Buffer.Size()); }
public virtual void TestSort() { Random random = Random(); BytesRefArray list = new BytesRefArray(Util.Counter.NewCounter()); List <string> stringList = new List <string>(); for (int j = 0; j < 2; j++) { if (j > 0 && random.NextBoolean()) { list.Clear(); stringList.Clear(); } int entries = AtLeast(500); BytesRef spare = new BytesRef(); int initSize = list.Size(); for (int i = 0; i < entries; i++) { string randomRealisticUnicodeString = TestUtil.RandomRealisticUnicodeString(random); spare.CopyChars(randomRealisticUnicodeString); Assert.AreEqual(initSize + i, list.Append(spare)); stringList.Add(randomRealisticUnicodeString); } stringList.Sort(); BytesRefIterator iter = list.Iterator(BytesRef.UTF8SortedAsUTF16Comparer); int a = 0; while ((spare = iter.Next()) != null) { Assert.AreEqual(stringList[a], spare.Utf8ToString(), "entry " + a + " doesn't match"); a++; } Assert.IsNull(iter.Next()); Assert.AreEqual(a, stringList.Count); } }
public virtual void TestSort() { Random random = Random(); BytesRefArray list = new BytesRefArray(Util.Counter.NewCounter()); List<string> stringList = new List<string>(); for (int j = 0; j < 2; j++) { if (j > 0 && random.NextBoolean()) { list.Clear(); stringList.Clear(); } int entries = AtLeast(500); BytesRef spare = new BytesRef(); int initSize = list.Size(); for (int i = 0; i < entries; i++) { string randomRealisticUnicodeString = TestUtil.RandomRealisticUnicodeString(random); spare.CopyChars(randomRealisticUnicodeString); Assert.AreEqual(initSize + i, list.Append(spare)); stringList.Add(randomRealisticUnicodeString); } stringList.Sort(); BytesRefIterator iter = list.Iterator(BytesRef.UTF8SortedAsUTF16Comparer); int a = 0; while ((spare = iter.Next()) != null) { Assert.AreEqual(stringList[a], spare.Utf8ToString(), "entry " + a + " doesn't match"); a++; } Assert.IsNull(iter.Next()); Assert.AreEqual(a, stringList.Count); } }