Package dovetaildb.bytes

Examples of dovetaildb.bytes.ArrayBytes


public class BlueSteelBagIndexTest extends BagIndexTest {

  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<PostingNode> nodes = new ArrayList<PostingNode>();
    PostingNode node3 = new PostingNode(3, new ArrayBytes(new byte[]{53}));
    nodes.add(node3);
    node3.setIdxPos(333);
    ArrayList<PostingNode> subnodes1 = new ArrayList<PostingNode>();
    PostingNode node5 = new PostingNode(5, new ArrayBytes(new byte[]{53}));
    node5.setIdxPos(555);
    subnodes1.add(node5);
    PostingNode node6 = new PostingNode(6, new ArrayBytes(new byte[]{53}));
    subnodes1.add(node6);
    SegmentPush sub1 = new SegmentPush(subnodes1);
    PostingNode node7 = new PostingNode(sub1, 7, new ArrayBytes(new byte[]{57}));
    nodes.add(node7);
    PostingNode node9 = new PostingNode(null, 9, new ArrayBytes(new byte[]{59}));
    nodes.add(node9);
    SegmentPush push = new SegmentPush(nodes);

    SegmentPush o;
    List<EditRec> edits = new ArrayList<EditRec>();
//    edits.add(new EditRec(1, new ArrayBytes(new byte[]{11}), false));
//    o = BlueSteelBagIndex.spliceEditsIntoSegmentPush(edits, push);
//    assertEquals(6, o.getCount());
//    Iterator<PostingNode> i = o.iterator();
//    assertTrue(i.hasNext());
//    assertEquals(1, i.next().getDocId());
//    assertTrue(i.hasNext());
//    PostingNode n = i.next();
//    assertEquals(9, n.getDocId());
//    assertEquals(333, n.getPush().getIdxPos());
   
    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<PostingNode> nodes = new ArrayList<PostingNode>();
    nodes.add(new PostingNode(1L, new ArrayBytes(new byte[]{11})));
    nodes.add(new PostingNode(2L, new ArrayBytes(new byte[]{22})));
    nodes.add(new PostingNode(3L, new ArrayBytes(new byte[]{33})));
    nodes.add(new PostingNode(4L, new ArrayBytes(new byte[]{44})));
    nodes.add(new PostingNode(5L, new ArrayBytes(new byte[]{55})));
    nodes.add(new PostingNode(6L, new ArrayBytes(new byte[]{66})));
    nodes.add(new PostingNode(7L, new ArrayBytes(new byte[]{77})));
    o=BlueSteelBagIndex.balanceSegmentPush(new SegmentPush(nodes), 4);
    compareSegments(o, new long[]{1,2,3,4,5,6,7});
    assertEquals(7, o.getCount());
    assertEquals(4, o.nodes.size());
    o=BlueSteelBagIndex.balanceSegmentPush(new SegmentPush(nodes), 2);
View Full Code Here

 
  public byte[] getTermBytes() {
    return term.getBytes();
  }
  public void setTermBytes(byte[] term) {
    this.term = new ArrayBytes(term);
  }
View Full Code Here

    TokenTable(Bytes fixedPrefix, ArrayList<TokenRec> tokenRecs) {
      this.fixedPrefix = fixedPrefix;
      this.tokenRecs = tokenRecs;
    }
    public TokenTable(byte prefixByte, ArrayList<TokenRec> tokenRecs) {
      this(new ArrayBytes(new byte[]{prefixByte}), tokenRecs);
    }
View Full Code Here

 
  class BlueSteelPostingListQuery extends AbstractRangeQueryNode {
    TraversalStack traversal;
    CompoundBytes termBuffer;
    public BlueSteelPostingListQuery(Bytes prefix, byte suffix, SegmentPush segmentPush) {
      this(new ArrayBytes(Util.appendByte(prefix.getBytes(), suffix)), segmentPush);
    }
View Full Code Here

