Package dovetaildb.bytes

Examples of dovetaildb.bytes.CompoundBytes


    }
    public void apply(Bytes prefix, Bytes suffix, Object pattern) {
      if (pattern instanceof Map) {
        Map<String,Object> map = (Map<String,Object>)pattern;
        handleMap(prefix, suffix, map);
        prefix = new CompoundBytes(prefix, HEADER_BYTE_MAPOPEN);
        for(Object entryObj : map.entrySet()) {
          Map.Entry entry = (Map.Entry) entryObj;
          String key = (String)entry.getKey();
          Object value = entry.getValue();
          Bytes curPrefix = new CompoundBytes(prefix, sencodeMapKey(key));
          curPrefix = new CompoundBytes(curPrefix, HEADER_BYTE_COLON);
          handleMapEntry(prefix, suffix, key, value);
          apply(curPrefix, suffix, value);
        }
      } else if (pattern instanceof List) {
        List<Object> list = (List<Object>)pattern;
        if (list.size() > 0) {
          Object first = list.get(0);
          if (first != null && first instanceof String && isOperationLead((String)first)) {
            handleOperation(prefix, suffix, (String)first, list);
          }
        } else if (list.size() > 1) {
          throw new ApiException("QueryFormatError", "malformed list structure; only 1 element is allowed here: "+pattern);
        } else {
          prefix = new CompoundBytes(prefix, HEADER_BYTE_LISTOPEN);
          handleList(prefix, suffix, list);
        }
      } else {
        handleAtomic(prefix, suffix, pattern);
      }
View Full Code Here


            subTable = parent.getTokenTable();
            push = parent.getSegmentPush();
          }
          if (subTable == null) {
            if (termTableDepth > 0) {
              Bytes newPrefix = new CompoundBytes(table.getFixedPrefix(), ArrayBytes.SINGLE_BYTE_OBJECTS[editBufferByte & 0xff]);
              subTable = new MemoryTokenTable(newPrefix, new ArrayList<TokenRec>());
            }
          }
          if (subTable != null) {
            subTable = applyEditsToTokenTable(subTokenTableEdits, subTable, policy, termTableDepth-1);
View Full Code Here

    int mappingIdx = 0;
    for(int i=0; i<numCompressedBytes; i++) {
      mappingIdx = (mappingIdx << 8) | (compressed.get(0) & 0xff);
      compressed = compressed.subBytes(1);
    }
    CompoundBytes uncompressed = mapping[mappingIdx >> numCenteringBits];
    return uncompressed.getPrefix();
  }
View Full Code Here

      int prevLen = prev.getLength();
      while(prevLen > 0 && prev.get(prevLen-1) == 255) {
        prevLen -= 1;
      }
      if (curLen >= prevLen) {
        mapping[i] = new CompoundBytes(cur, ArrayBytes.EMPTY_BYTES);
      } else {
        byte[] cmpBytes = new byte[prevLen-curLen];
        for(int j=curLen; j<prevLen; j++) {
          int thisByte = prev.get(j);
          if (j == prevLen-1) { // incr byte
            thisByte++;
          }
          cmpBytes[j-curLen] = (byte)thisByte;
        }
        // needs a compare key
        mapping[i] = new CompoundBytes(cur, new ArrayBytes(cmpBytes));
      }
      prev = cur;
    }
    assert (mapping.length & (mapping.length-1)) == 0; // assert length is a power of 2
    this.numCompressedBits = integerLogBase2RoundDown(mapping.length);
View Full Code Here

  protected Bytes termForTxnBag(String bag, long txn) {
    byte[] bagNameBytes = bag.getBytes();
    byte[] revNumBytes = new byte[9];
    Util.beLongToBytes(txn, revNumBytes, 1);
    return new CompoundBytes(
        new ArrayBytes(bagNameBytes),
        new ArrayBytes(revNumBytes));
  }
View Full Code Here

    public DocRec down() { return down; }
    public DocRec next() { return next; }
    public long compareTo(DocTerm docTerm) {
      long delta = docId - docTerm.docId;
      if (delta != 0) return delta;
      return new CompoundBytes(prefix,suffix).compareTo(docTerm.term);
    }
View Full Code Here

    public void setNext(Rec r) {this.next = (TermRec)r; }
    public long cumulativeCount() { return docCt + 1; }
    public TermRec down() { return down; }
    public TermRec next() { return next; }
    public long compareTo(DocTerm docTerm) {
      return new CompoundBytes(prefix,suffix).compareTo(docTerm.term);
    }
View Full Code Here

    public BlueSteelPostingListQuery(Bytes prefix, byte suffix, SegmentPush segmentPush) {
      this(new ArrayBytes(Util.appendByte(prefix.getBytes(), suffix)), segmentPush);
    }
    public BlueSteelPostingListQuery(Bytes prefix, SegmentPush segmentPush) {
      super(prefix, ArrayBytes.EMPTY_BYTES, ArrayBytes.EMPTY_BYTES, false, false);
      termBuffer = new CompoundBytes(prefix, null);
      traversal = new TraversalStack(segmentPush);
      traversal.next();
      traversal.checkpoint();
    }
View Full Code Here

          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

TOP

Related Classes of dovetaildb.bytes.CompoundBytes

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.