private void AssertAllIn(ISet <string> strings, BytesRefHash hash) { BytesRef @ref = new BytesRef(); BytesRef scratch = new BytesRef(); int count = hash.Size(); foreach (string @string in strings) { @ref.CopyChars(@string); int key = hash.Add(@ref); // add again to check duplicates Assert.AreEqual(@string, hash.Get((-key) - 1, scratch).Utf8ToString()); Assert.AreEqual(count, hash.Size()); Assert.IsTrue(key < count, "key: " + key + " count: " + count + " string: " + @string); } }
public virtual void TestSize() { BytesRef @ref = new BytesRef(); int num = AtLeast(2); for (int j = 0; j < num; j++) { int mod = 1 + Random().Next(39); for (int i = 0; i < 797; i++) { string str; do { str = TestUtil.RandomRealisticUnicodeString(Random(), 1000); } while (str.Length == 0); @ref.CopyChars(str); int count = Hash.Size(); int key = Hash.Add(@ref); if (key < 0) { Assert.AreEqual(Hash.Size(), count); } else { Assert.AreEqual(Hash.Size(), count + 1); } if (i % mod == 0) { Hash.Clear(); Assert.AreEqual(0, Hash.Size()); Hash.Reinit(); } } } }
internal SeekingTermSetTermsEnum(TermsEnum tenum, BytesRefHash terms, int[] ords) : base(tenum) { Terms = terms; Ords = ords; _comparator = BytesRef.UTF8SortedAsUnicodeComparer; _lastElement = terms.Size() - 1; _lastTerm = terms.Get(ords[_lastElement], new BytesRef()); _seekTerm = terms.Get(ords[_upto], _spare); }
public virtual void TestAddByPoolOffset() { BytesRef @ref = new BytesRef(); BytesRef scratch = new BytesRef(); BytesRefHash offsetHash = NewHash(Pool); int num = AtLeast(2); for (int j = 0; j < num; j++) { HashSet <string> strings = new HashSet <string>(); int uniqueCount = 0; for (int i = 0; i < 797; i++) { string str; do { str = TestUtil.RandomRealisticUnicodeString(Random(), 1000); } while (str.Length == 0); @ref.CopyChars(str); int count = Hash.Size(); int key = Hash.Add(@ref); if (key >= 0) { Assert.IsTrue(strings.Add(str)); Assert.AreEqual(uniqueCount, key); Assert.AreEqual(Hash.Size(), count + 1); int offsetKey = offsetHash.AddByPoolOffset(Hash.ByteStart(key)); Assert.AreEqual(uniqueCount, offsetKey); Assert.AreEqual(offsetHash.Size(), count + 1); uniqueCount++; } else { Assert.IsFalse(strings.Add(str)); Assert.IsTrue((-key) - 1 < count); Assert.AreEqual(str, Hash.Get((-key) - 1, scratch).Utf8ToString()); Assert.AreEqual(count, Hash.Size()); int offsetKey = offsetHash.AddByPoolOffset(Hash.ByteStart((-key) - 1)); Assert.IsTrue((-offsetKey) - 1 < count); Assert.AreEqual(str, Hash.Get((-offsetKey) - 1, scratch).Utf8ToString()); Assert.AreEqual(count, Hash.Size()); } } AssertAllIn(strings, Hash); foreach (string @string in strings) { @ref.CopyChars(@string); int key = Hash.Add(@ref); BytesRef bytesRef = offsetHash.Get((-key) - 1, scratch); Assert.AreEqual(@ref, bytesRef); } Hash.Clear(); Assert.AreEqual(0, Hash.Size()); offsetHash.Clear(); Assert.AreEqual(0, offsetHash.Size()); Hash.Reinit(); // init for the next round offsetHash.Reinit(); } }
private void AssertAllIn(ISet<string> strings, BytesRefHash hash) { BytesRef @ref = new BytesRef(); BytesRef scratch = new BytesRef(); int count = hash.Size(); foreach (string @string in strings) { @ref.CopyChars(@string); int key = hash.Add(@ref); // add again to check duplicates Assert.AreEqual(@string, hash.Get((-key) - 1, scratch).Utf8ToString()); Assert.AreEqual(count, hash.Size()); Assert.IsTrue(key < count, "key: " + key + " count: " + count + " string: " + @string); } }