Package dovetaildb.bytes

Examples of dovetaildb.bytes.Bytes


    if (idQuery != null) {
      long docId = idQuery.doc();
      assert docId > lastDocId;
      lastDocId = docId;
      do {
        Bytes idTerm = idQuery.term();
        assert idTerm.compareToParts(ID_BYTES, 0, 0, NUM_ID_BYTES, NUM_ID_BYTES, 9) == 0;
        byte[] idBytes = idTerm.subBytes(NUM_ID_BYTES, idTerm.getLength()-NUM_ID_BYTES).getBytes();
        String idString = Util.encodeBytes(idBytes);
        Object val = entries.get(idString);
        if (val != null) {
          entries.remove(idString);
          DbServiceUtil.sencodeMulti(ArrayBytes.EMPTY_BYTES, ArrayBytes.EMPTY_BYTES, val, edits, docId, false);
View Full Code Here


      if (isAllowed()) return true;
    }
    return false;
  }
  private boolean isAllowed() {
    Bytes term = subQueryNode.term();
    return (allowed.contains(term));
  }
View Full Code Here

  public static void sencodeMulti(Bytes prefix, Bytes suffix, Object val, ArrayList<EditRec> buffer, long docId, boolean idDel) {
    if (val instanceof Map) {
      Map map = (Map)val;
      prefix = CompoundBytes.make(prefix, HEADER_BYTE_MAPOPEN);
      if (true) {
        Bytes headerBytes = CompoundBytes.make(prefix, suffix);
        buffer.add(new EditRec(docId, headerBytes.flatten(), idDel));
      }
      for(Object entryObj : map.entrySet()) {
        Map.Entry entry = (Map.Entry) entryObj;
        String key = (String)entry.getKey();
        Bytes sub = new CompoundBytes(prefix, sencodeMapKey(key));
        sub = new CompoundBytes(sub, HEADER_BYTE_COLON);
        sencodeMulti(sub, suffix, entry.getValue(), buffer, docId, idDel);
      }
    } else if (val instanceof List) {
      List list = (List)val;
      prefix = CompoundBytes.make(prefix, HEADER_BYTE_LISTOPEN);
      if (true) {
        Bytes headerBytes = CompoundBytes.make(prefix, suffix);
        buffer.add(new EditRec(docId, headerBytes.flatten(), idDel));
      }
      for(int index=list.size()-1; index>=0; index--) {
        Object subVal = list.get(index);
        Bytes newSuffix = CompoundBytes.make(DbServiceUtil.sencodeListIndex(index), suffix);
        sencodeMulti(prefix, newSuffix, subVal, buffer, docId, idDel);
      }
    } else {
      Bytes bytes = CompoundBytes.make(CompoundBytes.make(prefix,sencode(val)),suffix);
      buffer.add(new EditRec(docId, bytes.flatten(), false));
    }
  }
View Full Code Here

          (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

      ArrayList<QueryNode> nodes = new ArrayList<QueryNode>();
      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);
        QueryNodeTemplate templ = applyPatternToBagIndex(curPrefix, value, index, revNum);
        nodes.add(templ.queryNode);
        vars.putAll(templ.varMappings);
      }
      if (map.isEmpty()) {
        queryNode = index.getRange(new Range(prefix, null, null, true, true), revNum);
      } else {
        queryNode = AndQueryNode.make(nodes);
      }
    } else if (pattern instanceof List) {
      List list = (List)pattern;
      if (list.size() > 0 && list.get(0) != null &&
          list.get(0) instanceof String &&
          SYMBOLS.contains(list.get(0).hashCode())) {
        return applyQueryToBagIndex(prefix, list, index, revNum);
      } else if (list.size() > 1) {
        throw new ApiException("QueryFormatError", "malformed list structure in query: "+pattern);
      } else {
        prefix = new CompoundBytes(prefix, HEADER_BYTE_LISTOPEN);
        if (list.isEmpty()) {
          queryNode = index.getTerm(prefix, revNum);
        } else {
          QueryNodeTemplate templ = applyPatternToBagIndex(prefix, list.get(0), index, revNum);
          queryNode = templ.queryNode;
          vars.putAll(templ.varMappings);
        }
      }
    } else {
      Bytes matchingBytes = new CompoundBytes(prefix,sencode(pattern));
      queryNode = index.getTerm(matchingBytes, revNum);
//      System.out.println(matchingBytes.toString()+" -> "+queryNode+" in "+revNum);
    }
    return new QueryNodeTemplate(queryNode, vars);
  }
View Full Code Here

      apply(query);
      return ranges;
    }
  }
  public static Range parseRange(Bytes prefix, int opHash, List<Object> query) {
    Bytes term1 = null;
    Bytes term2 = null;
    boolean isExclusive1 = false;
    boolean isExclusive2 = false;
    switch(opHash) {
    case DbServiceUtil.OP_HASH_AS:
    case DbServiceUtil.OP_HASH_ANY:
View Full Code Here

      } else {
        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);
          extractRangesFrom(curPrefix, value, ranges);
        }
      }
    } else if (pattern instanceof List) {
      List<Object> list = (List<Object>)pattern;
      if (list.size() > 0 && SYMBOLS.contains(list.get(0).hashCode())) {
        int opHash = list.get(0).hashCode();
        switch(opHash) {
        case DbServiceUtil.OP_HASH_AS:
        case DbServiceUtil.OP_HASH_OR:
        case DbServiceUtil.OP_HASH_AND:
        case DbServiceUtil.OP_HASH_NOT:
          throw new ApiException("QueryFormatError", "Invalid narrowing operator: "+list.get(0));
        default:
          ranges.add(parseRange(prefix, opHash, list));
        }
      } else if (list.size() > 1) {
        throw new RuntimeException("malformed list structure in query: "+pattern);
      } else {
        prefix = new CompoundBytes(prefix, HEADER_BYTE_LISTOPEN);
        if (list.isEmpty()) {
          ranges.add(new Range(prefix, null, null, true, true));
        } else {
          extractRangesFrom(prefix, list.get(0), ranges);
        }
      }
    } else {
      Bytes term = new CompoundBytes(prefix,sencode(pattern));
      ranges.add(new Range(term, ArrayBytes.EMPTY_BYTES, ArrayBytes.EMPTY_BYTES, true, true));
    }
  }
View Full Code Here

  public Bytes findAnyMatching(long seekDoc, Bytes seekTerm) {
    int ctr=0;
    int seekCtr=0;
    while (true) {
      ctr++;
      Bytes returnValue = null;
      QueryNode node = heap.top();
      long nodeDoc = node.doc();
      Bytes nodeTerm = node.term();
      boolean fastForward = node.compareTo(seekDoc, seekTerm) <= 0;
      if (fastForward) {
        seekCtr++;
        node.seek(seekDoc, seekTerm);
      }
View Full Code Here

        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) {
View Full Code Here

      if (push != null) {
        v1 |= 1;
      }
      long startPos = data.getSize();
      data.appendVLong(v1);
      Bytes token = node.getToken();
      data.appendVLong(token.getLength());
//      System.out.println("W "+data.getSize()+":"+token.getLength()+" ["+token+"] @ "+data);
      token.appendTo(data);
      if (push != null) {
        data.appendVLong(((FsPostingNode)push.leadNode).startPos);
        data.appendVLong(push.getCount());
      }
      return new FsPostingNode(data, startPos);
View Full Code Here

TOP

Related Classes of dovetaildb.bytes.Bytes

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.