      for(TokenRec rec : table.tokenRecs) {
        if (rec.token >= prefix.get(i)) {
          if (rec.token > prefix.get(i)) return null;
          if (rec.tokenTable==null) {
            Bytes pre = new SlicedBytes(prefix, 0, i+1);
            pre = new ArrayBytes(pre.getBytes()); // optimize
            RangeQueryNode ret = new BlueSteelPostingListQuery(pre, rec.segmentPush);
            return FilteredRangeQueryNode.make(ret, prefix, term1, term2, isExclusive1, isExclusive2);
          }
          table = rec.tokenTable;
          bos.write(rec.token);
          break;
        }
      }
    }
    if (bos.size() > 0) {
      prefix = new CompoundBytes(prefix, new ArrayBytes(bos.toByteArray())).flatten();
    }
   
    if (table == null) return null;
    int top,bottom;
    if (term1 == null) {
View Full Code Here

    // TODO: more efficient; BagIndex needs a "get multi"
    QueryNode data = index.getRange(ArrayBytes.EMPTY_BYTES, null, null, false, false, revNum);
    ArrayList<QueryNode> clauses = new ArrayList<QueryNode>(value.getDeletions().size()+value.getEntries().size());
   
    for(String key : value.getDeletions()) {
      QueryNode q = index.getTerm(new CompoundBytes(ID_BYTES, new ArrayBytes(Util.decodeString(key))), revNum);
      if (q == null) throw new RuntimeException("Object not found; id=\""+key+"\"");
      clauses.add(q);
    }
    if (clauses.size() > 0) {
      QueryNode idQuery = new OrderedOrQueryNode(clauses, null, null, null, false, false);
      do {
        long docId = idQuery.doc();
        data.skipTo(docId);
        do {
          edits.add(new EditRec(docId, data.term(), true));
        } while(data.nextTerm() == NextStatus.NEXT_TERM);
      } while(idQuery.next());
    }
   
    long insId = -1;
    for(Map.Entry<String,Object> entry : value.getEntries().entrySet()) {
      String key = entry.getKey();
      QueryNode q = index.getTerm(new CompoundBytes(ID_BYTES, new ArrayBytes(Util.decodeString(key))), revNum);
      if (q != null) {
        clauses.add(q);
      } else {
        long docId = insId--;
        DbServiceUtil.sencodeMulti(ArrayBytes.EMPTY_BYTES, entry.getValue(), edits, docId, false);
View Full Code Here

  public static final ArrayBytes HEADER_BYTE_LISTOPEN = new ArrayBytes(new byte[]{'['});
  public static final ArrayBytes HEADER_BYTE_MAPOPEN  = new ArrayBytes(new byte[]{'{'});

  public static Bytes sencodeMapKey(String key) {
    try {
      return new ArrayBytes(((String)key).getBytes("utf-8"));
    } catch (UnsupportedEncodingException e) {
      throw new RuntimeException(e);
    }
  }
View Full Code Here

        // lexiographic sort puts big negatives below small negatives
        bits ^= 0xFFFFFFFFFFFFFFFFL;
      } else {
        bits ^= 0x8000000000000000L;
      }
      return new ArrayBytes(new byte[] {
          'n',
          (byte)((bits >>> 8 * 7) & 0xFF),
          (byte)((bits >>> 8 * 6) & 0xFF),
          (byte)((bits >>> 8 * 5) & 0xFF),
          (byte)((bits >>> 8 * 4) & 0xFF),
          (byte)((bits >>> 8 * 3) & 0xFF),
          (byte)((bits >>> 8 * 2) & 0xFF),
          (byte)((bits >>> 8 * 1) & 0xFF),
          (byte)((bits) & 0xFF)});
    } else if (val instanceof String) {
      try {
        Bytes valBytes = new ArrayBytes(((String)val).getBytes("utf-8"));
        return new CompoundBytes(HEADER_BYTE_S, valBytes);
      } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
      }
    } else if (val == null) {
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.