Example #1
0
        /// <summary>
        /// Calculates this buffer's hash code from the remaining chars. The
        /// position, limit, capacity and mark don't affect the hash code.
        /// </summary>
        /// <returns>The hash code calculated from the remaining <see cref="float"/>s.</returns>
        public override int GetHashCode()
        {
            int myPosition = position;
            int hash       = 0;

            while (myPosition < limit)
            {
                hash += BitConversion.SingleToInt32Bits(Get(myPosition++));
            }
            return(hash);
        }
Example #2
0
            public override int GetHashCode(float obj)
            {
                if (obj != 0 && !float.IsNaN(obj))
                {
                    return(obj.GetHashCode());
                }

                // Make positive zero and negative zero have differnt hash codes,
                // and NaN always have the same hash code
                return(BitConversion.SingleToInt32Bits(obj).GetHashCode());
            }
Example #3
0
            private int CompareZero(float x, float y)
            {
                int a = BitConversion.SingleToInt32Bits(x);
                int b = BitConversion.SingleToInt32Bits(y);

                if (a > b)
                {
                    return(1);
                }
                else if (a < b)
                {
                    return(-1);
                }

                return(0);
            }
Example #4
0
        public override void WriteField(FieldInfo info, IIndexableField field)
        {
            fieldsStream.WriteVInt32(info.Number);
            int      bits = 0;
            BytesRef bytes;
            string   @string;

            // TODO: maybe a field should serialize itself?
            // this way we don't bake into indexer all these
            // specific encodings for different fields?  and apps
            // can customize...

            // LUCENENET specific - To avoid boxing/unboxing, we don't
            // call GetNumericValue(). Instead, we check the field.NumericType and then
            // call the appropriate conversion method.
            if (field.NumericType != NumericFieldType.NONE)
            {
                switch (field.NumericType)
                {
                case NumericFieldType.BYTE:
                case NumericFieldType.INT16:
                case NumericFieldType.INT32:
                    bits |= FIELD_IS_NUMERIC_INT;
                    break;

                case NumericFieldType.INT64:
                    bits |= FIELD_IS_NUMERIC_LONG;
                    break;

                case NumericFieldType.SINGLE:
                    bits |= FIELD_IS_NUMERIC_FLOAT;
                    break;

                case NumericFieldType.DOUBLE:
                    bits |= FIELD_IS_NUMERIC_DOUBLE;
                    break;

                default:
                    throw new ArgumentException("cannot store numeric type " + field.NumericType);
                }

                @string = null;
                bytes   = null;
            }
            else
            {
                bytes = field.GetBinaryValue();
                if (bytes != null)
                {
                    bits   |= FIELD_IS_BINARY;
                    @string = null;
                }
                else
                {
                    @string = field.GetStringValue();
                    if (@string == null)
                    {
                        throw new ArgumentException("field " + field.Name + " is stored but does not have binaryValue, stringValue nor numericValue");
                    }
                }
            }

            fieldsStream.WriteByte((byte)(sbyte)bits);

            if (bytes != null)
            {
                fieldsStream.WriteVInt32(bytes.Length);
                fieldsStream.WriteBytes(bytes.Bytes, bytes.Offset, bytes.Length);
            }
            else if (@string != null)
            {
                fieldsStream.WriteString(field.GetStringValue());
            }
            else
            {
                switch (field.NumericType)
                {
                case NumericFieldType.BYTE:
                case NumericFieldType.INT16:
                case NumericFieldType.INT32:
                    fieldsStream.WriteInt32(field.GetInt32Value().Value);
                    break;

                case NumericFieldType.INT64:
                    fieldsStream.WriteInt64(field.GetInt64Value().Value);
                    break;

                case NumericFieldType.SINGLE:
                    fieldsStream.WriteInt32(BitConversion.SingleToInt32Bits(field.GetSingleValue().Value));
                    break;

                case NumericFieldType.DOUBLE:
                    fieldsStream.WriteInt64(BitConversion.DoubleToInt64Bits(field.GetDoubleValue().Value));
                    break;

                default:
                    throw new InvalidOperationException("Cannot get here");
                }
            }
        }
