Package dovetaildb.bytes

Examples of dovetaildb.bytes.CompoundBytes


        ranges.add(new Range(prefix, null, null, true, true));
      }
    }
    @Override
    public void handleAtomic(Bytes prefix, Bytes suffix, Object value) {
      Bytes term = new CompoundBytes(prefix,sencode(value));
      ranges.add(new Range(term, ArrayBytes.EMPTY_BYTES, ArrayBytes.EMPTY_BYTES, true, true));
    }
View Full Code Here


    if (byObjectKey == null) {
      byObjectKey = new HashMap<String, QueryNodeDbResult>();
    }
    QueryNodeDbResult result = byObjectKey.get(key);
    if (result == null) {
      Bytes byteKey = new CompoundBytes(DbServiceUtil.HEADER_BYTE_MAPOPEN,
          new CompoundBytes(DbServiceUtil.sencodeMapKey(key),
              DbServiceUtil.HEADER_BYTE_COLON));
      Bytes subPrefix = new CompoundBytes(prefix, byteKey).flatten();
      result = new QueryNodeDbResult(node, subPrefix, suffix);
      byObjectKey.put(key, result);
    }
    return result;
  }
View Full Code Here

        byArrayIndex.add(null);
      }
    }
    QueryNodeDbResult result = byArrayIndex.get(index);
    if (result == null) {
      Bytes newPrefix = new CompoundBytes(prefix, DbServiceUtil.HEADER_BYTE_LISTOPEN).flatten();
      Bytes newSuffix = new CompoundBytes(DbServiceUtil.sencodeListIndex(index),suffix).flatten();
      result = new QueryNodeDbResult(node, newPrefix, newSuffix);
      byArrayIndex.set(index, result);
    }
    return result;
  }
View Full Code Here

      traversal = new TraversalStack(tokenRec.getSegmentPush());
      init(prefix, tokenRec);
    }
    protected void init(Bytes prefix, TokenRec tokenRec) {
      this.tokenRec = tokenRec;
      termBuffer = new CompoundBytes(prefix, null);
      if (! traversal.nextOrDown()) {
        throw new RuntimeException();
      }
      docId = traversal.getCurrentDocId();
    }
View Full Code Here

      }
      return queryNodeFromDescent(subRec, slice, tokenRec.tokenTable, range);
    }
   
    public QueryNode copy() {
      CompoundBytes termBufferCopy = new CompoundBytes(termBuffer.getPrefix(), termBuffer.getSuffix());
      return new BlueSteelPostingListQuery(traversal.copy(), termBufferCopy, tokenRec);
    }
View Full Code Here

      data = index.getRange(Range.OPEN_RANGE, revNum);
      int capacity = value.getDeletions().size()+value.getEntries().size();
      if (capacity > 0) {
        ArrayList<Bytes> idTerms = new ArrayList<Bytes>(capacity);
        for(String key : value.getDeletions()) {
          idTerms.add(new CompoundBytes(ID_BYTES, new ArrayBytes(Util.decodeString(key))));
        }
        for(String key : entries.keySet()) {
          idTerms.add(new CompoundBytes(ID_BYTES, new ArrayBytes(Util.decodeString(key))));
        }
        idQuery = index.getTerms(idTerms, revNum);
      }
    }
    long lastDocId = Long.MIN_VALUE;
View Full Code Here

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

          (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) {
      return HEADER_BYTE_L;
View Full Code Here

  public static QueryNodeTemplate applyPatternToBagIndex(Bytes prefix, Object pattern, BagIndex index, long revNum) {
    Map<String, QueryNode> vars = new HashMap<String, QueryNode>();
    QueryNode queryNode;
    if (pattern instanceof Map) {
      Map map = (Map)pattern;
      prefix = new CompoundBytes(prefix, HEADER_BYTE_MAPOPEN);
      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

    return new Range(prefix, term1, term2, !isExclusive1, !isExclusive2);
  }
  public static void extractRangesFrom(Bytes prefix, Object pattern, ArrayList<Range> ranges) {
    if (pattern instanceof Map) {
      Map map = (Map)pattern;
      prefix = new CompoundBytes(prefix, HEADER_BYTE_MAPOPEN);
      if (map.isEmpty()) {
        ranges.add(new Range(prefix, null, null, true, true));
      } 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

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.