示例#1
0
        public object Clone()
        {
            // LUCENENET: MemberwiseClone() doesn't throw in .NET
            TermBuffer clone = (TermBuffer)base.MemberwiseClone();

            clone.bytes = BytesRef.DeepCopyOf(bytes);
            return(clone);
        }
示例#2
0
        public Term ToTerm()
        {
            if (field == null) // unset
            {
                return(null);
            }

            return(term ?? (term = new Term(field, BytesRef.DeepCopyOf(bytes))));
        }
示例#3
0
        public object Clone()
        {
            TermBuffer clone = null;

            try
            {
                clone = (TermBuffer)base.MemberwiseClone();
            }
#pragma warning disable 168
            catch (InvalidOperationException e)
#pragma warning restore 168
            {
            }
            clone.bytes = BytesRef.DeepCopyOf(bytes);
            return(clone);
        }
示例#4
0
 internal static Term DeepCopyOf(Term other)
 {
     return(new Term(other.Field, BytesRef.DeepCopyOf(other.Bytes)));
 }
示例#5
0
 /// <summary>
 /// Returns the MurmurHash3_x86_32 hash.
 /// Original source/tests at <a href="https://github.com/yonik/java_util/">https://github.com/yonik/java_util/</a>.
 /// </summary>
 public static int Murmurhash3_x86_32(BytesRef bytes, int seed)
 {
     return(Murmurhash3_x86_32(bytes.Bytes, bytes.Offset, bytes.Length, seed));
 }
示例#6
0
 /// <summary>
 /// Returns <c>true</c> if the <paramref name="ref"/> ends with the given <paramref name="suffix"/>. Otherwise
 /// <c>false</c>.
 /// </summary>
 /// <param name="ref">
 ///          The <see cref="BytesRef"/> to test. </param>
 /// <param name="suffix">
 ///          The expected suffix </param>
 /// <returns> Returns <c>true</c> if the <paramref name="ref"/> ends with the given <paramref name="suffix"/>.
 ///         Otherwise <c>false</c>. </returns>
 public static bool EndsWith(BytesRef @ref, BytesRef suffix) // LUCENENET TODO: API - convert to extension method
 {
     return(SliceEquals(@ref, suffix, @ref.Length - suffix.Length));
 }
示例#7
0
 /// <summary>
 /// Returns <c>true</c> if the <paramref name="ref"/> starts with the given <paramref name="prefix"/>.
 /// Otherwise <c>false</c>.
 /// </summary>
 /// <param name="ref">
 ///          The <see cref="BytesRef"/> to test. </param>
 /// <param name="prefix">
 ///          The expected prefix </param>
 /// <returns> Returns <c>true</c> if the <paramref name="ref"/> starts with the given <paramref name="prefix"/>.
 ///         Otherwise <c>false</c>. </returns>
 public static bool StartsWith(BytesRef @ref, BytesRef prefix) // LUCENENET TODO: API - convert to extension method
 {
     return(SliceEquals(@ref, prefix, 0));
 }
示例#8
0
 public static bool EndsWith(this BytesRef @ref, BytesRef suffix) // LUCENENET specific - converted to extension method
 {
     return(SliceEquals(@ref, suffix, @ref.Length - suffix.Length));
 }
示例#9
0
 public static bool StartsWith(this BytesRef @ref, BytesRef prefix) // LUCENENET specific - converted to extension method
 {
     return(SliceEquals(@ref, prefix, 0));
 }
示例#10
0
 /// <summary>
 /// Override this method, if you like to receive the already prefix encoded range bounds.
 /// You can directly build classical range (inclusive) queries from them.
 /// </summary>
 public virtual void AddRange(BytesRef minPrefixCoded, BytesRef maxPrefixCoded)
 {
     throw new NotSupportedException();
 }
示例#11
0
 protected override AcceptStatus Accept(BytesRef term)
 {
     return(NumericUtils.GetPrefixCodedInt32Shift(term) == 0 ? AcceptStatus.YES : AcceptStatus.END);
 }
