Size() public method

Returns the number of BytesRef values in this BytesRefHash.
public Size ( ) : int
return int
コード例 #1
0
ファイル: TestBytesRefHash.cs プロジェクト: zfxsss/lucenenet
        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);
            }
        }
コード例 #2
0
ファイル: TestBytesRefHash.cs プロジェクト: zfxsss/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.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();
                    }
                }
            }
        }
コード例 #3
0
ファイル: TermsQuery.cs プロジェクト: Cefa68000/lucenenet
 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);
 }
コード例 #4
0
ファイル: TestBytesRefHash.cs プロジェクト: zfxsss/lucenenet
        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();
            }
        }
コード例 #5
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);
     }
 }