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