示例#12
0
 public static void Int32ToPrefixCoded(int val, int shift, BytesRef bytes)
 {
     Int32ToPrefixCodedBytes(val, shift, bytes);
 }
示例#13
0
 public static void Int64ToPrefixCoded(long val, int shift, BytesRef bytes)
 {
     Int64ToPrefixCodedBytes(val, shift, bytes);
 }
示例#14
0
 public int Find(BytesRef bytes)
 {
     return(ids[FindHash(bytes)]);
 }
示例#15
0
        /// <summary>
        /// Adds a new <see cref="BytesRef"/>
        /// </summary>
        /// <param name="bytes">
        ///          The bytes to hash </param>
        /// <returns> The id the given bytes are hashed if there was no mapping for the
        ///         given bytes, otherwise <c>(-(id)-1)</c>. this guarantees
        ///         that the return value will always be &gt;= 0 if the given bytes
        ///         haven't been hashed before.
        /// </returns>
        /// <exception cref="MaxBytesLengthExceededException">
        ///           if the given bytes are > 2 +
        ///           <see cref="ByteBlockPool.BYTE_BLOCK_SIZE"/> </exception>
        public int Add(BytesRef bytes)
        {
            if (Debugging.AssertsEnabled)
            {
                Debugging.Assert(bytesStart != null, "bytesStart is null - not initialized");
            }
            int length = bytes.Length;
            // final position
            int hashPos = FindHash(bytes);
            int e       = ids[hashPos];

            if (e == -1)
            {
                // new entry
                int len2 = 2 + bytes.Length;
                if (len2 + pool.ByteUpto > ByteBlockPool.BYTE_BLOCK_SIZE)
                {
                    if (len2 > ByteBlockPool.BYTE_BLOCK_SIZE)
                    {
                        throw new MaxBytesLengthExceededException("bytes can be at most " + (ByteBlockPool.BYTE_BLOCK_SIZE - 2) + " in length; got " + bytes.Length);
                    }
                    pool.NextBuffer();
                }
                var buffer     = pool.Buffer;
                int bufferUpto = pool.ByteUpto;
                if (count >= bytesStart.Length)
                {
                    bytesStart = bytesStartArray.Grow();
                    if (Debugging.AssertsEnabled)
                    {
                        Debugging.Assert(count < bytesStart.Length + 1, "count: {0} len: {1}", count, bytesStart.Length);
                    }
                }
                e = count++;

                bytesStart[e] = bufferUpto + pool.ByteOffset;

                // We first encode the length, followed by the
                // bytes. Length is encoded as vInt, but will consume
                // 1 or 2 bytes at most (we reject too-long terms,
                // above).
                if (length < 128)
                {
                    // 1 byte to store length
                    buffer[bufferUpto] = (byte)length;
                    pool.ByteUpto     += length + 1;
                    if (Debugging.AssertsEnabled)
                    {
                        Debugging.Assert(length >= 0, "Length must be positive: {0}", length);
                    }
                    System.Buffer.BlockCopy(bytes.Bytes, bytes.Offset, buffer, bufferUpto + 1, length);
                }
                else
                {
                    // 2 byte to store length
                    buffer[bufferUpto]     = (byte)(0x80 | (length & 0x7f));
                    buffer[bufferUpto + 1] = (byte)((length >> 7) & 0xff);
                    pool.ByteUpto         += length + 2;
                    System.Buffer.BlockCopy(bytes.Bytes, bytes.Offset, buffer, bufferUpto + 2, length);
                }
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(ids[hashPos] == -1);
                }
                ids[hashPos] = e;

                if (count == hashHalfSize)
                {
                    Rehash(2 * hashSize, true);
                }
                return(e);
            }
            return(-(e + 1));
        }
示例#16
0
 private bool Equals(int id, BytesRef b)
 {
     pool.SetBytesRef(scratch1, bytesStart[id]);
     return(scratch1.BytesEquals(b));
 }