• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

apache / datasketches-java / #306

30 Apr 2024 10:01PM UTC coverage: 97.645% (-0.5%) from 98.139%
#306

push

web-flow
Merge pull request #555 from apache/fix_pom_xml_header

Fix pom xml header

26865 of 27513 relevant lines covered (97.64%)

0.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.08
/src/main/java/org/apache/datasketches/thetacommon/SetOperationCornerCases.java
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements.  See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership.  The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied.  See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19

20
package org.apache.datasketches.thetacommon;
21

22
import java.util.HashMap;
23
import java.util.Map;
24

25
import org.apache.datasketches.common.SketchesArgumentException;
26

27
/**
28
 * Simplifies and speeds up set operations by resolving specific corner cases.
29
 * @author Lee Rhodes
30
 */
31
@SuppressWarnings("javadoc")
32
public class SetOperationCornerCases {
×
33
  private static final long MAX = Long.MAX_VALUE;
34

35
  /** Intersection actions */
36
  public enum IntersectAction {
1✔
37
    DEGEN_MIN_0_F("D", "Degenerate{MinTheta, 0, F}"),
1✔
38
    EMPTY_1_0_T("E", "Empty{1.0, 0, T}"),
1✔
39
    FULL_INTERSECT("I", "Full Intersect");
1✔
40

41
    private String actionId;
42
    private String actionDescription;
43

44
    private IntersectAction(final String actionId, final String actionDescription) {
1✔
45
      this.actionId = actionId;
1✔
46
      this.actionDescription = actionDescription;
1✔
47
    }
1✔
48

49
    public String getActionId() {
50
      return actionId;
×
51
    }
52

53
    public String getActionDescription() {
54
      return actionDescription;
×
55
    }
56
  }
57

58
  /** A not B actions */
59
  public enum AnotbAction {
1✔
60
    SKETCH_A("A", "Sketch A Exactly"),
1✔
61
    TRIM_A("TA", "Trim Sketch A by MinTheta"),
1✔
62
    DEGEN_MIN_0_F("D", "Degenerate{MinTheta, 0, F}"),
1✔
63
    DEGEN_THA_0_F("DA", "Degenerate{ThetaA, 0, F}"),
1✔
64
    EMPTY_1_0_T("E", "Empty{1.0, 0, T}"),
1✔
65
    FULL_ANOTB("N", "Full AnotB");
1✔
66

67
    private String actionId;
68
    private String actionDescription;
69

70
    private AnotbAction(final String actionId, final String actionDescription) {
1✔
71
      this.actionId = actionId;
1✔
72
      this.actionDescription = actionDescription;
1✔
73
    }
1✔
74

75
    public String getActionId() {
76
      return actionId;
×
77
    }
78

79
    public String getActionDescription() {
80
      return actionDescription;
×
81
    }
82
  }
83

84
  public enum UnionAction {
1✔
85
    SKETCH_A("A", "Sketch A Exactly"),
1✔
86
    TRIM_A("TA", "Trim Sketch A by MinTheta"),
1✔
87
    SKETCH_B("B", "Sketch B Exactly"),
1✔
88
    TRIM_B("TB", "Trim Sketch B by MinTheta"),
1✔
89
    DEGEN_MIN_0_F("D", "Degenerate{MinTheta, 0, F}"),
1✔
90
    DEGEN_THA_0_F("DA", "Degenerate{ThetaA, 0, F}"),
1✔
91
    DEGEN_THB_0_F("DB", "Degenerate{ThetaB, 0, F}"),
1✔
92
    EMPTY_1_0_T("E", "Empty{1.0, 0, T}"),
1✔
93
    FULL_UNION("N", "Full Union");
1✔
94

95
    private String actionId;
96
    private String actionDescription;
97

98
    private UnionAction(final String actionId, final String actionDescription) {
1✔
99
      this.actionId = actionId;
1✔
100
      this.actionDescription = actionDescription;
1✔
101
    }
1✔
102

103
    public String getActionId() {
104
      return actionId;
×
105
    }
106

107
    public String getActionDescription() {
108
      return actionDescription;
×
109
    }
110
  }
111

112
  public enum CornerCase {
1✔
113
    Empty_Empty(055, "A{ 1.0, 0, T} ; B{ 1.0, 0, T}",
1✔
114
        IntersectAction.EMPTY_1_0_T, AnotbAction.EMPTY_1_0_T, UnionAction.EMPTY_1_0_T),
115
    Empty_Exact(056, "A{ 1.0, 0, T} ; B{ 1.0,>0, F}",
1✔
116
        IntersectAction.EMPTY_1_0_T, AnotbAction.EMPTY_1_0_T, UnionAction.SKETCH_B),
117
    Empty_Estimation(052, "A{ 1.0, 0, T} ; B{<1.0,>0, F",
1✔
118
        IntersectAction.EMPTY_1_0_T, AnotbAction.EMPTY_1_0_T, UnionAction.SKETCH_B),
119
    Empty_Degen(050, "A{ 1.0, 0, T} ; B{<1.0, 0, F}",
1✔
120
        IntersectAction.EMPTY_1_0_T, AnotbAction.EMPTY_1_0_T, UnionAction.DEGEN_THB_0_F),
121

122
    Exact_Empty(065, "A{ 1.0,>0, F} ; B{ 1.0, 0, T}",
1✔
123
        IntersectAction.EMPTY_1_0_T, AnotbAction.SKETCH_A, UnionAction.SKETCH_A),
124
    Exact_Exact(066, "A{ 1.0,>0, F} ; B{ 1.0,>0, F}",
1✔
125
        IntersectAction.FULL_INTERSECT, AnotbAction.FULL_ANOTB, UnionAction.FULL_UNION),
126
    Exact_Estimation(062, "A{ 1.0,>0, F} ; B{<1.0,>0, F}",
1✔
127
        IntersectAction.FULL_INTERSECT, AnotbAction.FULL_ANOTB, UnionAction.FULL_UNION),
128
    Exact_Degen(060, "A{ 1.0,>0, F} ; B{<1.0, 0, F}",
1✔
129
        IntersectAction.DEGEN_MIN_0_F, AnotbAction.TRIM_A, UnionAction.TRIM_A),
130

131
    Estimation_Empty(025, "A{<1.0,>0, F} ; B{ 1.0, 0, T}",
1✔
132
        IntersectAction.EMPTY_1_0_T, AnotbAction.SKETCH_A, UnionAction.SKETCH_A),
133
    Estimation_Exact(026, "A{<1.0,>0, F} ; B{ 1.0,>0, F}",
1✔
134
        IntersectAction.FULL_INTERSECT, AnotbAction.FULL_ANOTB, UnionAction.FULL_UNION),
135
    Estimation_Estimation(022, "A{<1.0,>0, F} ; B{<1.0,>0, F}",
1✔
136
        IntersectAction.FULL_INTERSECT, AnotbAction.FULL_ANOTB, UnionAction.FULL_UNION),
137
    Estimation_Degen(020, "A{<1.0,>0, F} ; B{<1.0, 0, F}",
1✔
138
        IntersectAction.DEGEN_MIN_0_F, AnotbAction.TRIM_A, UnionAction.TRIM_A),
139

140
    Degen_Empty(005, "A{<1.0, 0, F} ; B{ 1.0, 0, T}",
1✔
141
        IntersectAction.EMPTY_1_0_T, AnotbAction.DEGEN_THA_0_F, UnionAction.DEGEN_THA_0_F),
142
    Degen_Exact(006, "A{<1.0, 0, F} ; B{ 1.0,>0, F}",
1✔
143
        IntersectAction.DEGEN_MIN_0_F, AnotbAction.DEGEN_THA_0_F, UnionAction.TRIM_B),
144
    Degen_Estimation(002, "A{<1.0, 0, F} ; B{<1.0,>0, F}",
1✔
145
        IntersectAction.DEGEN_MIN_0_F, AnotbAction.DEGEN_MIN_0_F, UnionAction.TRIM_B),
146
    Degen_Degen(000, "A{<1.0, 0, F} ; B{<1.0, 0, F}",
1✔
147
        IntersectAction.DEGEN_MIN_0_F, AnotbAction.DEGEN_MIN_0_F, UnionAction.DEGEN_MIN_0_F);
148

149
    private static final Map<Integer, CornerCase> caseIdToCornerCaseMap = new HashMap<>();
1✔
150
    private int caseId;
151
    private String caseDescription;
152
    private IntersectAction intersectAction;
153
    private AnotbAction anotbAction;
154
    private UnionAction unionAction;
155

156
    static {
157
      for (final CornerCase cc : values()) {
1✔
158
        caseIdToCornerCaseMap.put(cc.getId(), cc);
1✔
159
      }
160
    }
1✔
161

162
    private CornerCase(final int caseId, final String caseDescription,
163
        final IntersectAction intersectAction, final AnotbAction anotbAction, final UnionAction unionAction) {
1✔
164
      this.caseId = caseId;
1✔
165
      this.caseDescription = caseDescription;
1✔
166
      this.intersectAction = intersectAction;
1✔
167
      this.anotbAction = anotbAction;
1✔
168
      this.unionAction = unionAction;
1✔
169
    }
1✔
170

171
    public int getId() {
172
      return caseId;
1✔
173
    }
174

175
    public String getCaseDescription() {
176
      return caseDescription;
×
177
    }
178

179
    public IntersectAction getIntersectAction() {
180
      return intersectAction;
×
181
    }
182

183
    public AnotbAction getAnotbAction() {
184
      return anotbAction;
1✔
185
    }
186

187
    public UnionAction getUnionAction() {
188
      return unionAction;
×
189
    }
190

191
    //See checkById test in /tuple/MiscTest.
192
    public static CornerCase caseIdToCornerCase(final int id) {
193
      final CornerCase cc = caseIdToCornerCaseMap.get(id);
1✔
194
      if (cc == null) {
1✔
195
        throw new SketchesArgumentException("Possible Corruption: Illegal CornerCase ID: " + Integer.toOctalString(id));
×
196
      }
197
      return cc;
1✔
198
    }
199
  } //end of enum CornerCase
200

201
  public static int createCornerCaseId(
202
      final long thetaLongA, final int countA, final boolean emptyA,
203
      final long thetaLongB, final int countB, final boolean emptyB) {
204
    return (sketchStateId(emptyA, countA, thetaLongA) << 3) | sketchStateId(emptyB, countB, thetaLongB);
1✔
205
  }
206

207
  public static int sketchStateId(final boolean isEmpty, final int numRetained, final long thetaLong) {
208
    // assume thetaLong = MAX if empty
209
    return (((thetaLong == MAX) || isEmpty) ? 4 : 0) | ((numRetained > 0) ? 2 : 0) | (isEmpty ? 1 : 0);
1✔
210
  }
211
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc