Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ UpdateReturnState hashUpdate(final long hash) {
* @return the hash table threshold
*/
static final int setHashTableThreshold(final int lgNomLongs, final int lgArrLongs) {
//FindBugs may complain if DQS_RESIZE_THRESHOLD == REBUILD_THRESHOLD, but this allows us
// to tune these constants for different sketches.
//FindBugs may complain (DB_DUPLICATE_BRANCHES) if DQS_RESIZE_THRESHOLD == REBUILD_THRESHOLD,
//but this allows us to tune these constants for different sketches.
final double fraction = (lgArrLongs <= lgNomLongs) ? DQS_RESIZE_THRESHOLD : REBUILD_THRESHOLD;
return (int) Math.floor(fraction * (1 << lgArrLongs));
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/apache/datasketches/theta/UnionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ private void processVer3(final Memory skMem) {
// OR the above and the SI bit is set
if (SingleItemSketch.testPre0SeedHash(skMem.getLong(0), seedHash_)) {
final long hash = skMem.getLong(8);
update(hash); //a hash < 1 will be rejected later
//backdoor update, hash function is bypassed. A hash < 1 will be rejected later
gadget_.hashUpdate(hash);
return;
}
return; //empty
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/org/apache/datasketches/tuple/Sketch.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,14 @@ public double getTheta() {
* @return a SketchIterator
*/
public SketchIterator<S> iterator() {
return new SketchIterator<S>(keys_, summaries_);
return new SketchIterator<>(keys_, summaries_);
}

long getThetaLong() {
/**
* Returns Theta as a long
* @return Theta as a long
*/
public long getThetaLong() {
return theta_;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
public interface UpdatableSummary<U> extends Summary {

/**
* This is to provide a method of updating summaries
* This is to provide a method of updating summaries.
* This should not be called by the user.
* @param value update value
*/
public void update(U value);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.datasketches.tuple.adouble;

import org.apache.datasketches.ResizeFactor;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.tuple.UpdatableSketch;

/**
* @author Lee Rhodes
*/
public class DoubleSketch extends UpdatableSketch<Double, DoubleSummary> {

/**
* Constructs this sketch with given <i>lgK</i>.
* @param lgK Log_base2 of <i>Nominal Entries</i>.
* <a href="{@docRoot}/resources/dictionary.html#nomEntries">See Nominal Entries</a>
* @param mode The DoubleSummary mode to be used
*/
public DoubleSketch(final int lgK, final DoubleSummary.Mode mode) {
super(1 << lgK, ResizeFactor.X8.ordinal(), 1.0F, new DoubleSummaryFactory(mode));
}

/**
* Constructs this sketch from a Memory image, which must be from an DoubleSketch, and
* usually with data.
* @param mem the given Memory
* @param mode The DoubleSummary mode to be used
*/
public DoubleSketch(final Memory mem, final DoubleSummary.Mode mode) {
super(mem, new DoubleSummaryDeserializer(), new DoubleSummaryFactory(mode));
}

@Override
public void update(final String key, final Double value) {
super.update(key, value);
}

@Override
public void update(final long key, final Double value) {
super.update(key, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
* Supported modes: Sum, Min, Max, AlwaysOne, Increment. The default mode is Sum.
*/
public final class DoubleSummary implements UpdatableSummary<Double> {
private double value_;
private final Mode mode_;

/**
* The aggregation modes for this Summary
Expand All @@ -48,6 +50,7 @@ public static enum Mode {
* <p>New retained value = min(previous retained value, incoming value)</p>
*/
Min,

/**
* The aggregation mode is the maximum function.
* <p>New retained value = max(previous retained value, incoming value)</p>
Expand All @@ -58,27 +61,21 @@ public static enum Mode {
* The aggregation mode is always one.
* <p>New retained value = 1.0</p>
*/
AlwaysOne,

/**
* The aggregation mode is increment by one.
* <p>New retained value = previous retained value + 1.0</p>
*/
Increment
AlwaysOne
}

private double value_;
private final Mode mode_;

/**
* Creates an instance of DoubleSummary with zero starting value and default mode (Sum)
* Creates an instance of DoubleSummary with a given starting value and mode
* @param value starting value
* @param mode update mode
*/
public DoubleSummary() {
this(0, Mode.Sum);
private DoubleSummary(final double value, final Mode mode) {
value_ = value;
mode_ = mode;
}

/**
* Creates an instance of DoubleSummary with a starting value and a given mode (Sum)
* Creates an instance of DoubleSummary with a given mode.
* @param mode update mode
*/
public DoubleSummary(final Mode mode) {
Expand All @@ -96,21 +93,9 @@ public DoubleSummary(final Mode mode) {
case AlwaysOne:
value_ = 1.0;
break;
case Increment:
value_ = 0;
}
}

/**
* Creates an instance of DoubleSummary with a given starting value and mode
* @param value starting value
* @param mode update mode
*/
public DoubleSummary(final double value, final Mode mode) {
value_ = value;
mode_ = mode;
}

@Override
public void update(final Double value) {
switch (mode_) {
Expand All @@ -126,8 +111,6 @@ public void update(final Double value) {
case AlwaysOne:
value_ = 1.0;
break;
case Increment:
value_++;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public final class DoubleSummaryFactory implements SummaryFactory<DoubleSummary>
/**
* Creates an instance of DoubleSummaryFactory with default mode
*/
@Deprecated
public DoubleSummaryFactory() {
summaryMode_ = DoubleSummary.Mode.Sum;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ public final class DoubleSummarySetOperations implements SummarySetOperations<Do

private final Mode summaryMode_;

//TODO see IntegerSummarySetOperations for better model

/**
* Creates an instance with default mode.
*/
@Deprecated
public DoubleSummarySetOperations() {
summaryMode_ = DoubleSummary.Mode.Sum;
}
Expand All @@ -53,13 +56,14 @@ public DoubleSummary union(final DoubleSummary a, final DoubleSummary b) {
return result;
}

@Override

/**
* Intersection is not well defined or even meaningful between numeric values.
* Nevertheless, this can be defined to be just a different type of aggregation.
* In this case it is defined to be the same as union. It can be overridden to
* be a more meaningful operation.
*/
@Override
public DoubleSummary intersection(final DoubleSummary a, final DoubleSummary b) {
return union(a, b);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.datasketches.tuple.aninteger;

import org.apache.datasketches.ResizeFactor;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.tuple.UpdatableSketch;

/**
* @author Lee Rhodes
*/
public class IntegerSketch extends UpdatableSketch<Integer, IntegerSummary> {

/**
* Constructs this sketch with given <i>lgK</i>.
* @param lgK Log_base2 of <i>Nominal Entries</i>.
* <a href="{@docRoot}/resources/dictionary.html#nomEntries">See Nominal Entries</a>
* @param mode The IntegerSummary mode to be used
*/
public IntegerSketch(final int lgK, final IntegerSummary.Mode mode) {
super(1 << lgK, ResizeFactor.X8.ordinal(), 1.0F, new IntegerSummaryFactory(mode));
}

/**
* Constructs this sketch from a Memory image, which must be from an IntegerSketch, and
* usually with data.
* @param mem the given Memory
* @param mode The IntegerSummary mode to be used
*/
public IntegerSketch(final Memory mem, final IntegerSummary.Mode mode) {
super(mem, new IntegerSummaryDeserializer(), new IntegerSummaryFactory(mode));
}

@Override
public void update(final String key, final Integer value) {
super.update(key, value);
}

@Override
public void update(final long key, final Integer value) {
super.update(key, value);
}

}
Loading