/**
   * Operator equal, compares the BaseCryptoRandomStream object with the BaseCryptoRandomStream
   * parameter
   *
   * @param otherStream stream to be content compared with this stream
   */
  public boolean Equals(BaseCryptoRandomStream otherStream) {
    ByteBuffer thisBuffer;
    int thisLimit = 0;
    ByteBuffer paramBuffer;
    int paramLimit = 0;
    int result;

    if (otherStream == null) {
      return false;
    } else {
      if (this.GetBitLength() != otherStream.GetBitLength()) {
        return false;
      } else {
        thisBuffer = this.cryptoBuffer;
        if (this.ReducedLength()) {
          thisLimit = this.cryptoBuffer.limit();
          thisBuffer.limit(this.GetUCLength());
        }
        paramBuffer = otherStream.cryptoBuffer;
        if (otherStream.ReducedLength()) {
          paramLimit = otherStream.cryptoBuffer.limit();
          paramBuffer.limit(otherStream.GetUCLength());
        }
        result = thisBuffer.compareTo(paramBuffer);
        if (this.ReducedLength()) {
          this.cryptoBuffer.limit(thisLimit);
        }
        paramBuffer = otherStream.cryptoBuffer;
        if (otherStream.ReducedLength()) {
          otherStream.cryptoBuffer.limit(paramLimit);
        }
        return (result == 0);
      }
    }
  }
 @Override
 public ByteBuffer get(ByteBuffer key) throws IOException, AlluxioException {
   Preconditions.checkNotNull(key);
   // TODO(binfan): improve the inefficient for-loop to binary search.
   for (PartitionInfo partition : mPartitions) {
     // NOTE: keyStart and keyLimit are both inclusive
     if (key.compareTo(partition.bufferForKeyStart()) >= 0
         && key.compareTo(partition.bufferForKeyLimit()) <= 0) {
       long blockId = partition.getBlockId();
       KeyValuePartitionReader reader = KeyValuePartitionReader.Factory.create(blockId);
       try {
         ByteBuffer value = reader.get(key);
         return value;
       } finally {
         reader.close();
       }
     }
   }
   return null;
 }
Exemple #3
0
 @Override
 public int compareTo(Datum datum) {
   switch (datum.type()) {
     case BLOB:
       initFromBytes();
       ((BlobDatum) datum).initFromBytes();
       return bb.compareTo(((BlobDatum) datum).bb);
     case NULL_TYPE:
       return -1;
     default:
       throw new InvalidOperationException(datum.type());
   }
 }
 /* XXX add equals for columns */
 public boolean equal(TableSplit split) {
   return Serialization.equals(m_tablename, split.m_tablename)
       && m_startrow.compareTo(split.getStartRow()) == 0
       && m_endrow.compareTo(split.getEndRow()) == 0
       && m_hostname.equals(split.m_hostname);
 }
 public int compareTo(TableSplit split) {
   return m_startrow.compareTo(split.getStartRow());
 }
  /**
   * Updates the ScanSpec by setting the row interval to match this split
   *
   * @param scan_spec The base ScanSpec to start with
   * @return a new scan_spec object with a row interval matching this split
   */
  public ScanSpec createScanSpec(ScanSpec base_spec) {
    ScanSpec scan_spec = new ScanSpec(base_spec);

    RowInterval interval = new RowInterval();

    scan_spec.unsetRow_intervals();

    try {

      if (m_startrow != null && m_startrow.limit() > 0) {
        interval.setStart_row_binary(m_startrow);
        interval.setStart_inclusive(false);
        interval.setStart_inclusiveIsSet(true);
      }

      if (m_endrow != null && m_endrow.limit() > 0) {
        interval.setEnd_row_binary(m_endrow);
        interval.setEnd_inclusive(true);
        interval.setEnd_inclusiveIsSet(true);
      }

      ByteBuffer riStartRow;
      ByteBuffer riEndRow;
      Charset charset = Charset.forName("UTF-8");
      CharsetEncoder encoder = charset.newEncoder();

      if (base_spec.isSetRow_intervals()) {
        for (RowInterval ri : base_spec.getRow_intervals()) {
          riStartRow =
              (ri != null && ri.isSetStart_row())
                  ? encoder.encode(CharBuffer.wrap(ri.getStart_row()))
                  : null;
          riEndRow =
              (ri != null && ri.isSetEnd_row())
                  ? encoder.encode(CharBuffer.wrap(ri.getEnd_row()))
                  : null;
          if (riStartRow != null) {
            if (m_startrow == null
                || m_startrow.limit() == 0
                || riStartRow.compareTo(m_startrow) > 0) {
              interval.setStart_row_binary(riStartRow);
              interval.setStart_inclusive(ri.isStart_inclusive());
              interval.setStart_inclusiveIsSet(true);
            }
          }
          if (riEndRow != null) {
            if (m_endrow == null || m_endrow.limit() == 0 || riEndRow.compareTo(m_endrow) < 0) {
              interval.setEnd_row_binary(riEndRow);
              interval.setEnd_inclusive(ri.isEnd_inclusive());
              interval.setEnd_inclusiveIsSet(true);
            }
          }
          // Only allowing a single row interval
          break;
        }
      }

    } catch (CharacterCodingException e) {
      e.printStackTrace();
      System.exit(-1);
    }

    if (interval.isSetStart_row_binary() || interval.isSetEnd_row_binary()) {
      scan_spec.addToRow_intervals(interval);
      scan_spec.setRow_intervalsIsSet(true);
    }

    return scan_spec;
  }
 public int compareTo(WiffByteBuffer b) {
   return buffer.compareTo(b.asByteBuffer());
 }