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

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

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

Union.toByteArray介绍

[英]Returns a byte array image of this Union object
[中]返回此联合对象的字节数组映像

代码示例

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

@Test(expectedExceptions = ClassCastException.class)
public void checkFamilyID() {
 int k = 32;
 Union union;
 union = SetOperation.builder().setNominalEntries(k).buildUnion();
 byte[] byteArray = union.toByteArray();
 WritableMemory mem = WritableMemory.wrap(byteArray);
 Sketches.wrapIntersection(mem);
}

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

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkHeapifyFamilyExcep() {
 int k = 512;
 Union union = SetOperation.builder().setNominalEntries(k).buildUnion();
 byte[] byteArray = union.toByteArray();
 Memory mem = Memory.wrap(byteArray);
 //Improper use
 Sketch.heapify(mem);
}

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

@Test
public void checkSetOpMethods() {
 int k = 1024;
 Memory mem1 = getCompactSketch(k, 0, k);
 Memory mem2 = getCompactSketch(k, k/2, (3*k)/2);
 SetOperationBuilder bldr = setOperationBuilder();
 Union union = bldr.setNominalEntries(2 * k).buildUnion();
 union.update(mem1);
 CompactSketch cSk = union.getResult(true, null);
 assertEquals((int)cSk.getEstimate(), k);
 union.update(mem2);
 cSk = union.getResult(true, null);
 assertEquals((int)cSk.getEstimate(), (3*k)/2);
 byte[] ubytes = union.toByteArray();
 WritableMemory uMem = WritableMemory.wrap(ubytes);
 Union union2 = (Union)heapifySetOperation(uMem);
 cSk = union2.getResult(true, null);
 assertEquals((int)cSk.getEstimate(), (3*k)/2);
 union2 = (Union)heapifySetOperation(uMem, Util.DEFAULT_UPDATE_SEED);
 cSk = union2.getResult(true, null);
 assertEquals((int)cSk.getEstimate(), (3*k)/2);
 union2 = (Union)wrapSetOperation(uMem);
 cSk = union2.getResult(true, null);
 assertEquals((int)cSk.getEstimate(), (3*k)/2);
 union2 = (Union)wrapSetOperation(uMem, Util.DEFAULT_UPDATE_SEED);
 cSk = union2.getResult(true, null);
 assertEquals((int)cSk.getEstimate(), (3*k)/2);
 int serVer = getSerializationVersion(uMem);
 assertEquals(serVer, 3);
}

代码示例来源: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
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: 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
 WritableMemory uMem = WritableMemory.wrap(new byte[getMaxUnionBytes(k)]);
 Union union = SetOperation.builder().setNominalEntries(k).buildUnion(uMem);
 union.update(usk1); //update with heap UpdateSketch
 union.update(usk2); //update with heap UpdateSketch
 testAllCompactForms(union, u, 0.0);
 Union union2 = (Union)SetOperation.heapify(WritableMemory.wrap(union.toByteArray()));
 testAllCompactForms(union2, u, 0.0);
}

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

@Test
public void checkWrapExact() {
 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
 WritableMemory uMem = WritableMemory.wrap(new byte[getMaxUnionBytes(k)]);
 Union union = SetOperation.builder().setNominalEntries(k).buildUnion(uMem);
 union.update(usk1); //update with heap UpdateSketch
 union.update(usk2); //update with heap UpdateSketch
 testAllCompactForms(union, u, 0.0);
 Union union2 = Sketches.wrapUnion(WritableMemory.wrap(union.toByteArray()));
 testAllCompactForms(union2, u, 0.0);
}

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

@Test
public void checkWrapEstNoOverlap() {
 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
 }
 WritableMemory uMem = WritableMemory.wrap(new byte[getMaxUnionBytes(k)]);
 Union union = SetOperation.builder().setNominalEntries(k).buildUnion(uMem);
 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 = Sketches.wrapUnion(WritableMemory.wrap(union.toByteArray()));
 testAllCompactForms(union2, u, 0.05);
}

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

@Test
public void checkWrapEstNoOverlapOrderedDirectIn() {
 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)]);
 CompactSketch cosk2 = 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(cosk2);       //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: 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: DataSketches/sketches-core

@Test
public void checkHeapifyEstNoOverlapUnorderedMemIn() {
 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(false, cskMem2); //unordered, loads the cskMem2 as unordered
 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: DataSketches/sketches-core

@Test
public void checkWrapEstNoOverlapOrderedIn() {
 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
 }
 CompactSketch cosk2 = usk2.compact(true, null);
 WritableMemory uMem = WritableMemory.wrap(new byte[getMaxUnionBytes(k)]);
 Union union = SetOperation.builder().setNominalEntries(k).buildUnion(uMem);
 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 = Sketches.wrapUnion(WritableMemory.wrap(union.toByteArray()));
 testAllCompactForms(union2, u, 0.05);
 union2.reset();
 assertEquals(union2.getResult(true, null).getEstimate(), 0.0, 0.0);
}

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

Union union2 = Sketches.wrapUnion(WritableMemory.wrap(union.toByteArray()));

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

Union union2 = Sketches.wrapUnion(WritableMemory.wrap(union.toByteArray()));

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

Union union2 = Sketches.wrapUnion(WritableMemory.wrap(union.toByteArray()));

相关文章

微信公众号

最新文章

更多