例 1 : これはカスタムの writable Q1の実装です。回答: 高速に動作させるには、compareTo() メソッドと、rowComparator を実装する必要があります。
例 2 : テキスト ペア 例 104-107 ページ
Q2,カスタム オブジェクトに 2 つ以上のテキスト フィールドと 1 つの長い書き込み可能フィールドがある場合はどうなりますか? 例 1のように、Comparator.Compare メソッドのコード スニペット。これは、 Text である 2 つの属性のみを含むデータ型で機能します。
カスタム データ型に2 つ以上の要素があり、それも 1 つの Text、2 つの IntWaritable、1 つの BooleanAritable である場合はどうでしょうか。
そのような場合に rawComparator を実装する方法は?
public int compare(byte[] b1, int s1, int l1,
byte[] b2, int s2, int l2) {
try {
int firstL1 = WritableUtils.decodeVIntSize(b1[s1]) + readVInt(b1, s1);
int firstL2 = WritableUtils.decodeVIntSize(b2[s2]) + readVInt(b2, s2);
int cmp = TEXT_COMPARATOR.compare(b1, s1, firstL1, b2, s2, firstL2);
if (cmp != 0) {
return cmp;
}
return TEXT_COMPARATOR.compare(b1, s1 + firstL1,
l1 - firstL1,b2, s2 + firstL2, l2 - firstL2);
}catch (IOException e) {
throw new IllegalArgumentException(e);
}