Beispiel #1
0
  /**
   * Find the value associated with the given key, or the entry immediately following this key in
   * the ordered BTree.
   *
   * @param key Lookup key.
   * @return Value associated with the key, or a greater entry, or null if no greater entry was
   *     found.
   */
  public synchronized Tuple findGreaterOrEqual(Object key) throws IOException {
    Tuple tuple;
    TupleBrowser browser;

    if (key == null) {
      // there can't be a key greater than or equal to "null"
      // because null is considered an infinite key.
      return null;
    }

    tuple = new Tuple(null, null);
    browser = browse(key);
    if (browser.getNext(tuple)) {
      return tuple;
    } else {
      return null;
    }
  }
Beispiel #2
0
  /**
   * Find the value associated with the given key.
   *
   * @param key Lookup key.
   * @return Value associated with the key, or null if not found.
   */
  public synchronized Object find(Object key) throws IOException {
    if (key == null) {
      throw new IllegalArgumentException("Argument 'key' is null");
    }
    BPage rootPage = getRoot();
    if (rootPage == null) {
      return null;
    }

    Tuple tuple = new Tuple(null, null);
    TupleBrowser browser = rootPage.find(_height, key);

    if (browser.getNext(tuple)) {
      // find returns the matching key or the next ordered key, so we must
      // check if we have an exact match
      if (_comparator.compare(key, tuple.getKey()) != 0) {
        return null;
      } else {
        return tuple.getValue();
      }
    } else {
      return null;
    }
  }