Example #5
0
        public override void WriteField(FieldInfo info, IIndexableField field)
        {
            int      bits /* = 0*/; // LUCENENET: IDE0059: Remove unnecessary value assignment
            BytesRef bytes;
            string   @string;

            // LUCENENET specific - To avoid boxing/unboxing, we don't
            // call GetNumericValue(). Instead, we check the field.NumericType and then
            // call the appropriate conversion method.
            if (field.NumericType != NumericFieldType.NONE)
            {
                switch (field.NumericType)
                {
                case NumericFieldType.BYTE:
                case NumericFieldType.INT16:
                case NumericFieldType.INT32:
                    bits = NUMERIC_INT32;
                    break;

                case NumericFieldType.INT64:
                    bits = NUMERIC_INT64;
                    break;

                case NumericFieldType.SINGLE:
                    bits = NUMERIC_SINGLE;
                    break;

                case NumericFieldType.DOUBLE:
                    bits = NUMERIC_DOUBLE;
                    break;

                default:
                    throw new ArgumentException("cannot store numeric type " + field.NumericType);
                }

                @string = null;
                bytes   = null;
            }
            else
            {
                bytes = field.GetBinaryValue();
                if (bytes != null)
                {
                    bits    = BYTE_ARR;
                    @string = null;
                }
                else
                {
                    bits    = STRING;
                    @string = field.GetStringValue();
                    if (@string == null)
                    {
                        throw new ArgumentException("field " + field.Name + " is stored but does not have BinaryValue, StringValue nor NumericValue");
                    }
                }
            }

            long infoAndBits = (((long)info.Number) << TYPE_BITS) | (uint)bits;

            bufferedDocs.WriteVInt64(infoAndBits);

            if (bytes != null)
            {
                bufferedDocs.WriteVInt32(bytes.Length);
                bufferedDocs.WriteBytes(bytes.Bytes, bytes.Offset, bytes.Length);
            }
            else if (@string != null)
            {
                bufferedDocs.WriteString(field.GetStringValue());
            }
            else
            {
                switch (field.NumericType)
                {
                case NumericFieldType.BYTE:
                case NumericFieldType.INT16:
                case NumericFieldType.INT32:
                    bufferedDocs.WriteInt32(field.GetInt32Value().Value);
                    break;

                case NumericFieldType.INT64:
                    bufferedDocs.WriteInt64(field.GetInt64Value().Value);
                    break;

                case NumericFieldType.SINGLE:
                    bufferedDocs.WriteInt32(BitConversion.SingleToInt32Bits(field.GetSingleValue().Value));
                    break;

                case NumericFieldType.DOUBLE:
                    bufferedDocs.WriteInt64(BitConversion.DoubleToInt64Bits(field.GetDoubleValue().Value));
                    break;

                default:
                    throw AssertionError.Create("Cannot get here");
                }
            }
        }
 public override ByteBuffer PutSingle(int index, float value)
 {
     return(PutInt32(index, BitConversion.SingleToInt32Bits(value)));
 }
Example #7
0
 /// <summary>
 /// Returns a hash code value for this object. </summary>
 public override int GetHashCode()
 {
     return(BitConversion.SingleToInt32Bits(Boost) ^ clauses.GetHashCode()
            + MinimumNumberShouldMatch + (disableCoord ? 17 : 0));
 }
Example #8
0
 /// <summary>
 /// Writes a 32-bit <see cref="float"/> to the target stream. The resulting output is the
 /// four bytes resulting from calling <see cref="BitConversion.SingleToInt32Bits(float)"/>.
 /// <para/>
 /// NOTE: This was writeFloat() in Java
 /// </summary>
 /// <param name="value">The <see cref="float"/> to write to the target stream.</param>
 /// <exception cref="IOException">If an error occurs while writing to the target stream.</exception>
 /// <seealso cref="DataInputStream.ReadSingle()"/>
 public void WriteSingle(float value)
 {
     WriteInt32(BitConversion.SingleToInt32Bits(value));
 }
 private static int ToSortable(float value)
 {
     return(Flip(BitConversion.SingleToInt32Bits(value)));
 }
Example #10
0
 public override void SetSingleValue(float value)
 {
     base.SetInt64Value(BitConversion.SingleToInt32Bits(value));
 }
Example #11
0
 /// <summary>
 /// Creates a new DocValues field with the specified 32-bit <see cref="float"/> value </summary>
 /// <param name="name"> field name </param>
 /// <param name="value"> 32-bit <see cref="float"/> value </param>
 /// <exception cref="ArgumentNullException"> if the field name is <c>null</c> </exception>
 public SingleDocValuesField(string name, float value)
     : base(name, BitConversion.SingleToInt32Bits(value))
 {
 }