// Path: hawtdb/src/main/java/org/fusesource/hawtdb/api/Predicate.java
// public interface Predicate<Key> {
//     
//     /**
//      * 
//      * @param first the first key in the range or null if unknown
//      * @param second the last key in the range or null if unknown
//      * @param comparator the Comparator configured for the index, may be null.
//      *
//      * @return true if the predicate is interested in keys in the range.
//      */
//     boolean isInterestedInKeysBetween(Key first, Key second, Comparator comparator);
//     
//     /**
//      * @param key
//      * @param comparator the Comparator configured for the index, may be null.
//      *
//      * @return true if the predicate is interested in the key
//      */
//     boolean isInterestedInKey(Key key, Comparator comparator);
//     
// }


import org.fusesource.hawtdb.api.Predicate;
import java.util.*;
import java.util.Map.Entry;
/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.fusesource.hawtdb.internal.index;



/**
 *
 * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
 */
final class BTreePredicateIterator<Key, Value> implements Iterator<Entry<Key, Value>> {

    private final BTreeIndex<Key, Value> index;
    private Predicate<Key> predicate;
    private final Stack<Data<Key, Value>> stack = new Stack<Data<Key, Value>>();


    private class Data<Key, Value> {
        private BTreeNode<Key, Value> node;
        private int pos;

        public Data(BTreeNode<Key, Value> node) {
            this.node = node;
        }
    }

    private Entry<Key, Value> nextEntry;

// Path: hawtdb/src/main/java/org/fusesource/hawtdb/api/Predicate.java
// public interface Predicate<Key> {
//     
//     /**
//      * 
//      * @param first the first key in the range or null if unknown
//      * @param second the last key in the range or null if unknown
//      * @param comparator the Comparator configured for the index, may be null.
//      *
//      * @return true if the predicate is interested in keys in the range.
//      */
//     boolean isInterestedInKeysBetween(Key first, Key second, Comparator comparator);
//     
//     /**
//      * @param key
//      * @param comparator the Comparator configured for the index, may be null.
//      *
//      * @return true if the predicate is interested in the key
//      */
//     boolean isInterestedInKey(Key key, Comparator comparator);
//     
// }


// Path: hawtdb/src/main/java/org/fusesource/hawtdb/internal/index/BTreePredicateIterator.java
import org.fusesource.hawtdb.api.Predicate;
import java.util.*;
import java.util.Map.Entry;

/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.fusesource.hawtdb.internal.index;



/**
 *
 * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
 */
final class BTreePredicateIterator<Key, Value> implements Iterator<Entry<Key, Value>> {

    private final BTreeIndex<Key, Value> index;
    private Predicate<Key> predicate;
    private final Stack<Data<Key, Value>> stack = new Stack<Data<Key, Value>>();


    private class Data<Key, Value> {
        private BTreeNode<Key, Value> node;
        private int pos;

        public Data(BTreeNode<Key, Value> node) {
            this.node = node;
        }
    }

    private Entry<Key, Value> nextEntry;

    BTreePredicateIterator(BTreeIndex<Key, Value> index, BTreeNode<Key, Value> root, Predicate<Key> predicate) {