Package dovetaildb.bytes

Examples of dovetaildb.bytes.ArrayBytes


  }


  private ArrayBytes bytes(String s) {
    try {
      return new ArrayBytes(s.getBytes("utf-8"));
    } catch (UnsupportedEncodingException e) {
      throw new RuntimeException(e);
    }
  }
View Full Code Here


  }
 
  public void testSpliceSegmentsIntoSegmentPush() {
   
    ArrayList<MemoryPostingNode> nodes = new ArrayList<MemoryPostingNode>();
    MemoryPostingNode node3 = new MemoryPostingNode(3, new ArrayBytes(new byte[]{53}));
    nodes.add(node3);
    ArrayList<MemoryPostingNode> subnodes1 = new ArrayList<MemoryPostingNode>();
    MemoryPostingNode node5 = new MemoryPostingNode(5, new ArrayBytes(new byte[]{53}));
    subnodes1.add(node5);
    MemoryPostingNode node6 = new MemoryPostingNode(6, new ArrayBytes(new byte[]{53}));
    subnodes1.add(node6);
    SegmentPush sub1 = new SegmentPush(subnodes1);
    MemoryPostingNode node7 = new MemoryPostingNode(sub1, 7, new ArrayBytes(new byte[]{57}));
    nodes.add(node7);
    MemoryPostingNode node9 = new MemoryPostingNode(null, 9, new ArrayBytes(new byte[]{59}));
    nodes.add(node9);
    SegmentPush push = new SegmentPush(nodes);

    SegmentPush o;
    List<EditRec> edits = new ArrayList<EditRec>();
   
    edits = new ArrayList<EditRec>();
    edits.add(new EditRec(2, new ArrayBytes(new byte[]{0}), false));
    o = BlueSteelBagIndex.spliceEditsIntoSegmentPush(edits, push);
    compareSegments(o, new long[]{2,3,5,6,7,9});
   
    edits = new ArrayList<EditRec>();
    edits.add(new EditRec(9, new ArrayBytes(new byte[]{127}), false));
    o = BlueSteelBagIndex.spliceEditsIntoSegmentPush(edits, push);
    compareSegments(o, new long[]{3,5,6,7,9,9});

    edits = new ArrayList<EditRec>();
    edits.add(new EditRec(7, new ArrayBytes(new byte[]{0}), false));
    o = BlueSteelBagIndex.spliceEditsIntoSegmentPush(edits, push);
    compareSegments(o, new long[]{3,5,6,7,7,9});

    edits = new ArrayList<EditRec>();
    edits.add(new EditRec(3, new ArrayBytes(new byte[]{127}), false));
    o = BlueSteelBagIndex.spliceEditsIntoSegmentPush(edits, push);
    compareSegments(o, new long[]{3,3,5,6,7,9});

    edits = new ArrayList<EditRec>();
    edits.add(new EditRec(5, new ArrayBytes(new byte[]{127}), false));
    o = BlueSteelBagIndex.spliceEditsIntoSegmentPush(edits, push);
    compareSegments(o, new long[]{3,5,5,6,7,9});

    edits = new ArrayList<EditRec>();
    edits.add(new EditRec(6, new ArrayBytes(new byte[]{127}), false));
    o = BlueSteelBagIndex.spliceEditsIntoSegmentPush(edits, push);
    compareSegments(o, new long[]{3,5,6,6,7,9});

    edits = new ArrayList<EditRec>();
    edits.add(new EditRec(8, new ArrayBytes(new byte[]{127}), false));
    o = BlueSteelBagIndex.spliceEditsIntoSegmentPush(edits, push);
    compareSegments(o, new long[]{3,5,6,7,8,9});

    edits = new ArrayList<EditRec>();
    edits.add(makeEdit(node3, true));
    o = BlueSteelBagIndex.spliceEditsIntoSegmentPush(edits, push);
    compareSegments(o, new long[]{5,6,7,9});

    edits = new ArrayList<EditRec>();
    edits.add(makeEdit(node5, true));
    o = BlueSteelBagIndex.spliceEditsIntoSegmentPush(edits, push);
    compareSegments(o, new long[]{3,6,7,9});

    edits = new ArrayList<EditRec>();
    edits.add(makeEdit(node6, true));
    o = BlueSteelBagIndex.spliceEditsIntoSegmentPush(edits, push);
    compareSegments(o, new long[]{3,5,7,9});

    edits = new ArrayList<EditRec>();
    edits.add(makeEdit(node7, true));
    o = BlueSteelBagIndex.spliceEditsIntoSegmentPush(edits, push);
    compareSegments(o, new long[]{3,5,6,9});
 
    edits = new ArrayList<EditRec>();
    edits.add(makeEdit(node9, true));
    o = BlueSteelBagIndex.spliceEditsIntoSegmentPush(edits, push);
    compareSegments(o, new long[]{3,5,6,7});
   
    edits = new ArrayList<EditRec>();
    edits.add(new EditRec(2, new ArrayBytes(new byte[]{0}), false));
    edits.add(makeEdit(node3, true));
    o = BlueSteelBagIndex.spliceEditsIntoSegmentPush(edits, push);
    compareSegments(o, new long[]{2,5,6,7,9});
   
    edits = new ArrayList<EditRec>();
    edits.add(makeEdit(node3, true));
    edits.add(new EditRec(4, new ArrayBytes(new byte[]{0}), false));
    o = BlueSteelBagIndex.spliceEditsIntoSegmentPush(edits, push);
    compareSegments(o, new long[]{4,5,6,7,9});

    edits = new ArrayList<EditRec>();
    edits.add(new EditRec(7, new ArrayBytes(new byte[]{0}), false));
    edits.add(makeEdit(node7, true));
    o = BlueSteelBagIndex.spliceEditsIntoSegmentPush(edits, push);
    compareSegments(o, new long[]{3,5,6,7,9});

    edits = new ArrayList<EditRec>();
    edits.add(makeEdit(node9, true));
    edits.add(new EditRec(10, new ArrayBytes(new byte[]{0}), false));
    o = BlueSteelBagIndex.spliceEditsIntoSegmentPush(edits, push);
    compareSegments(o, new long[]{3,5,6,7,10});

    edits = new ArrayList<EditRec>();
    edits.add(new EditRec(8, new ArrayBytes(new byte[]{0}), false));
    edits.add(makeEdit(node9, true));
    o = BlueSteelBagIndex.spliceEditsIntoSegmentPush(edits, push);
    compareSegments(o, new long[]{3,5,6,7,8});

    edits = new ArrayList<EditRec>();
View Full Code Here

  }

  public void testBalanceSegmentPush() {
    SegmentPush o;
    ArrayList<MemoryPostingNode> nodes = new ArrayList<MemoryPostingNode>();
    nodes.add(new MemoryPostingNode(1L, new ArrayBytes(new byte[]{11})));
    nodes.add(new MemoryPostingNode(2L, new ArrayBytes(new byte[]{22})));
    nodes.add(new MemoryPostingNode(3L, new ArrayBytes(new byte[]{33})));
    nodes.add(new MemoryPostingNode(4L, new ArrayBytes(new byte[]{44})));
    nodes.add(new MemoryPostingNode(5L, new ArrayBytes(new byte[]{55})));
    nodes.add(new MemoryPostingNode(6L, new ArrayBytes(new byte[]{66})));
    nodes.add(new MemoryPostingNode(7L, new ArrayBytes(new byte[]{77})));
    nodes.add(new MemoryPostingNode(8L, new ArrayBytes(new byte[]{88})));
    nodes.add(new MemoryPostingNode(9L, new ArrayBytes(new byte[]{99})));
    nodes.add(new MemoryPostingNode(10L,new ArrayBytes(new byte[]{00})));
    SegmentPush push = new SegmentPush(nodes);
    o=BlueSteelBagIndex.balanceSegmentPush(push, new ProbabilisticBalancingPolicy(4, 0.5f, 0.0f));
    compareSegments(o, new long[]{1,2,3,4,5,6,7,8,9,10});
    assertEquals(10, o.getCount());
    assertEquals(3, o.getTopLevelCount());
View Full Code Here

    assertEquals(2, o.getTopLevelCount());
  }
 
  public void testOrganicBalancing() {
    ArrayList<MemoryPostingNode> nodes = new ArrayList<MemoryPostingNode>();
    nodes.add(new MemoryPostingNode(3L, new ArrayBytes(new byte[]{33})));
    nodes.add(new MemoryPostingNode(7L, new ArrayBytes(new byte[]{77})));
    SegmentPush push = new SegmentPush(nodes);
    ArrayList<EditRec> edits = new ArrayList<EditRec>();
    edits.add(new EditRec(2L, new ArrayBytes(new byte[]{22})));
    push = BlueSteelBagIndex.spliceEditsIntoSegmentPush(edits, push);
    push.getTextDisplay();
    push = BlueSteelBagIndex.balanceSegmentPush(push, new ProbabilisticBalancingPolicy(5, 0.5f, 0.0f));
    push.getTextDisplay();
    push.getTextDisplay();
View Full Code Here

    checkTwoInserts(twoInsertsRev);
    checkEmpty(initialEmptyRev); // old rev should still appear empty
  }
 
  private ArrayBytes randTerm(Random r) {
    return new ArrayBytes(randTermBytes(r));
  }
