Examples of VIntWritable


Examples of org.apache.hadoop.io.VIntWritable

            byte[] buffer = new byte[in.readInt()];
            in.readFully(buffer);
            return new String(buffer, UTF8);

        case DataType.INTEGER:
            VIntWritable vint = new VIntWritable();
            vint.readFields(in);
            return vint.get();

        case DataType.LONG:
            VLongWritable vlong = new VLongWritable();
            vlong.readFields(in);
            return vlong.get();
View Full Code Here

Examples of org.apache.hadoop.io.VIntWritable

            }
            return;

        case DataType.INTEGER:
            out.writeByte(DataType.INTEGER);
            new VIntWritable((Integer) val).write(out);
            return;

        case DataType.LONG:
            out.writeByte(DataType.LONG);
            new VLongWritable((Long) val).write(out);
View Full Code Here

Examples of org.apache.hadoop.io.VIntWritable

public class VIntWritableTest extends WritableTestBase {
 
  @Test
  public void test() throws IOException {
    // vv VIntWritableTest
    byte[] data = serialize(new VIntWritable(163));
    assertThat(StringUtils.byteToHexString(data), is("8fa3"));
    // ^^ VIntWritableTest
  }
View Full Code Here

Examples of org.apache.hadoop.io.VIntWritable

    // ^^ VIntWritableTest
  }
 
  @Test
  public void testSizes() throws IOException {
    assertThat(serializeToString(new VIntWritable(1)), is("01")); // 1 byte
    assertThat(serializeToString(new VIntWritable(-112)), is("90")); // 1 byte
    assertThat(serializeToString(new VIntWritable(127)), is("7f")); // 1 byte
    assertThat(serializeToString(new VIntWritable(128)), is("8f80")); // 2 byte
    assertThat(serializeToString(new VIntWritable(163)), is("8fa3")); // 2 byte
    assertThat(serializeToString(new VIntWritable(Integer.MAX_VALUE)),
        is("8c7fffffff")); // 5 byte
    assertThat(serializeToString(new VIntWritable(Integer.MIN_VALUE)),
        is("847fffffff")); // 5 byte
  }
View Full Code Here

Examples of org.apache.hadoop.io.VIntWritable

    Writable[] vectorValues = new Writable[] {
      new Text("test1"), new Text("test2"), new Text("test3")
    };
    ArrayWritable vector = new ArrayWritable(Text.class, vectorValues);
    MapWritable map = new MapWritable();
    map.put(new Text("one"), new VIntWritable(1));
    map.put(new Text("two"), new VLongWritable(2));
    Writable[] writables = new Writable[] {
      new BytesWritable(new byte[] { 1, 2, 3, 4 }),
      new ByteWritable((byte) 123), new BooleanWritable(true),
      new VIntWritable(12345), new VLongWritable(123456789L),
      new FloatWritable((float) 1.2), new DoubleWritable(1.234),
      new Text("random string")
    };
    TypedBytesWritable tbw = new TypedBytesWritable();
    tbw.setValue("typed bytes text");
View Full Code Here

Examples of org.apache.hadoop.io.VIntWritable

 
  @Override
  public void readFields(DataInput in) throws IOException {
    representedAsList = in.readBoolean();
   
    VIntWritable vInt = new VIntWritable();
    VLongWritable vLong = new VLongWritable();
   
    if (representedAsList) {
      transactionSet = Lists.newArrayList();
      vInt.readFields(in);
      int numTransactions = vInt.get();
      for (int i = 0; i < numTransactions; i++) {
        vLong.readFields(in);
        Long support = vLong.get();
       
        vInt.readFields(in);
        int length = vInt.get();
       
        int[] items = new int[length];
        for (int j = 0; j < length; j++) {
          vInt.readFields(in);
          items[j] = vInt.get();
        }
        Pair<IntArrayList,Long> transaction = new Pair<IntArrayList,Long>(new IntArrayList(items), support);
        transactionSet.add(transaction);
      }
    } else {
      vInt.readFields(in);
      nodes = vInt.get();
      attribute = new int[nodes];
      nodeCount = new long[nodes];
      childCount = new int[nodes];
      nodeChildren = new int[nodes][];
      for (int i = 0; i < nodes; i++) {
        vInt.readFields(in);
        attribute[i] = vInt.get();
        vLong.readFields(in);
        nodeCount[i] = vLong.get();
        vInt.readFields(in);
        int childCountI = vInt.get();
        childCount[i] = childCountI;
        nodeChildren[i] = new int[childCountI];
        for (int j = 0; j < childCountI; j++) {
          vInt.readFields(in);
          nodeChildren[i][j] = vInt.get();
        }
      }
    }
  }
View Full Code Here

Examples of org.apache.hadoop.io.VIntWritable

  }
 
  @Override
  public void write(DataOutput out) throws IOException {
    out.writeBoolean(representedAsList);
    VIntWritable vInt = new VIntWritable();
    VLongWritable vLong = new VLongWritable();
    if (representedAsList) {
      int transactionSetSize = transactionSet.size();
      vInt.set(transactionSetSize);
      vInt.write(out);
      for (Pair<IntArrayList, Long> transaction : transactionSet) {
        vLong.set(transaction.getSecond());
        vLong.write(out);

        vInt.set(transaction.getFirst().size());
        vInt.write(out);

        IntArrayList items = transaction.getFirst();
        for (int idx = 0; idx < items.size(); idx++) {
          int item = items.get(idx);
          vInt.set(item);
          vInt.write(out);
        }
      }
    } else {
      vInt.set(nodes);
      vInt.write(out);
      for (int i = 0; i < nodes; i++) {
        vInt.set(attribute[i]);
        vInt.write(out);
        vLong.set(nodeCount[i]);
        vLong.write(out);
        vInt.set(childCount[i]);
        vInt.write(out);
        int max = childCount[i];
        for (int j = 0; j < max; j++) {
          vInt.set(nodeChildren[i][j]);
          vInt.write(out);
        }
      }
    }
  }
View Full Code Here

Examples of org.apache.hadoop.io.VIntWritable

  public void setup() throws Exception
  {
    bm = new ByteBasedSortedMap(WritableComparator.get(Text.class));
    cls = sd.getSerializedClass();
    wObj = cls.newInstance();
    value = new VIntWritable();
    wEntry = new ByteBasedSortedMap.WritableEntry(wObj, value);
    bldr = new StringBuilder();
  }
View Full Code Here

Examples of org.apache.hadoop.io.VIntWritable

  public void testGeti() throws Exception
  {
    int i = 0;
    for(i = table.length - 1; i >= 0; i--
    {
      bm.put(new Text(table[i]), new VIntWritable(i));
    }
    Assert.assertEquals(table.length, bm.size());
//    bldr.setLength(0);
//    bm.dump(bldr, wEntry);
//    System.out.println(bldr);
View Full Code Here

Examples of org.apache.hadoop.io.VIntWritable

  public void testKeyItr() throws Exception
  {
    int i = 0;
    for(i = table.length - 1; i >= 0; i--
    {
      bm.put(new Text(table[i]), new VIntWritable(i));
    }
    Assert.assertEquals(table.length, bm.size());
   
    Iterator<Writable> it = bm.keyIterator(wObj);
    i=0;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.