Package dovetaildb.bytes

Examples of dovetaildb.bytes.Bytes


        return NextStatus.NEXT_DOC;
      }
    }
    public void seek(long seekDoc, Bytes seekTerm) {
      int seekTermLen = seekTerm.getLength();
      Bytes myPrefix = termBuffer.getPrefix();
      int myPrefixLen = myPrefix.getLength();

      if (myPrefix.isPrefixOf(seekTerm)) {
        seekBuffer.reInitialize(seekTerm, myPrefixLen, seekTermLen - myPrefixLen);
        seekTerm = seekBuffer;
      } else {
        if (seekTerm.compareTo(myPrefix) > 0) {
          // snap to the next doc
View Full Code Here


    }
    public Bytes term() {
      if (traversal.getCurrent() == null) {
        throw new RuntimeException();
      }
      Bytes token = traversal.getCurrent().token;
      termBuffer.setSuffix(token);
      return termBuffer;
    }
View Full Code Here

      Bytes token = traversal.getCurrent().token;
      termBuffer.setSuffix(token);
      return termBuffer;
    }
    public QueryNode specialize(Range range) {
      Bytes prefix = range.prefix;
      int prefixLen = prefix.getLength();
      Bytes myPrefix = termBuffer.getPrefix();
      int myPrefixLen = myPrefix.getLength();
      if (prefixLen <= myPrefixLen) {
        if (! range.containsPrefix(myPrefix)) return null;
        return this;
      }// TODO can exclude something in the else too
      if (tokenRec.tokenTable == null) {
View Full Code Here

    for(int i=0; i<200; i++) {
      tryQuery(byId, revNum, r);
    }
  }
  private Range genRange(Random r) {
    Bytes pre = randTerm(r);
    Bytes r1 = r.nextBoolean() ? null : randTerm(r);
    Bytes r2 = r.nextBoolean() ? null : randTerm(r);
    Bytes min, max;
    if (r1 != null && r2 != null) {
      min = (r1.compareTo(r2) < 0) ? r1 : r2;
      max = (r1.compareTo(r2) < 0) ? r2 : r1;
    } else {
      min = r1;
View Full Code Here

    switch (r.nextInt(2)) {
    case 0:
      final ArrayList<Bytes> termsForQuery = new ArrayList<Bytes>();
      final ArrayList<Bytes> terms = new ArrayList<Bytes>();
      for(int i=r.nextInt(10); i>=0; i--) {
        Bytes bytes = randTerm(r);
        terms.add(bytes);
        termsForQuery.add(bytes.copy());
      }
      node = index.getTerms(termsForQuery, revNum);
      matches = new Filter<Bytes>(){
        public MatchReq filter(Bytes item) {
          return terms.contains(item) ? MatchReq.mustmatch : MatchReq.nomatch;
        }
      };
      break;
    case 1:
      Range range = genRange(r);
      range.flattenTerms();
      boolean relaxed = false;
      Range spec = null;
      if (r.nextBoolean()) {
        node = index.getRange(new Range(range), revNum);
      } else {
        spec = new Range(range);
        Bytes prefix = range.getPrefix();
        Bytes min = range.getMinSuffix();
        Bytes max = range.getMaxSuffix();
        if (min == null && max == null) {
          range.setPrefix(new SlicedBytes(prefix, 0, r.nextInt(prefix.getLength()+1)));
        } else if (min == null) {
          range.setMaxSuffix(new SlicedBytes(max, 0, r.nextInt(max.getLength()+1)));
        } else {
          range.setMinSuffix(new SlicedBytes(min, 0, r.nextInt(min.getLength()+1)));
        }
        spec.flattenTerms();
        range.flattenTerms();
View Full Code Here

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

  public void setPrefix(Bytes prefix) {
    this.prefix = prefix;
  }
  public void propagatePrefixIntoRange(int prefixPos) {
    if (prefixPos == prefix.getLength()) return;
    Bytes delta = new SlicedBytes(prefix, prefixPos);
    prefix = new SlicedBytes(prefix, 0, prefixPos);
    if (minSuffix == null) {
      minSuffix = delta;
      isMinIncluded = true;
    } else {
      minSuffix = CompoundBytes.prependBytes(minSuffix, delta);
    }
    if (maxSuffix == null) {
      byte[] bytes = delta.getBytes();
      if (! Util.incrementBinary(bytes)) {
        maxSuffix = null;
        isMaxIncluded = true;
      } else {
        maxSuffix = new ArrayBytes(bytes);
View Full Code Here

  public String toString() {
    return "Range("+prefix+","+this.minSuffix+","+this.maxSuffix+","+this.isMinIncluded+","+this.isMaxIncluded+")";
  }
  public boolean matches(Bytes term) {
    if (! prefix.isPrefixOf(term)) return false;
    Bytes suffix = term.copy().subBytes(prefix.getLength());
    if (minSuffix != null) {
      int minCmp = suffix.compareTo(minSuffix);
      if (minCmp < 0) return false;
      if (minCmp == 0 && ! isMinIncluded) return false;
    }
    if (maxSuffix != null) {
      int maxCmp = suffix.compareTo(maxSuffix);
      if (maxCmp > 0) return false;
      if (maxCmp == 0 && ! isMaxIncluded) return false;
    }
    return true;
  }
View Full Code Here

    int prefixLen = prefix.getLength();
    if (testLen <= prefixLen) {
      return test.isPrefixOf(prefix);
    } else {
      if (! prefix.isPrefixOf(test)) return false;
      Bytes testSuffix = new SlicedBytes(test, prefixLen, testLen-prefixLen);
      if (minSuffix != null) {
        if ((! testSuffix.isPrefixOf(minSuffix)) &&
            (testSuffix.compareTo(minSuffix) < 0)) return false;
      }
      if (maxSuffix != null) {
        if ((! testSuffix.isPrefixOf(maxSuffix)) &&
              (testSuffix.compareTo(maxSuffix) > 0)) return false;
      }
      return true;
    }
  }
View Full Code Here

  }

  public static ArrayList<EditRec> popTermBytes(ArrayList<EditRec> editBuffer) {
    ArrayList<EditRec> newTermBytes = new ArrayList<EditRec>();
    for(EditRec edit : editBuffer) {
      Bytes term = edit.term;
      int newLength = term.getLength() - 1;
      term = new SlicedBytes(term, 1, newLength);
      newTermBytes.add(new EditRec(edit.docId, term, edit.isDeletion));
    }
    return newTermBytes;
  }
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.