1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package org.apache.hadoop.hbase.io.util; 20 21 import org.apache.hadoop.hbase.classification.InterfaceAudience; 22 23 /** 24 * Dictionary interface 25 * 26 * Dictionary indexes should be either bytes or shorts, only positive. (The 27 * first bit is reserved for detecting whether something is compressed or not). 28 */ 29 @InterfaceAudience.Private 30 public interface Dictionary { 31 byte NOT_IN_DICTIONARY = -1; 32 33 void init(int initialSize); 34 /** 35 * Gets an entry from the dictionary. 36 * 37 * @param idx index of the entry 38 * @return the entry, or null if non existent 39 */ 40 byte[] getEntry(short idx); 41 42 /** 43 * Finds the index of an entry. 44 * If no entry found, we add it. 45 * 46 * @param data the byte array that we're looking up 47 * @param offset Offset into <code>data</code> to add to Dictionary. 48 * @param length Length beyond <code>offset</code> that comprises entry; must be > 0. 49 * @return the index of the entry, or {@link #NOT_IN_DICTIONARY} if not found 50 */ 51 short findEntry(byte[] data, int offset, int length); 52 53 /** 54 * Adds an entry to the dictionary. 55 * Be careful using this method. It will add an entry to the 56 * dictionary even if it already has an entry for the same data. 57 * Call {{@link #findEntry(byte[], int, int)}} to add without duplicating 58 * dictionary entries. 59 * 60 * @param data the entry to add 61 * @param offset Offset into <code>data</code> to add to Dictionary. 62 * @param length Length beyond <code>offset</code> that comprises entry; must be > 0. 63 * @return the index of the entry 64 */ 65 66 short addEntry(byte[] data, int offset, int length); 67 68 /** 69 * Flushes the dictionary, empties all values. 70 */ 71 void clear(); 72 }