Package dovetaildb.bytes

Examples of dovetaildb.bytes.SlicedBytes


    edits.add(new EditRec(1, bytes("brother:yes"), false));
    edits.add(new EditRec(1, bytes("name:phil"), false));

    root=BlueSteelBagIndex.applyEditsToTokenTable(edits, root, new ProbabilisticBalancingPolicy(10, 0.5f, 0.0f), 2); // "2" here means we get three tiers

    SlicedBytes sb;
    TokenRec tr;
    sb = new SlicedBytes(ArrayBytes.fromString("brot"), 0, 4);
    tr = root.descend(sb);
    assertEquals(3, sb.getSlicePosition());
    assertEquals('o', (char)tr.token);
   
    sb = new SlicedBytes(ArrayBytes.fromString("bro"), 0, 3);
    tr = root.descend(sb);
    assertEquals(3, sb.getSlicePosition());
    assertEquals('o', (char)tr.token);
    assertEquals(0, sb.getLength());
   
    sb = new SlicedBytes(ArrayBytes.fromString(""), 0, 0);
    tr = root.descend(sb);
    assertNull(tr);
    assertEquals(0, sb.getLength());
   
    sb = new SlicedBytes(ArrayBytes.fromString("a"), 0, 1);
    tr = root.descend(sb);
    assertEquals(1, sb.getSlicePosition());
    assertEquals('a', (char)tr.token);
    assertEquals(0, sb.getLength());
   
    sb = new SlicedBytes(ArrayBytes.fromString("brXX"), 0, 4);
    tr = root.descend(sb);
    assertNull(tr);
    assertTrue(sb.getLength() > 0);
   
    sb = new SlicedBytes(ArrayBytes.fromString("aXXX"), 0, 4);
    tr = root.descend(sb);
    assertNull(tr);
    assertTrue(sb.getLength() > 0);
   
    sb = new SlicedBytes(ArrayBytes.fromString("XXXX"), 0, 4);
    tr = root.descend(sb);
    assertNull(tr);
    assertTrue(sb.getLength() > 0);
   
  }
View Full Code Here


        return this;
      }// TODO can exclude something in the else too
      if (tokenRec.tokenTable == null) {
        return this;
      }
      SlicedBytes slice = new SlicedBytes(prefix, 0);
      TokenRec subRec = tokenRec.tokenTable.descend(slice);
      if (subRec == null) {
        if (slice.getLength() > 0) {
          return null; // no results apply
        } else {
          return this; // all results apply
        }
      } else if (subRec == tokenRec) {
View Full Code Here

        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();
        node = index.getRange(new Range(range), revNum);
//        while (node != null) {
View Full Code Here

      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);
   
    compressed = index.compress(new ArrayBytes(new byte[]{0, (byte)250, 42}));
    assertEquals(new ArrayBytes(new byte[]{(byte)((250<<3)/256), (byte)((250<<3)%256), 42}), compressed);
   
    compressed = index.compress(new ArrayBytes(new byte[]{1, 5, 42}));
    assertEquals(new ArrayBytes(new byte[]{1<<3, 5<<3, 42}), compressed);
   
    slice = new SlicedBytes(new ArrayBytes(new byte[]{0, 5<<3, 42}), 0, 3);
    uncompressed = index.decompressPrefix(slice);
    assertEquals(2, slice.getSlicePosition());
    assertEquals(new ArrayBytes(new byte[]{0, 5}), uncompressed);
  }
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

    }
    if (i == 0) {
      minSuffix = minTerm;
      maxSuffix = maxTerm;
    } else {
      prefix = new SlicedBytes(minTerm, 0, i);
      minSuffix = minTerm.subBytes(i);
      maxSuffix = maxTerm.subBytes(i);
    }
  }
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

  }
 
  @Override
  public QueryNode getRange(Range range, long revNum) {
    TokenTable table = getRootTokenTable(revNum);
    SlicedBytes slice = new SlicedBytes(range.prefix, 0);
    TokenRec rec = table.descend(slice);
    return queryNodeFromDescent(rec, slice, table, range);
  }
View Full Code Here

  public static Bytes[] determineCompressionTable(BagIndex index, double lengthToRowRatio) {
    long forkThreshold = 25;
    QueryNode query = index.getRange(Range.OPEN_RANGE, index.getCurrentRevNum());
    ByteTable root = new ByteTable();
    if (query == null) return EMPTY_BYTE_ARRAY;
    SlicedBytes slice = new SlicedBytes(ArrayBytes.EMPTY_BYTES, 0);
    do {
      Bytes term = query.term();
      slice.reInitialize(query.term(), 0, term.getLength());
      root.count(slice, forkThreshold);
    } while(query.anyNext());
    long counted = root.hits;
    int numSlots = 1 << integerLogBase2RoundDown((long)(Math.sqrt(counted)/lengthToRowRatio));
    long minHits = (counted / numSlots) >> 8;
View Full Code Here

TOP

Related Classes of dovetaildb.bytes.SlicedBytes

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.