/** @return False if the value does not match the range, otherwise true. */
  @SuppressWarnings("unchecked")
  private boolean readValue(int pin, long pos, PhEntry<T> result) {
    Object o = node.checkAndGetEntryPIN(pin, pos, valTemplate, result.getKey(), rangeMin, rangeMax);
    if (o == null) {
      return false;
    }

    if (o instanceof Node) {
      Node sub = (Node) o;
      // skip this for postLen>=63
      if (checker != null
          && sub.getPostLen() < (PhTree11.DEPTH_64 - 1)
          && !checker.isValid(sub.getPostLen() + 1, valTemplate)) {
        return false;
      }
      result.setNodeInternal(sub);
      return true;
    }

    if (checker != null && !checker.isValid(result.getKey())) {
      return false;
    }
    result.setValueInternal((T) o);
    return true;
  }
  private boolean niFindNextHCI(PhEntry<T> result) {
    // HCI
    // repeat until we found a value inside the given range
    long currentPos = next;
    do {
      if (currentPos != START && currentPos >= maskUpper) {
        break;
      }

      if (currentPos == START) {
        // starting position
        currentPos = maskLower;
      } else {
        currentPos = PhTree11.inc(currentPos, maskLower, maskUpper);
        if (currentPos <= maskLower) {
          break;
        }
      }

      Object v = node.ntGetEntry(currentPos, result.getKey(), valTemplate);
      if (v == null) {
        continue;
      }

      next = currentPos;

      // read and check post-fix
      if (readValue(currentPos, v, result)) {
        return true;
      }
    } while (true);
    return false;
  }
 private boolean niFindNextIter(PhEntry<T> result) {
   while (niIterator.hasNext()) {
     NtEntry<Object> e = niIterator.nextEntryReuse();
     System.arraycopy(e.getKdKey(), 0, result.getKey(), 0, dims);
     if (readValue(e.key(), e.value(), result)) {
       next = e.getKey(); // This is required for kNN-adjusting of iterators
       return true;
     }
   }
   return false;
 }
  private boolean readValue(long pos, Object value, PhEntry<T> result) {
    if (!node.checkAndGetEntryNt(pos, value, result, valTemplate, rangeMin, rangeMax)) {
      return false;
    }

    // subnode ?
    if (value instanceof Node) {
      Node sub = (Node) value;
      // skip this for postLen>=63
      if (checker != null
          && sub.getPostLen() < (PhTree11.DEPTH_64 - 1)
          && !checker.isValid(sub.getPostLen() + 1, valTemplate)) {
        return false;
      }
      return true;
    }

    return checker == null || checker.isValid(result.getKey());
  }