blob: a4191a78abd48b8d7b8eb68a35e5d0dd4cacf28b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchlib.expression;
import com.yahoo.vespa.objects.Deserializer;
import com.yahoo.vespa.objects.ObjectVisitor;
import com.yahoo.vespa.objects.Serializer;
/**
* This result holds a float value.
*
* @author <a href="mailto:havardpe@yahoo-inc.com">Haavard Pettersen</a>
* @author Simon Thoresen Hult
*/
public class FloatBucketResultNode extends BucketResultNode {
// The global class identifier shared with C++.
public static final int classId = registerClass(0x4000 + 102, FloatBucketResultNode.class, FloatBucketResultNode::new);
// bucket start, inclusive
private double from = 0;
// bucket end, exclusive
private double to = 0;
@Override
public boolean empty() {
return to == from;
}
/**
* Constructs an empty result node.
*/
public FloatBucketResultNode() {
// empty
}
/**
* Create a bucket with the given limits
*
* @param from bucket start
* @param to bucket end
*/
public FloatBucketResultNode(double from, double to) {
this.from = from;
this.to = to;
}
/**
* Obtain the bucket start
*
* @return bucket start
*/
public double getFrom() {
return from;
}
/**
* Obtain the bucket end
*
* @return bucket end
*/
public double getTo() {
return to;
}
@Override
protected int onGetClassId() {
return classId;
}
@Override
protected void onSerialize(Serializer buf) {
buf.putDouble(null, from);
buf.putDouble(null, to);
}
@Override
protected void onDeserialize(Deserializer buf) {
from = buf.getDouble(null);
to = buf.getDouble(null);
}
@Override
protected int onCmp(ResultNode rhs) {
if (classId != rhs.getClassId()) {
return (classId - rhs.getClassId());
}
FloatBucketResultNode b = (FloatBucketResultNode)rhs;
double f1 = from;
double f2 = b.from;
if (f1 < f2) {
return -1;
} else if (f1 > f2) {
return 1;
} else {
double t1 = to;
double t2 = b.to;
if (t1 < t2) {
return -1;
} else if (t1 > t2) {
return 1;
}
}
return 0;
}
@Override
public int hashCode() {
return super.hashCode() + (int)from + (int)to;
}
@Override
public void visitMembers(ObjectVisitor visitor) {
super.visitMembers(visitor);
visitor.visit("from", from);
visitor.visit("to", to);
}
}
|