Add() public method

Adds a new BytesRef
/// if the given bytes are > 2 + ///
public Add ( BytesRef bytes ) : int
bytes BytesRef /// the bytes to hash
return int
コード例 #1
0
ファイル: TestBytesRefHash.cs プロジェクト: clieben/lucenenet
        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.Count;
                    int key   = Hash.Add(@ref);
                    if (key < 0)
                    {
                        Assert.AreEqual(Hash.Count, count);
                    }
                    else
                    {
                        Assert.AreEqual(Hash.Count, count + 1);
                    }
                    if (i % mod == 0)
                    {
                        Hash.Clear();
                        Assert.AreEqual(0, Hash.Count);
                        Hash.Reinit();
                    }
                }
            }
        }
コード例 #2
0
ファイル: TestBytesRefHash.cs プロジェクト: clieben/lucenenet
        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);
            }
        }
コード例 #3
0
 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);
     }
 }