Lucene.Net  3.0.3
Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
ReciprocalFloatFunction.cs
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 using System;
19 using Lucene.Net.Index;
20 using Lucene.Net.Search.Function;
21 
22 namespace Lucene.Net.Spatial.Util
23 {
25  {
26  protected readonly ValueSource source;
27  protected readonly float m;
28  protected readonly float a;
29  protected readonly float b;
30 
31  /// <summary>
32  /// f(source) = a/(m*float(source)+b)
33  /// </summary>
34  /// <param name="source"></param>
35  /// <param name="m"></param>
36  /// <param name="a"></param>
37  /// <param name="b"></param>
38  public ReciprocalFloatFunction(ValueSource source, float m, float a, float b)
39  {
40  this.source = source;
41  this.m = m;
42  this.a = a;
43  this.b = b;
44  }
45 
46  public class FloatDocValues : DocValues
47  {
48  private readonly ReciprocalFloatFunction _enclosingInstance;
49  private readonly DocValues vals;
50 
51  public FloatDocValues(ReciprocalFloatFunction enclosingInstance, DocValues vals)
52  {
53  _enclosingInstance = enclosingInstance;
54  this.vals = vals;
55  }
56 
57  public override float FloatVal(int doc)
58  {
59  return _enclosingInstance.a / (_enclosingInstance.m * vals.FloatVal(doc) + _enclosingInstance.b);
60  }
61 
62  public override string ToString(int doc)
63  {
64  return _enclosingInstance.a + "/("
65  + _enclosingInstance.m + "*float(" + vals.ToString(doc) + ')'
66  + '+' + _enclosingInstance.b + ')';
67  }
68  }
69 
70  public override DocValues GetValues(IndexReader reader)
71  {
72  var vals = source.GetValues(reader);
73  return new FloatDocValues(this, vals);
74  }
75 
76  public override string Description()
77  {
78  return a + "/("
79  + m + "*float(" + source.Description() + ")"
80  + "+" + b + ')';
81  }
82 
83  public override bool Equals(object o)
84  {
85  if (typeof(ReciprocalFloatFunction) != o.GetType()) return false;
86  var other = (ReciprocalFloatFunction)o;
87  return this.m == other.m
88  && this.a == other.a
89  && this.b == other.b
90  && this.source.Equals(other.source);
91  }
92 
93  public override int GetHashCode()
94  {
95  int h = (int) BitConverter.DoubleToInt64Bits(a) + (int) BitConverter.DoubleToInt64Bits(m);
96  h ^= (h << 13) | (int)((uint)h >> 20);
97  return h + ((int) BitConverter.DoubleToInt64Bits(b)) + source.GetHashCode();
98  }
99  }
100 }