com.yahoo.sketches.theta.Union类的使用及代码示例

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

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

Union介绍

[英]The API for Union operations
[中]用于联合操作的API

代码示例

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

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

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

@Override
public void reset(ColumnValueSelector selector)
{
 union.reset();
 fold(selector);
}

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

@Test
public void checkHeapifyEstNoOverlapOrderedIn() {
 int lgK = 12; //4096
 int k = 1 << lgK;
 int u = 4*k;
 UpdateSketch usk1 = UpdateSketch.builder().setNominalEntries(k).build();   //2k estimating
 UpdateSketch usk2 = UpdateSketch.builder().setNominalEntries(2 * k).build(); //2k exact for early stop test
 for (int i=0; i<u/2; i++) usk1.update(i); //2k
 for (int i=u/2; i<u; i++) usk2.update(i); //2k no overlap, exact, will force early stop
 CompactSketch cosk2 = usk2.compact(true, null);
 Union union = SetOperation.builder().setNominalEntries(k).buildUnion();
 union.update(usk1);  //update with heap UpdateSketch
 union.update(cosk2); //update with heap Compact, Ordered input, early stop
 UpdateSketch emptySketch = UpdateSketch.builder().setNominalEntries(k).build();
 union.update(emptySketch); //updates with empty
 emptySketch = null;
 union.update(emptySketch); //updates with null
 testAllCompactForms(union, u, 0.05);
 Union union2 = (Union)SetOperation.heapify(Memory.wrap(union.toByteArray()));
 testAllCompactForms(union2, u, 0.05);
 union2.reset();
 assertEquals(union2.getResult(true, null).getEstimate(), 0.0, 0.0);
}

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

public void updateUnion(Union union)
{
 if (obj instanceof Memory) {
  union.update((Memory) obj);
 } else {
  union.update(getSketch());
 }
}

代码示例来源: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 checkUnionEarlyStop() {
 int lgK = 10;
 int k = 1<<lgK;
 int u = 4*k; //4096 + 2048 = 6144
 long v = 0;
 int trials = 10;
 UpdateSketch usk1 = UpdateSketch.builder().setNominalEntries(k).build();
 UpdateSketch usk2 = UpdateSketch.builder().setNominalEntries(k).build();
 Union union = SetOperation.builder().setNominalEntries(2 * k).buildUnion();
 for (int t = 0; t < trials; t++) {
  for (int i=0; i<u; i++) {
   usk1.update(i + v);
   usk2.update(i + v + u/2);
  }
  v += u + u/2;
  CompactSketch csk1 = usk1.compact(true, null);
  CompactSketch csk2 = usk2.compact(true, null);
  Sketch pwSk = PairwiseSetOperations.union(csk1, csk2, 2 * k);
  double pwEst = pwSk.getEstimate();
  union.update(csk1);
  union.update(csk2);
  CompactSketch stdSk = union.getResult(true, null);
  double stdEst = stdSk.getEstimate();
  assertEquals(pwEst, stdEst, 0.0);
  usk1.reset();
  usk2.reset();
  union.reset();
 }
}

代码示例来源: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: DataSketches/sketches-core

@Test
public void checkHeapifyEstNoOverlap() {
 int lgK = 12; //4096
 int k = 1 << lgK;
 int u = 4*k;
 UpdateSketch usk1 = UpdateSketch.builder().setNominalEntries(k).build();   //2k estimating
 UpdateSketch usk2 = UpdateSketch.builder().setNominalEntries(2 * k).build(); //2k exact
 for (int i=0; i<u/2; i++) usk1.update(i); //2k
 for (int i=u/2; i<u; i++) usk2.update(i); //2k no overlap, exact
 Union union = SetOperation.builder().setNominalEntries(k).buildUnion();
 union.update(usk1); //update with heap UpdateSketch
 union.update(usk2); //update with heap UpdateSketch, early stop not possible
 testAllCompactForms(union, u, 0.05);
 Union union2 = (Union)SetOperation.heapify(Memory.wrap(union.toByteArray()));
 testAllCompactForms(union2, u, 0.05);
}

代码示例来源:origin: com.yahoo.bullet/bullet-core

@Override
protected void mergeUnionSketch() {
  result = unionSketch.getResult(false, null);
  unionSketch.reset();
}

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

@Test
public void checkMoveAndResize() {
 int k = 1 << 12;
 int u = 2 * k;
 int bytes = Sketches.getMaxUpdateSketchBytes(k);
 try (WritableDirectHandle wdh = WritableMemory.allocateDirect(bytes/2);
    WritableDirectHandle wdh2 = WritableMemory.allocateDirect(bytes/2) ) {
  WritableMemory wmem = wdh.get();
  UpdateSketch sketch = Sketches.updateSketchBuilder().setNominalEntries(k).build(wmem);
  assertTrue(sketch.isSameResource(wmem));
  WritableMemory wmem2 = wdh2.get();
  Union union = SetOperation.builder().buildUnion(wmem2);
  assertTrue(union.isSameResource(wmem2));
  for (int i = 0; i < u; i++) { union.update(i); }
  assertFalse(union.isSameResource(wmem));
  Union union2 = SetOperation.builder().buildUnion(); //on-heap union
  assertFalse(union2.isSameResource(wmem2));  //obviously not
 }
}

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

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkBadSketchFamily() {
 Union union = setOperationBuilder().buildUnion();
 byte[] byteArr = union.toByteArray();
 Memory srcMem = Memory.wrap(byteArr);
 Sketches.getEstimate(srcMem); //Union is not a Theta Sketch, it is an operation
}

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

