View Javadoc

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.regionserver.wal;
20  
21  import org.apache.hadoop.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  interface Dictionary {
31    static final byte NOT_IN_DICTIONARY = -1;
32  
33    /**
34     * Gets an entry from the dictionary.
35     * 
36     * @param idx index of the entry
37     * @return the entry, or null if non existent
38     */
39    public byte[] getEntry(short idx);
40  
41    /**
42     * Finds the index of an entry.
43     * If no entry found, we add it.
44     * 
45     * @param data the byte array that we're looking up
46     * @param offset Offset into <code>data</code> to add to Dictionary.
47     * @param length Length beyond <code>offset</code> that comprises entry; must be > 0.
48     * @return the index of the entry, or {@link #NOT_IN_DICTIONARY} if not found
49     */
50    public short findEntry(byte[] data, int offset, int length);
51  
52    /**
53     * Adds an entry to the dictionary.
54     * Be careful using this method.  It will add an entry to the
55     * dictionary even if it already has an entry for the same data.
56     * Call {{@link #findEntry(byte[], int, int)}} to add without duplicating
57     * dictionary entries.
58     * 
59     * @param data the entry to add
60     * @param offset Offset into <code>data</code> to add to Dictionary.
61     * @param length Length beyond <code>offset</code> that comprises entry; must be > 0.
62     * @return the index of the entry
63     */
64  
65    public short addEntry(byte[] data, int offset, int length);
66  
67    /**
68     * Flushes the dictionary, empties all values.
69     */
70    public void clear();
71  }