java.util.Comparator, Configurable, RawComparatorBooleanWritable.Comparator, BytesWritable.Comparator, ByteWritable.Comparator, DoubleWritable.Comparator, FloatWritable.Comparator, IntWritable.Comparator, LongWritable.Comparator, MD5Hash.Comparator, NullWritable.Comparator, ShortWritable.Comparator, Text.Comparator, UTF8.Comparator@Public @Stable public class WritableComparator extends java.lang.Object implements RawComparator, Configurable
WritableComparables.
This base implementation uses the natural ordering. To define alternate
orderings, override compare(WritableComparable,WritableComparable).
One may optimize compare-intensive operations by overriding
compare(byte[],int,int,byte[],int,int). Static utility methods are
provided to assist in optimized implementations of this method.
| Modifier | Constructor | Description |
|---|---|---|
protected |
WritableComparator() |
|
protected |
WritableComparator(java.lang.Class<? extends WritableComparable> keyClass) |
Construct for a
WritableComparable implementation. |
protected |
WritableComparator(java.lang.Class<? extends WritableComparable> keyClass,
boolean createInstances) |
|
protected |
WritableComparator(java.lang.Class<? extends WritableComparable> keyClass,
Configuration conf,
boolean createInstances) |
| Modifier and Type | Method | Description |
|---|---|---|
int |
compare(byte[] b1,
int s1,
int l1,
byte[] b2,
int s2,
int l2) |
Optimization hook.
|
int |
compare(java.lang.Object a,
java.lang.Object b) |
Compare two Object.
|
int |
compare(WritableComparable a,
WritableComparable b) |
Compare two WritableComparables.
|
static int |
compareBytes(byte[] b1,
int s1,
int l1,
byte[] b2,
int s2,
int l2) |
Lexicographic order of binary data.
|
static void |
define(java.lang.Class c,
WritableComparator comparator) |
Register an optimized comparator for a
WritableComparable
implementation. |
static WritableComparator |
get(java.lang.Class<? extends WritableComparable> c) |
For backwards compatibility.
|
static WritableComparator |
get(java.lang.Class<? extends WritableComparable> c,
Configuration conf) |
Get a comparator for a
WritableComparable implementation. |
Configuration |
getConf() |
Return the configuration used by this object.
|
java.lang.Class<? extends WritableComparable> |
getKeyClass() |
Returns the WritableComparable implementation class.
|
static int |
hashBytes(byte[] bytes,
int length) |
Compute hash for binary data.
|
static int |
hashBytes(byte[] bytes,
int offset,
int length) |
Compute hash for binary data.
|
WritableComparable |
newKey() |
Construct a new
WritableComparable instance. |
static double |
readDouble(byte[] bytes,
int start) |
Parse a double from a byte array.
|
static float |
readFloat(byte[] bytes,
int start) |
Parse a float from a byte array.
|
static int |
readInt(byte[] bytes,
int start) |
Parse an integer from a byte array.
|
static long |
readLong(byte[] bytes,
int start) |
Parse a long from a byte array.
|
static int |
readUnsignedShort(byte[] bytes,
int start) |
Parse an unsigned short from a byte array.
|
static int |
readVInt(byte[] bytes,
int start) |
Reads a zero-compressed encoded integer from a byte array and returns it.
|
static long |
readVLong(byte[] bytes,
int start) |
Reads a zero-compressed encoded long from a byte array and returns it.
|
void |
setConf(Configuration conf) |
Set the configuration to be used by this object.
|
protected WritableComparator()
protected WritableComparator(java.lang.Class<? extends WritableComparable> keyClass)
WritableComparable implementation.keyClass - WritableComparable Class.protected WritableComparator(java.lang.Class<? extends WritableComparable> keyClass, boolean createInstances)
protected WritableComparator(java.lang.Class<? extends WritableComparable> keyClass, Configuration conf, boolean createInstances)
public static WritableComparator get(java.lang.Class<? extends WritableComparable> c)
c - WritableComparable Type.public static WritableComparator get(java.lang.Class<? extends WritableComparable> c, Configuration conf)
WritableComparable implementation.c - class.conf - configuration.public void setConf(Configuration conf)
ConfigurablesetConf in interface Configurableconf - configuration to be usedpublic Configuration getConf()
ConfigurablegetConf in interface Configurablepublic static void define(java.lang.Class c,
WritableComparator comparator)
WritableComparable
implementation. Comparators registered with this method must be
thread-safe.c - class.comparator - WritableComparator.public java.lang.Class<? extends WritableComparable> getKeyClass()
public WritableComparable newKey()
WritableComparable instance.public int compare(byte[] b1,
int s1,
int l1,
byte[] b2,
int s2,
int l2)
The default implementation reads the data into two WritableComparables (using Writable.readFields(DataInput), then calls compare(WritableComparable,WritableComparable).
compare in interface RawComparatorb1 - The first byte array.s1 - The position index in b1. The object under comparison's starting index.l1 - The length of the object in b1.b2 - The second byte array.s2 - The position index in b2. The object under comparison's starting index.l2 - The length of the object under comparison in b2.public int compare(WritableComparable a, WritableComparable b)
Comparable.compareTo(Object).a - the first object to be compared.b - the second object to be compared.public int compare(java.lang.Object a,
java.lang.Object b)
compare in interface java.util.Comparatora - the first object to be compared.b - the second object to be compared.public static int compareBytes(byte[] b1,
int s1,
int l1,
byte[] b2,
int s2,
int l2)
b1 - b1.s1 - s1.l1 - l1.b2 - b2.s2 - s2.l2 - l2.public static int hashBytes(byte[] bytes,
int offset,
int length)
bytes - bytes.offset - offset.length - length.public static int hashBytes(byte[] bytes,
int length)
bytes - bytes.length - length.public static int readUnsignedShort(byte[] bytes,
int start)
bytes - bytes.start - start.public static int readInt(byte[] bytes,
int start)
bytes - bytes.start - start.public static float readFloat(byte[] bytes,
int start)
bytes - bytes.start - start.public static long readLong(byte[] bytes,
int start)
bytes - bytes.start - start.public static double readDouble(byte[] bytes,
int start)
bytes - bytes.start - start.public static long readVLong(byte[] bytes,
int start)
throws java.io.IOException
bytes - byte array with decode longstart - starting indexjava.io.IOException - raised on errors performing I/O.public static int readVInt(byte[] bytes,
int start)
throws java.io.IOException
bytes - byte array with the encoded integerstart - start indexjava.io.IOException - raised on errors performing I/O.Copyright © 2008–2025 Apache Software Foundation. All rights reserved.