View Full Code Here

      long id = r.nextInt(MAX_IDS);
      byte[] field = randTermBytes(r);
      String rep = Util.bytesAsString(field)+" "+id;
      if (!seen.contains(rep)) {
        seen.add(rep);
        edits.add(new EditRec(id, new ArrayBytes(field), false));
      }
    }
    int startDiv = edits.size()/2;
    List<EditRec> removeQueue = new ArrayList<EditRec>(edits.subList(0, startDiv));
    List<EditRec> addQueue    = new ArrayList<EditRec>(edits.subList(startDiv, edits.size()));
View Full Code Here

    value <<= numCenteringBits;
    for(int i = numCompressedBytes-1; i >= 0; i--) {
      compressedPrefix[i] = (byte)(value & 0xFF);
      value >>= 8;
    }
    return new ArrayBytes(compressedPrefix);
  }
View Full Code Here

  @Override
  protected BagIndex createIndex() {
    Bytes[] mapping = new Bytes[] {
       
        new ArrayBytes(new byte[]{}),
        new ArrayBytes(new byte[]{'a','a'}),
        new ArrayBytes(new byte[]{'a','b'}),
        new ArrayBytes(new byte[]{'a','c'}),
       
        new ArrayBytes(new byte[]{'a','d'}),
        new ArrayBytes(new byte[]{'a','e'}),
        new ArrayBytes(new byte[]{'a'}),
        new ArrayBytes(new byte[]{'a','h'}),

        new ArrayBytes(new byte[]{'a'}),
        new ArrayBytes(new byte[]{}),
        new ArrayBytes(new byte[]{'d','a','a'}),
        new ArrayBytes(new byte[]{}),

        new ArrayBytes(new byte[]{'d','b'}),
        new ArrayBytes(new byte[]{'d','c'}),
        new ArrayBytes(new byte[]{'d','d'}),
        new ArrayBytes(new byte[]{}),

    };
    return new PrefixCompressedBagIndex(new TrivialBagIndex(), mapping);
  }
