public Get ( int bytesID, BytesRef @ref ) : BytesRef | ||
bytesID | int | /// the id |
@ref | BytesRef | |
return | BytesRef |
private void AssertAllIn(ISet <string> strings, BytesRefHash hash) { BytesRef @ref = new BytesRef(); BytesRef scratch = new BytesRef(); int count = hash.Count; 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.Count); Assert.IsTrue(key < count, "key: " + key + " count: " + count + " string: " + @string); } }
public virtual void TestGet() { BytesRef @ref = new BytesRef(); BytesRef scratch = new BytesRef(); int num = AtLeast(2); for (int j = 0; j < num; j++) { IDictionary <string, int?> strings = new Dictionary <string, int?>(); 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.Count; int key = Hash.Add(@ref); if (key >= 0) { Assert.IsFalse(strings.ContainsKey(str)); strings[str] = Convert.ToInt32(key); Assert.AreEqual(uniqueCount, key); uniqueCount++; Assert.AreEqual(Hash.Count, count + 1); } else { Assert.IsTrue((-key) - 1 < count); Assert.AreEqual(Hash.Count, count); } } foreach (KeyValuePair <string, int?> entry in strings) { @ref.CopyChars(entry.Key); Assert.AreEqual(@ref, Hash.Get((int)entry.Value, scratch)); } Hash.Clear(); Assert.AreEqual(0, Hash.Count); Hash.Reinit(); } }
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++) { ISet <string> strings = new JCG.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.Count; int key = Hash.Add(@ref); if (key >= 0) { Assert.IsTrue(strings.Add(str)); Assert.AreEqual(uniqueCount, key); Assert.AreEqual(Hash.Count, count + 1); int offsetKey = offsetHash.AddByPoolOffset(Hash.ByteStart(key)); Assert.AreEqual(uniqueCount, offsetKey); Assert.AreEqual(offsetHash.Count, 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.Count); 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.Count); } } 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.Count); offsetHash.Clear(); Assert.AreEqual(0, offsetHash.Count); Hash.Reinit(); // init for the next round offsetHash.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); }
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); } }