001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.fusesource.hawtdb.api;
018    
019    import java.io.IOException;
020    import java.util.Iterator;
021    import java.util.Map;
022    
023    /**
024     * Provides Key/Value storage and retrieval. 
025     * 
026     * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
027     */
028    public interface Index<Key,Value> {
029    
030        /**
031         * Frees any extra storage that the index created.
032         */
033        void destroy();
034        
035        /**
036         * clear the index
037         * 
038         * @throws IOException
039         * 
040         */
041        void clear();
042    
043        /**
044         * @param key
045         * @return true if it contains the key
046         * @throws IOException
047         */
048        boolean containsKey(Key key);
049    
050        /**
051         * remove the index key
052         * 
053         * @param key
054         * @return StoreEntry removed
055         * @throws IOException
056         */
057        Value remove(Key key);
058    
059        /**
060         * store the key, item
061         * 
062         * @param key
063         * @param entry
064         * @throws IOException
065         */
066        Value put(Key key, Value entry);
067    
068        /**
069         * get the value at the given key, or put it if null.
070         *
071         * @param key
072         * @param entry
073         * @throws IOException
074         */
075        Value putIfAbsent(Key key, Value entry);
076    
077        /**
078         * @param key
079         * @return the entry
080         * @throws IOException
081         */
082        Value get(Key key);
083        
084        int size();
085        
086        boolean isEmpty();
087    
088        /**
089         * @return the location where index root resides on the page file.
090         */
091        int getIndexLocation();
092    
093    }