com.yahoo.sketches.theta.Union.getResult()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(126)

本文整理了Java中com.yahoo.sketches.theta.Union.getResult()方法的一些代码示例,展示了Union.getResult()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Union.getResult()方法的具体详情如下:
包路径:com.yahoo.sketches.theta.Union
类名称:Union
方法名:getResult

Union.getResult介绍

[英]Gets the result of this operation as an ordered CompactSketch on the Java heap. This does not disturb the underlying data structure of the union. Therefore, it is OK to continue updating the union after this operation.
[中]以Java堆上的有序CompactSketch的形式获取此操作的结果。这不会影响联盟的底层数据结构。因此,在此操作之后,可以继续更新union。

代码示例

代码示例来源:origin: apache/incubator-druid

@Override
public Object get()
{
 if (union == null) {
  return SketchHolder.EMPTY;
 }
 //in the code below, I am returning SetOp.getResult(true, null)
 //"true" returns an ordered sketch but slower to compute than unordered sketch.
 //however, advantage of ordered sketch is that they are faster to "union" later
 //given that results from the aggregator will be combined further, it is better
 //to return the ordered sketch here
 synchronized (this) {
  return SketchHolder.of(union.getResult(true, null));
 }
}

代码示例来源:origin: gchq/Gaffer

@Override
  protected Union _apply(final Union a, final Union b) {
    a.update(b.getResult());
    return a;
  }
}

代码示例来源:origin: gchq/Gaffer

@Override
public byte[] serialise(final Union union) throws SerialisationException {
  return union.getResult().toByteArray();
}

代码示例来源:origin: apache/incubator-druid

public Sketch getSketch()
{
 if (cachedSketch != null) {
  return cachedSketch;
 }
 if (obj instanceof Sketch) {
  cachedSketch = (Sketch) obj;
 } else if (obj instanceof Union) {
  cachedSketch = ((Union) obj).getResult();
 } else if (obj instanceof Memory) {
  cachedSketch = deserializeFromMemory((Memory) obj);
 } else {
  throw new ISE("Can't get sketch from object of type [%s]", obj.getClass().getName());
 }
 return cachedSketch;
}

代码示例来源:origin: apache/incubator-druid

@Override
public Object get(ByteBuffer buf, int position)
{
 Int2ObjectMap<Union> unionMap = unions.get(buf);
 Union union = unionMap != null ? unionMap.get(position) : null;
 if (union == null) {
  return SketchHolder.EMPTY;
 }
 //in the code below, I am returning SetOp.getResult(true, null)
 //"true" returns an ordered sketch but slower to compute than unordered sketch.
 //however, advantage of ordered sketch is that they are faster to "union" later
 //given that results from the aggregator will be combined further, it is better
 //to return the ordered sketch here
 return SketchHolder.of(union.getResult(true, null));
}

代码示例来源:origin: gchq/Gaffer

@Override
  protected Double getTestValue(final Union object) {
    return object.getResult().getEstimate();
//        assertEquals(estimate, unionDeserialised.getResult().getEstimate(), DELTA);
  }

代码示例来源: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

@Test
public void testAggregate() {
  final UnionAggregator unionAggregator = new UnionAggregator();
  Union currentState = union1;
  assertEquals(2.0D, currentState.getResult().getEstimate(), DELTA);
  currentState = unionAggregator.apply(currentState, union2);
  assertEquals(4.0D, currentState.getResult().getEstimate(), DELTA);
}

代码示例来源: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

public static void testAllCompactForms(Union union, double expected, double toll) {
 double compEst1, compEst2;
 compEst1 = union.getResult(false, null).getEstimate(); //not ordered, no mem
 assertEquals(compEst1, expected, toll*expected);
 CompactSketch comp2 = union.getResult(true, null); //ordered, no mem
 compEst2 = comp2.getEstimate();
 assertEquals(compEst2, compEst1, 0.0);
 WritableMemory mem = WritableMemory.wrap(new byte[comp2.getCurrentBytes(false)]);
 compEst2 = union.getResult(false, mem).getEstimate(); //not ordered, mem
 assertEquals(compEst2, compEst1, 0.0);
 compEst2 = union.getResult(true, mem).getEstimate(); //ordered, mem
 assertEquals(compEst2, compEst1, 0.0);
}

