1 package org.apache.lucene.util.encoding;
3 import java.io.IOException;
4 import java.io.OutputStream;
7 * Licensed to the Apache Software Foundation (ASF) under one or more
8 * contributor license agreements. See the NOTICE file distributed with
9 * this work for additional information regarding copyright ownership.
10 * The ASF licenses this file to You under the Apache License, Version 2.0
11 * (the "License"); you may not use this file except in compliance with
12 * the License. You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
24 * An {@link IntEncoderFilter} which encodes the gap between the given values,
25 * rather than the values themselves. This encoder usually yields better
26 * encoding performance space-wise (i.e., the final encoded values consume less
27 * space) if the values are 'close' to each other.
29 * <b>NOTE:</b> this encoder assumes the values are given to
30 * {@link #encode(int)} in an ascending sorted manner, which ensures only
31 * positive values are encoded and thus yields better performance. If you are
32 * not sure whether the values are sorted or not, it is possible to chain this
33 * encoder with {@link SortingIntEncoder} to ensure the values will be
34 * sorted before encoding.
36 * @lucene.experimental
38 public class DGapIntEncoder extends IntEncoderFilter {
42 /** Initializes with the given encoder. */
43 public DGapIntEncoder(IntEncoder encoder) {
48 public void encode(int value) throws IOException {
49 encoder.encode(value - prev);
54 public IntDecoder createMatchingDecoder() {
55 return new DGapIntDecoder(encoder.createMatchingDecoder());
59 public void reInit(OutputStream out) {
65 public String toString() {
66 return "DGap (" + encoder.toString() + ")";