Cambridge SMT System
MergeComparator.java
Go to the documentation of this file.
1 /*******************************************************************************
2  * Licensed under the Apache License, Version 2.0 (the "License");
3  * you may not use these files except in compliance with the License.
4  * You may obtain a copy of the License at
5  *
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  * Unless required by applicable law or agreed to in writing, software
9  * distributed under the License is distributed on an "AS IS" BASIS,
10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  * See the License for the specific language governing permissions and
12  * limitations under the License.
13  *
14  * Copyright 2014 - Juan Pino, Aurelien Waite, William Byrne
15  *******************************************************************************/
16 package uk.ac.cam.eng.extraction.hadoop.merge;
17 
18 import java.io.IOException;
19 
20 import org.apache.hadoop.io.DataOutputBuffer;
21 import org.apache.hadoop.io.WritableComparable;
22 import org.apache.hadoop.io.WritableComparator;
23 
24 import uk.ac.cam.eng.extraction.Rule;
25 
33 public class MergeComparator extends WritableComparator {
34 
35  private final DataOutputBuffer buffera = new DataOutputBuffer();
36  private final DataOutputBuffer bufferb = new DataOutputBuffer();
37 
38  public MergeComparator() {
39  super(Rule.class);
40  }
41 
42  @Override
43  @SuppressWarnings("rawtypes")
44  public int compare(WritableComparable a, WritableComparable b) {
45  try {
46  buffera.reset();
47  a.write(buffera);
48  bufferb.reset();
49  b.write(bufferb);
50  return compareBytes(buffera.getData(), 0, buffera.getLength(),
51  bufferb.getData(), 0, bufferb.getLength());
52  } catch (IOException e) {
53  throw new RuntimeException(e);
54  }
55  }
56 
57  @Override
58  public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
59  return compareBytes(b1, s1, l1, b2, s2, l2);
60  }
61 
62 }
int compare(WritableComparable a, WritableComparable b)
int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2)