View Full Code Here

  public void testMultiByteCompressionTable() {
    int SIZE = 1024;
    Bytes[] mapping = new Bytes[SIZE];
    for(int i=0; i<SIZE; i++) { // creates a kind of identity compression table
      byte[] arr = new byte[]{(byte)((i&0xff00)>>8), (byte)(i & 0x00ff)};
      mapping[i] = new ArrayBytes(arr);
    }
    PrefixCompressedBagIndex index = new PrefixCompressedBagIndex(new TrivialBagIndex(), mapping);
   
    Bytes compressed, uncompressed;
    SlicedBytes slice;
   
    compressed = index.compress(new ArrayBytes(new byte[]{0, 5, 42}));
    assertEquals(new ArrayBytes(new byte[]{0, 5<<3, 42}), compressed);
   
    compressed = index.compress(new ArrayBytes(new byte[]{0, (byte)250, 42}));
    assertEquals(new ArrayBytes(new byte[]{(byte)((250<<3)/256), (byte)((250<<3)%256), 42}), compressed);
   
    compressed = index.compress(new ArrayBytes(new byte[]{1, 5, 42}));
    assertEquals(new ArrayBytes(new byte[]{1<<3, 5<<3, 42}), compressed);
   
    slice = new SlicedBytes(new ArrayBytes(new byte[]{0, 5<<3, 42}), 0, 3);
    uncompressed = index.decompressPrefix(slice);
    assertEquals(2, slice.getSlicePosition());
    assertEquals(new ArrayBytes(new byte[]{0, 5}), uncompressed);
  }
View Full Code Here

      byte[] bytes = delta.getBytes();
      if (! Util.incrementBinary(bytes)) {
        maxSuffix = null;
        isMaxIncluded = true;
      } else {
        maxSuffix = new ArrayBytes(bytes);
        isMaxIncluded = false;
      }
    } else {
      maxSuffix = CompoundBytes.prependBytes(maxSuffix, delta);
    }
View Full Code Here

TOP

Related Classes of dovetaildb.bytes.ArrayBytes

Copyright © 2018 www.massapicom. 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.