代码示例来源: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 checkFastWrap() {
 int k = 16;
 long seed = DEFAULT_UPDATE_SEED;
 int unionSize = Sketches.getMaxUnionBytes(k);
 WritableMemory srcMem = WritableMemory.wrap(new byte[unionSize]);
 Union union = Sketches.setOperationBuilder().setNominalEntries(k).buildUnion(srcMem);
 for (int i = 0; i < k; i++) { union.update(i); } //exact
 assertEquals(union.getResult().getEstimate(), k, 0.0);
 Union union2 = UnionImpl.fastWrap(srcMem, seed);
 assertEquals(union2.getResult().getEstimate(), k, 0.0);
 Memory srcMemR = srcMem;
 Union union3 = UnionImpl.fastWrap(srcMemR, seed);
 assertEquals(union3.getResult().getEstimate(), k, 0.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 checkEmptyUnionCompactResult() {
 int k = 64;
 WritableMemory uMem = WritableMemory.wrap(new byte[getMaxUnionBytes(k)]); //union memory
 Union union = SetOperation.builder().setNominalEntries(k).buildUnion(uMem);
 WritableMemory mem = WritableMemory.wrap(new byte[Sketch.getMaxCompactSketchBytes(0)]);
 CompactSketch csk = union.getResult(false, mem); //DirectCompactSketch
 assertTrue(csk.isEmpty());
}

代码示例来源:origin: DataSketches/sketches-core

@Test
public void checkEmptyUnionCompactOrderedResult() {
 int k = 64;
 WritableMemory uMem = WritableMemory.wrap(new byte[getMaxUnionBytes(k)]); //union memory
 Union union = SetOperation.builder().setNominalEntries(k).buildUnion(uMem);
 WritableMemory mem = WritableMemory.wrap(new byte[Sketch.getMaxCompactSketchBytes(0)]);
 CompactSketch csk = union.getResult(true, mem); //DirectCompactSketch
 assertTrue(csk.isEmpty());
}

代码示例来源: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
public void checkSerDe() {
 SingleItemSketch sis = SingleItemSketch.create(1);
 byte[] byteArr = sis.toByteArray();
 Memory mem = Memory.wrap(byteArr);
 SingleItemSketch sis2 = SingleItemSketch.heapify(mem);
 assertEquals(sis2.getEstimate(), 1.0);
 SingleItemSketch sis3 = SingleItemSketch.heapify(mem, DEFAULT_UPDATE_SEED);
 assertEquals(sis2.getEstimate(), 1.0);
 Union union = Sketches.setOperationBuilder().buildUnion();
 union.update(sis);
 union.update(sis2);
 union.update(sis3);
 assertEquals(union.getResult().getEstimate(), 1.0);
}

代码示例来源:origin: DataSketches/sketches-core

@Test
public void checkUnionCompactOrderedSource() {
 int k = 1 << 12;
 UpdateSketch sk = Sketches.updateSketchBuilder().build();
 for (int i = 0; i < k; i++) { sk.update(i); }
 double est1 = sk.getEstimate();
 int bytes = Sketches.getMaxCompactSketchBytes(sk.getRetainedEntries());
 try (WritableDirectHandle h = WritableMemory.allocateDirect(bytes)) {
  WritableMemory wmem = h.get();
  CompactSketch csk = sk.compact(true, wmem); //ordered, direct
  Union union = Sketches.setOperationBuilder().buildUnion();
  union.update(csk);
  double est2 = union.getResult().getEstimate();
  assertEquals(est2, est1);
 }
}

代码示例来源: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());
}

相关文章