@Test
public void checkIsSameResource() {
 int k = 16;
 WritableMemory wmem = WritableMemory.wrap(new byte[(k*16) + 32]);
 Memory roCompactMem = Memory.wrap(new byte[8]);
 Union union = Sketches.setOperationBuilder().setNominalEntries(k).buildUnion(wmem);
 assertTrue(union.isSameResource(wmem));
 assertFalse(union.isSameResource(roCompactMem));
 Intersection inter = Sketches.setOperationBuilder().buildIntersection(wmem);
 assertTrue(inter.isSameResource(wmem));
 assertFalse(inter.isSameResource(roCompactMem));
 AnotB aNotB = Sketches.setOperationBuilder().buildANotB();
 assertFalse(aNotB.isSameResource(roCompactMem));
}

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

@Test
public void checkHeapifyEstNoOverlapOrderedMemIn() {
 int lgK = 12; //4096
 int k = 1 << lgK;
 int u = 4*k;
 UpdateSketch usk1 = UpdateSketch.builder().setNominalEntries(k).build();   //2k estimating
 UpdateSketch usk2 = UpdateSketch.builder().setNominalEntries(2 * k).build(); //2k exact for early stop test
 for (int i=0; i<u/2; i++) usk1.update(i);  //2k estimating
 for (int i=u/2; i<u; i++) usk2.update(i);  //2k no overlap, exact, will force early stop
 WritableMemory cskMem2 = WritableMemory.wrap(new byte[usk2.getCurrentBytes(true)]);
 usk2.compact(true, cskMem2); //ordered, loads the cskMem2 as ordered
 Union union = SetOperation.builder().setNominalEntries(k).buildUnion();
 union.update(usk1);        //updates with heap UpdateSketch
 union.update(cskMem2);     //updates with direct CompactSketch, ordered, use early stop
 UpdateSketch emptySketch = UpdateSketch.builder().setNominalEntries(k).build();
 union.update(emptySketch); //updates with empty sketch
 emptySketch = null;
 union.update(emptySketch); //updates with null sketch
 testAllCompactForms(union, u, 0.05);
 Union union2 = (Union)SetOperation.heapify(Memory.wrap(union.toByteArray()));
 testAllCompactForms(union2, u, 0.05);
 union2.reset();
 assertEquals(union2.getResult(true, null).getEstimate(), 0.0, 0.0);
}

代码示例来源: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: DataSketches/sketches-core

@Test
public void wrapAndTryUpdatingUnion() {
 Union u1 = SetOperation.builder().buildUnion();
 u1.update(1);
 Memory mem = Memory.wrap(ByteBuffer.wrap(u1.toByteArray())
   .asReadOnlyBuffer().order(ByteOrder.nativeOrder()));
 Union u2 = (Union) Sketches.wrapSetOperation(mem);
 Union u3 = Sketches.wrapUnion(mem);
 Assert.assertEquals(u2.getResult().getEstimate(), 1.0);
 Assert.assertEquals(u3.getResult().getEstimate(), 1.0);
 try {
  u2.update(2);
  fail();
 } catch (SketchesReadOnlyException e) {
  //expected
 }
 try {
  u3.update(2);
  fail();
 } catch (SketchesReadOnlyException e) {
  //expected
 }
}

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

union.update(cskA);
union.update(cskB);
cskC = union.getResult();
cskR = PairwiseSetOperations.union(cskA, cskB, k);
assertEquals(cskC.isEmpty(), cskR.isEmpty());
union.reset();
cskA = uskA.compact();
union.update(cskA);
union.update(cskB);
cskC = union.getResult();
cskR = PairwiseSetOperations.union(cskA, cskB, k);
assertEquals(cskC.isEmpty(), cskR.isEmpty());
union.reset();

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

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

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

@Test
public void checkHeapifyExact() {
 int lgK = 9; //512
 int k = 1 << lgK;
 int u = k;
 UpdateSketch usk1 = UpdateSketch.builder().setNominalEntries(k).build();
 UpdateSketch usk2 = UpdateSketch.builder().setNominalEntries(k).build();
 for (int i=0; i<u/2; i++) usk1.update(i); //256
 for (int i=u/2; i<u; i++) usk2.update(i); //256 no overlap
 assertEquals(u, usk1.getEstimate() + usk2.getEstimate(), 0.0); //exact, no overlap
 Union union = SetOperation.builder().setNominalEntries(k).buildUnion();
 union.update(usk1); //update with heap UpdateSketch
 union.update(usk2); //update with heap UpdateSketch
 testAllCompactForms(union, u, 0.0);
 Union union2 = (Union)SetOperation.heapify(Memory.wrap(union.toByteArray()));
 testAllCompactForms(union2, u, 0.0);
}

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

@Test(expectedExceptions = ClassCastException.class)
public void checkFamilyID() {
 int k = 32;
 Union union = SetOperation.builder().setNominalEntries(k).buildUnion();
 byte[] byteArray = union.toByteArray();
 Memory mem = Memory.wrap(byteArray);
 Intersection inter1 = (Intersection) SetOperation.heapify(mem); //bad cast
 println(inter1.toString());
}

代码示例来源:origin: org.apache.druid.extensions/druid-datasketches

@Override
public synchronized boolean isSameResource(Memory mem)
{
 return delegate.isSameResource(mem);
}

相关文章

微信公众号

最新文章

更多