本文整理了Java中com.yahoo.sketches.theta.Union.update()
方法的一些代码示例,展示了Union.update()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Union.update()
方法的具体详情如下:
包路径:com.yahoo.sketches.theta.Union
类名称:Union
方法名:update
[英]Present this union with the given double (or float) datum. The double will be converted to a long using Double.doubleToLongBits(datum), which normalizes all NaN values to a single NaN representation. Plus and minus zero will be normalized to plus zero. The special floating-point values NaN and +/- Infinity are treated as distinct.
[中]用给定的双(或浮动)基准表示此接头。双精度将转换为长使用双精度。doubleToLongBits(数据),将所有NaN值标准化为单个NaN表示。正负零将被标准化为正负零。特殊的浮点值NaN和+/-无穷大被视为不同的。
代码示例来源:origin: apache/incubator-druid
public void updateUnion(Union union)
{
if (obj instanceof Memory) {
union.update((Memory) obj);
} else {
union.update(getSketch());
}
}
代码示例来源:origin: apache/incubator-druid
static void updateUnion(Union union, Object update)
{
if (update instanceof SketchHolder) {
((SketchHolder) update).updateUnion(union);
} else if (update instanceof String) {
union.update((String) update);
} else if (update instanceof byte[]) {
union.update((byte[]) update);
} else if (update instanceof Double) {
union.update(((Double) update));
} else if (update instanceof Integer || update instanceof Long) {
union.update(((Number) update).longValue());
} else if (update instanceof int[]) {
union.update((int[]) update);
} else if (update instanceof long[]) {
union.update((long[]) update);
} else if (update instanceof List) {
for (Object entry : (List) update) {
union.update(entry.toString());
}
} else {
throw new ISE("Illegal type received while theta sketch merging [%s]", update.getClass());
}
}
}
代码示例来源:origin: gchq/Gaffer
@Override
protected Union _apply(final Union a, final Union b) {
a.update(b.getResult());
return a;
}
}
代码示例来源:origin: gchq/Gaffer
@Override
protected Sketch _apply(final Sketch a, final Sketch b) {
final Union union = Sketches.setOperationBuilder().buildUnion();
union.update(a);
union.update(b);
return union.getResult();
}
}
代码示例来源:origin: gchq/Gaffer
@Override
protected Union getExampleOutput() {
final Union union = SetOperation.builder().buildUnion();
union.update(1.0D);
union.update(2.0D);
union.update(3.0D);
return union;
}
代码示例来源:origin: gchq/Gaffer
@Override
public Union deserialise(final byte[] bytes) throws SerialisationException {
final Union union = Sketches.setOperationBuilder().buildUnion();
union.update(WritableMemory.wrap(bytes));
return union;
}
代码示例来源:origin: gchq/Gaffer
@Before
public void setup() {
union1 = Sketches.setOperationBuilder().buildUnion();
union1.update("A");
union1.update("B");
union2 = Sketches.setOperationBuilder().buildUnion();
union2.update("C");
union2.update("D");
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testSketchAggregatorFactoryComparator()
{
Comparator<Object> comparator = SketchHolder.COMPARATOR;
Assert.assertEquals(0, comparator.compare(null, null));
Union union1 = (Union) SetOperation.builder().setNominalEntries(1 << 4).build(Family.UNION);
union1.update("a");
union1.update("b");
Sketch sketch1 = union1.getResult();
Assert.assertEquals(-1, comparator.compare(null, SketchHolder.of(sketch1)));
Assert.assertEquals(1, comparator.compare(SketchHolder.of(sketch1), null));
Union union2 = (Union) SetOperation.builder().setNominalEntries(1 << 4).build(Family.UNION);
union2.update("a");
union2.update("b");
union2.update("c");
Sketch sketch2 = union2.getResult();
Assert.assertEquals(-1, comparator.compare(SketchHolder.of(sketch1), SketchHolder.of(sketch2)));
Assert.assertEquals(-1, comparator.compare(SketchHolder.of(sketch1), SketchHolder.of(union2)));
Assert.assertEquals(1, comparator.compare(SketchHolder.of(sketch2), SketchHolder.of(sketch1)));
Assert.assertEquals(1, comparator.compare(SketchHolder.of(sketch2), SketchHolder.of(union1)));
Assert.assertEquals(1, comparator.compare(SketchHolder.of(union2), SketchHolder.of(union1)));
Assert.assertEquals(1, comparator.compare(SketchHolder.of(union2), SketchHolder.of(sketch1)));
}
代码示例来源:origin: DataSketches/sketches-core
@Test
public void heapifyUnion() {
Union u1 = SetOperation.builder().buildUnion();
u1.update(1);
Memory mem = Memory.wrap(ByteBuffer.wrap(u1.toByteArray())
.asReadOnlyBuffer().order(ByteOrder.nativeOrder()));
Union u2 = (Union) SetOperation.heapify(mem);
u2.update(2);
Assert.assertEquals(u2.getResult().getEstimate(), 2.0);
}
代码示例来源:origin: DataSketches/sketches-core
@Test
public void checkGetResult() {
int k = 1024;
UpdateSketch sk = Sketches.updateSketchBuilder().build();
Union union = Sketches.setOperationBuilder().setNominalEntries(k).buildUnion();
union.update(sk);
CompactSketch csk = union.getResult();
assertEquals(csk.getCurrentBytes(true), 8);
}
代码示例来源:origin: DataSketches/sketches-core
@Test
public void unionWrapped() {
Sketch sketch = SingleItemSketch.create(1);
Union union = Sketches.setOperationBuilder().buildUnion();
union.update(Memory.wrap(sketch.toByteArray()));
assertEquals(union.getResult().getEstimate(), 1, 0);
}
代码示例来源:origin: DataSketches/sketches-core
@Test
public void checkGetResult() {
int k = 1024;
UpdateSketch sk = Sketches.updateSketchBuilder().build();
int memBytes = getMaxUnionBytes(k);
byte[] memArr = new byte[memBytes];
WritableMemory iMem = WritableMemory.wrap(memArr);
Union union = Sketches.setOperationBuilder().setNominalEntries(k).buildUnion(iMem);
union.update(sk);
CompactSketch csk = union.getResult();
assertEquals(csk.getCurrentBytes(true), 8);
}
代码示例来源:origin: DataSketches/sketches-core
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkMemBadSerVer() {
int lgK = 12; //4096
int k = 1 << lgK;
UpdateSketch usk1 = UpdateSketch.builder().setNominalEntries(k).build();
CompactSketch usk1c = usk1.compact(true, null);
WritableMemory v3mem1 = WritableMemory.wrap(usk1c.toByteArray());
//corrupt SerVer
v3mem1.putByte(SER_VER_BYTE, (byte)0);
Union union = SetOperation.builder().setNominalEntries(k).buildUnion();
union.update(v3mem1);
}
代码示例来源:origin: DataSketches/sketches-core
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkCorruptedCompactFlag() {
int k = 16;
WritableMemory mem = WritableMemory.wrap(new byte[(k*8) + 24]);
UpdateSketch sketch = Sketches.updateSketchBuilder().setNominalEntries(k).build();
for (int i=0; i<k; i++) { sketch.update(i); }
CompactSketch sketchInDirectOrd = sketch.compact(true, mem);
sketch.compact(false, mem); //corrupt memory
Union union = Sketches.setOperationBuilder().setNominalEntries(k).buildUnion();
union.update(sketchInDirectOrd);
}
代码示例来源:origin: DataSketches/sketches-core
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkCorruptFamilyException() {
int k = 16;
WritableMemory mem = WritableMemory.wrap(new byte[(k*8) + 24]);
UpdateSketch sketch = Sketches.updateSketchBuilder().setNominalEntries(k).build();
for (int i=0; i<k; i++) {
sketch.update(i);
}
sketch.compact(true, mem);
mem.putByte(PreambleUtil.FAMILY_BYTE, (byte)0); //corrupt family
Union union = Sketches.setOperationBuilder().setNominalEntries(k).buildUnion();
union.update(mem);
}
代码示例来源:origin: DataSketches/sketches-core
@Test
public void checkUpdateMemorySpecialCases2() {
int lgK = 12; //4096
int k = 1 << lgK;
int u = 2*k;
UpdateSketch usk1 = UpdateSketch.builder().setNominalEntries(k).build();
for (int i=0; i<u; i++) usk1.update(i); //force prelongs to 3
CompactSketch usk1c = usk1.compact(true, null);
WritableMemory v3mem1 = WritableMemory.wrap(usk1c.toByteArray());
//println(PreambleUtil.toString(v3mem1));
Union union = SetOperation.builder().setNominalEntries(k).buildUnion();
union.update(v3mem1);
}
代码示例来源:origin: DataSketches/sketches-core
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkVer1FamilyException() {
int k = 16;
WritableMemory v3mem = WritableMemory.wrap(new byte[(k*8) + 24]);
UpdateSketch sketch = Sketches.updateSketchBuilder().setNominalEntries(k).build();
for (int i=0; i<k; i++) {
sketch.update(i);
}
sketch.compact(true, v3mem);
WritableMemory v1mem = ForwardCompatibilityTest.convertSerV3toSerV1(v3mem);
v1mem.putByte(PreambleUtil.FAMILY_BYTE, (byte)2); //corrupt family
Union union = Sketches.setOperationBuilder().setNominalEntries(k).buildUnion();
union.update(v1mem);
}
代码示例来源:origin: DataSketches/sketches-core
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkVer2FamilyException() {
int k = 16;
WritableMemory v3mem = WritableMemory.wrap(new byte[(k*8) + 24]);
UpdateSketch sketch = Sketches.updateSketchBuilder().setNominalEntries(k).build();
for (int i=0; i<k; i++) {
sketch.update(i);
}
sketch.compact(true, v3mem);
WritableMemory v2mem = ForwardCompatibilityTest.convertSerV3toSerV2(v3mem);
v2mem.putByte(PreambleUtil.FAMILY_BYTE, (byte)2); //corrupt family
Union union = Sketches.setOperationBuilder().setNominalEntries(k).buildUnion();
union.update(v2mem);
}
代码示例来源:origin: DataSketches/sketches-core
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkMemBadSerVer() {
int lgK = 12; //4096
int k = 1 << lgK;
UpdateSketch usk1 = UpdateSketch.builder().setNominalEntries(k).build();
CompactSketch usk1c = usk1.compact(true, null);
WritableMemory v3mem1 = WritableMemory.wrap(usk1c.toByteArray());
//corrupt SerVer
v3mem1.putByte(SER_VER_BYTE, (byte)0);
WritableMemory uMem = WritableMemory.wrap(new byte[getMaxUnionBytes(k)]); //union memory
Union union = SetOperation.builder().setNominalEntries(k).buildUnion(uMem);
union.update(v3mem1);
}
代码示例来源:origin: DataSketches/sketches-core
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkCompactFlagCorruption() {
int k = 1 << 12;
int bytes = Sketch.getMaxUpdateSketchBytes(k);
WritableMemory wmem1 = WritableMemory.allocate(bytes);
UpdateSketch sk = Sketches.updateSketchBuilder().setNominalEntries(k).build(wmem1);
for (int i = 0; i < k; i++) { sk.update(i); }
sk.compact(true, wmem1); //corrupt the wmem1 to be a compact sketch
Union union = SetOperation.builder().buildUnion();
union.update(sk); //update the union with the UpdateSketch object
CompactSketch csk1 = union.getResult();
println(""+csk1.getEstimate());
}
内容来源于网络,如有侵权,请联系作者删除!